Skip to content

Commit

Permalink
Update config files for unattended upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
dsimog01 committed Jul 24, 2023
1 parent f28da86 commit bd070ea
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions scripts/dappnode_install_pre.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bd070ea

Please sign in to comment.