Skip to content

Commit ba37575

Browse files
committed
init_userconf.sh: only add line to /etc/sudoers once
The script `init_userconf.sh` is installed into `/etc/cont-init.d/02_userconf` and will be run every time the container is started. Currently, if the container is restarted multiple times, the line `%sudo ALL=(ALL) NOPASSWD:ALL` will be added each time the container is started. This change checks if the line already exists and does not add it if it does.
1 parent 6f25f32 commit ba37575

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

scripts/init_userconf.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ echo "$USER:$PASSWORD" | chpasswd
170170
if [ "${RUNROOTLESS}" = "true" ]; then
171171
echo "No sudoers changes needed when running rootless"
172172
elif [[ ${ROOT,,} == "true" ]]; then
173-
adduser "$USER" sudo && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >>/etc/sudoers
173+
line='%sudo ALL=(ALL) NOPASSWD:ALL'
174+
sudoers_file='/etc/sudoers'
175+
adduser "$USER" sudo && { grep -qxF "$line" "$sudoers_file" || echo "$line" >> "$sudoers_file"; }
174176
echo "$USER added to sudoers"
175177
fi
176178

0 commit comments

Comments
 (0)