Skip to content

Commit 7996c17

Browse files
dsimog01Luka Gulin
authored andcommitted
Update config files for unattended upgrades
1 parent 8a5da54 commit 7996c17

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

scripts/dappnode_install_pre.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,52 @@ install_unattendedupgrades() {
116116
fi
117117
}
118118

119+
# UNATTENDED UPGRADES SETUP: Enable unattended upgrades and set the configuration
120+
setup_unattendedupgrades() {
121+
# Check and configure unattended-upgrades config file
122+
unattended_config_file="/etc/apt/apt.conf.d/50unattended-upgrades"
123+
if [ ! -f "$unattended_config_file" ]; then
124+
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
125+
return 1
126+
fi
127+
128+
# Enable automatic removal of unused dependencies and disable automatic reboot
129+
modify_config_file "$unattended_config_file" 'Unattended-Upgrade::Remove-Unused-Dependencies' 'true'
130+
modify_config_file "$unattended_config_file" 'Unattended-Upgrade::Automatic-Reboot' 'false'
131+
132+
# Check and configure auto-upgrades config file
133+
auto_upgrades_file="/etc/apt/apt.conf.d/20auto-upgrades"
134+
if [ ! -f "$auto_upgrades_file" ]; then
135+
# Create the file
136+
echo unattended-upgrades unattended-upgrades/enable_auto_updates boolean true | debconf-set-selections
137+
dpkg-reconfigure -f noninteractive unattended-upgrades
138+
139+
# Check if the file was created
140+
if [ ! -f "$auto_upgrades_file" ]; then
141+
echo -e "\e[31m \n\n WARNING: $auto_upgrades_file could not be created \n\n \e[0m" 2>&1 | tee -a $LOG_FILE
142+
return 1
143+
fi
144+
fi
145+
146+
# Enable automatic updates and unattended-upgrades (file should exist now)
147+
modify_config_file "$auto_upgrades_file" 'APT::Periodic::Update-Package-Lists' '1'
148+
modify_config_file "$auto_upgrades_file" 'APT::Periodic::Unattended-Upgrade' '1'
149+
150+
echo -e "\e[32m \n\n Verified unattended-upgrades installation and setup. \n\n \e[0m" 2>&1 | tee -a $LOG_FILE
151+
}
152+
153+
# UNATTENDED UPGRADES SETUP: Auxiliary function to modify a setting in a config file
154+
modify_config_file() {
155+
local config_file="$1"
156+
local config_setting_key="$2"
157+
local config_setting_value="$3"
158+
# Remove any appearances of the key from the file
159+
sed -i "/^$config_setting_key .*/d" "$config_file"
160+
# Add the updated setting
161+
echo "$config_setting_key \"$config_setting_value\";" >> "$config_file"
162+
}
163+
164+
119165
# HOST UPDATE
120166
host_update () {
121167
apt-get update 2>&1 | tee -a $LOG_FILE

0 commit comments

Comments
 (0)