From 34c0b1a8c1437d862a16dbfc7dca4893823b6aa4 Mon Sep 17 00:00:00 2001 From: Luka Gulin Date: Wed, 17 May 2023 18:38:43 +0200 Subject: [PATCH 1/5] add unattened upgrades --- scripts/dappnode_install_pre.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/dappnode_install_pre.sh b/scripts/dappnode_install_pre.sh index 96654f9..27fc87f 100755 --- a/scripts/dappnode_install_pre.sh +++ b/scripts/dappnode_install_pre.sh @@ -105,6 +105,17 @@ install_iptables () { fi } +# UNATTENDED UPGRADES INSTALLATION: for upgrading system automatically +install_unattendedupgrades() { + apt-get update -y + apt-get install unattended-upgrades -y | tee -a $LOG_FILE + if unattended-upgrades -h >/dev/null 2>&1 ; then + echo -e "\e[32m \n\n Verified unattended-upgrades installation \n\n \e[0m" 2>&1 | tee -a $LOG_FILE + else + echo -e "\e[31m \n\n WARNING: unattended-upgrades not installed, upgrades must be done manually! \n\n \e[0m" 2>&1 | tee -a $LOG_FILE + fi +} + # HOST UPDATE host_update () { apt-get update 2>&1 | tee -a $LOG_FILE @@ -164,6 +175,13 @@ else install_lsof 2>&1 | tee -a $LOG_FILE fi +# Only install unatended upgrades if needed +if unattended-upgrades -h >/dev/null 2>&1; then + echo -e "\e[32m \n\n unattended-upgrades is already installed \n\n \e[0m" 2>&1 | tee -a $LOG_FILE +else + instal_unattendedupgrades 2>&1 | tee -a $LOG_FILE +fi + #Check connectivity { [ -f /etc/network/interfaces ] && grep "iface en.* inet dhcp" /etc/network/interfaces &>/dev/null; } || { echo "Interfaces not found"; exit 1; } From 55a9ba9d2768cd67f3da6532ddacf82a5299060c Mon Sep 17 00:00:00 2001 From: 3alpha Date: Wed, 17 May 2023 19:07:48 +0200 Subject: [PATCH 2/5] TIpfeller --- scripts/dappnode_install_pre.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/dappnode_install_pre.sh b/scripts/dappnode_install_pre.sh index 27fc87f..ab21170 100755 --- a/scripts/dappnode_install_pre.sh +++ b/scripts/dappnode_install_pre.sh @@ -179,7 +179,7 @@ fi if unattended-upgrades -h >/dev/null 2>&1; then echo -e "\e[32m \n\n unattended-upgrades is already installed \n\n \e[0m" 2>&1 | tee -a $LOG_FILE else - instal_unattendedupgrades 2>&1 | tee -a $LOG_FILE + install_unattendedupgrades 2>&1 | tee -a $LOG_FILE fi #Check connectivity From 7fe4abdfe4dc150c3822a9104941c0c8809a0e41 Mon Sep 17 00:00:00 2001 From: Luka Gulin Date: Thu, 18 May 2023 15:11:07 +0200 Subject: [PATCH 3/5] add opt-out for unattended upgrades --- scripts/dappnode_install_pre.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/dappnode_install_pre.sh b/scripts/dappnode_install_pre.sh index ab21170..5bdbdfe 100755 --- a/scripts/dappnode_install_pre.sh +++ b/scripts/dappnode_install_pre.sh @@ -175,11 +175,13 @@ else install_lsof 2>&1 | tee -a $LOG_FILE fi -# Only install unatended upgrades if needed -if unattended-upgrades -h >/dev/null 2>&1; then - echo -e "\e[32m \n\n unattended-upgrades is already installed \n\n \e[0m" 2>&1 | tee -a $LOG_FILE -else - install_unattendedupgrades 2>&1 | tee -a $LOG_FILE +if [[ $SKIP_UNNATENDED_UPGRADES != "true" ]]; then + # Only install unatended upgrades if needed + if unattended-upgrades -h >/dev/null 2>&1; then + echo -e "\e[32m \n\n unattended-upgrades is already installed \n\n \e[0m" 2>&1 | tee -a $LOG_FILE + else + install_unattendedupgrades 2>&1 | tee -a $LOG_FILE + fi fi #Check connectivity From 0d970b5d27b01a3a5fa44b12546e0d0dc46540b7 Mon Sep 17 00:00:00 2001 From: 3alpha Date: Thu, 18 May 2023 20:40:31 +0200 Subject: [PATCH 4/5] TYPO --- scripts/dappnode_install_pre.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/dappnode_install_pre.sh b/scripts/dappnode_install_pre.sh index 5bdbdfe..c6e34f3 100755 --- a/scripts/dappnode_install_pre.sh +++ b/scripts/dappnode_install_pre.sh @@ -175,7 +175,7 @@ else install_lsof 2>&1 | tee -a $LOG_FILE fi -if [[ $SKIP_UNNATENDED_UPGRADES != "true" ]]; then +if [[ $SKIP_UNATTENDED_UPGRADES != "true" ]]; then # Only install unatended upgrades if needed if unattended-upgrades -h >/dev/null 2>&1; then echo -e "\e[32m \n\n unattended-upgrades is already installed \n\n \e[0m" 2>&1 | tee -a $LOG_FILE From 5e0ab64301034e0a070921a24cffaf1739e2c079 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 24 Jul 2023 11:30:30 +0200 Subject: [PATCH 5/5] Update config files for unattended upgrades --- scripts/dappnode_install_pre.sh | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/scripts/dappnode_install_pre.sh b/scripts/dappnode_install_pre.sh index c6e34f3..50b4718 100755 --- a/scripts/dappnode_install_pre.sh +++ b/scripts/dappnode_install_pre.sh @@ -116,6 +116,52 @@ install_unattendedupgrades() { fi } +# UNATTENDED UPGRADES SETUP: Enable unattended upgrades and set the configuration +setup_unattendedupgrades() { + # Check and configure unattended-upgrades config file + unattended_config_file="/etc/apt/apt.conf.d/50unattended-upgrades" + if [ ! -f "$unattended_config_file" ]; then + echo -e "\e[31m \n\n WARNING: $unattended_config_file should have been created by the unattended-upgrades package \n\n \e[0m" 2>&1 | tee -a $LOG_FILE + return 1 + fi + + # Enable automatic removal of unused dependencies and disable automatic reboot + modify_config_file "$unattended_config_file" 'Unattended-Upgrade::Remove-Unused-Dependencies' 'true' + modify_config_file "$unattended_config_file" 'Unattended-Upgrade::Automatic-Reboot' 'false' + + # Check and configure auto-upgrades config file + auto_upgrades_file="/etc/apt/apt.conf.d/20auto-upgrades" + if [ ! -f "$auto_upgrades_file" ]; then + # Create the file + echo unattended-upgrades unattended-upgrades/enable_auto_updates boolean true | debconf-set-selections + dpkg-reconfigure -f noninteractive unattended-upgrades + + # Check if the file was created + if [ ! -f "$auto_upgrades_file" ]; then + echo -e "\e[31m \n\n WARNING: $auto_upgrades_file could not be created \n\n \e[0m" 2>&1 | tee -a $LOG_FILE + return 1 + fi + fi + + # Enable automatic updates and unattended-upgrades (file should exist now) + modify_config_file "$auto_upgrades_file" 'APT::Periodic::Update-Package-Lists' '1' + modify_config_file "$auto_upgrades_file" 'APT::Periodic::Unattended-Upgrade' '1' + + echo -e "\e[32m \n\n Verified unattended-upgrades installation and setup. \n\n \e[0m" 2>&1 | tee -a $LOG_FILE +} + +# UNATTENDED UPGRADES SETUP: Auxiliary function to modify a setting in a config file +modify_config_file() { + local config_file="$1" + local config_setting_key="$2" + local config_setting_value="$3" + # Remove any appearances of the key from the file + sed -i "/^$config_setting_key .*/d" "$config_file" + # Add the updated setting + echo "$config_setting_key \"$config_setting_value\";" >> "$config_file" +} + + # HOST UPDATE host_update () { apt-get update 2>&1 | tee -a $LOG_FILE