File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -81,22 +81,12 @@ rm -f /etc/profile.d/00-restore-env.sh
8181echo " export PATH=${PATH// $(sh -lc ' echo $PATH' )/ \$ PATH} " > /etc/profile.d/00-restore-env.sh
8282chmod +x /etc/profile.d/00-restore-env.sh
8383
84+ # Source common helper functions
85+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
86+ source " ${SCRIPT_DIR} /../_common/common-setup.sh"
87+
8488# Determine the appropriate non-root user
85- if [ " ${USERNAME} " = " auto" ] || [ " ${USERNAME} " = " automatic" ]; then
86- USERNAME=" "
87- POSSIBLE_USERS=(" vscode" " node" " codespace" " $( awk -v val=1000 -F " :" ' $3==val{print $1}' /etc/passwd) " )
88- for CURRENT_USER in " ${POSSIBLE_USERS[@]} " ; do
89- if id -u " ${CURRENT_USER} " > /dev/null 2>&1 ; then
90- USERNAME=" ${CURRENT_USER} "
91- break
92- fi
93- done
94- if [ " ${USERNAME} " = " " ]; then
95- USERNAME=root
96- fi
97- elif [ " ${USERNAME} " = " none" ] || ! id -u ${USERNAME} > /dev/null 2>&1 ; then
98- USERNAME=root
99- fi
89+ USERNAME=$( determine_user_from_input " ${USERNAME} " " root" )
10090
10191architecture=" $( uname -m) "
10292# Normalize arm64 to aarch64 for consistency
Original file line number Diff line number Diff line change @@ -391,25 +391,15 @@ case "${ADJUSTED_ID}" in
391391 ;;
392392esac
393393
394- # If in automatic mode, determine if a user already exists, if not use vscode
395- if [ " ${USERNAME} " = " auto" ] || [ " ${USERNAME} " = " automatic" ]; then
396- if [ " ${_REMOTE_USER} " != " root" ]; then
397- USERNAME=" ${_REMOTE_USER} "
398- else
399- USERNAME=" "
400- POSSIBLE_USERS=(" devcontainer" " vscode" " node" " codespace" " $( awk -v val=1000 -F " :" ' $3==val{print $1}' /etc/passwd) " )
401- for CURRENT_USER in " ${POSSIBLE_USERS[@]} " ; do
402- if id -u ${CURRENT_USER} > /dev/null 2>&1 ; then
403- USERNAME=${CURRENT_USER}
404- break
405- fi
406- done
407- if [ " ${USERNAME} " = " " ]; then
408- USERNAME=vscode
409- fi
410- fi
411- elif [ " ${USERNAME} " = " none" ]; then
412- USERNAME=root
394+ # Source common helper functions
395+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
396+ source " ${SCRIPT_DIR} /../_common/common-setup.sh"
397+
398+ # If in automatic mode, determine if a user already exists, if not use vscode (which will be created)
399+ USERNAME=$( determine_user_from_input " ${USERNAME} " " vscode" )
400+
401+ # Handle the special "none" case for common-utils
402+ if [ " ${USERNAME} " = " none" ]; then
413403 USER_UID=0
414404 USER_GID=0
415405fi
Original file line number Diff line number Diff line change @@ -27,22 +27,12 @@ rm -f /etc/profile.d/00-restore-env.sh
2727echo " export PATH=${PATH// $(sh -lc ' echo $PATH' )/ \$ PATH} " > /etc/profile.d/00-restore-env.sh
2828chmod +x /etc/profile.d/00-restore-env.sh
2929
30+ # Source common helper functions
31+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
32+ source " ${SCRIPT_DIR} /../_common/common-setup.sh"
33+
3034# Determine the appropriate non-root user
31- if [ " ${USERNAME} " = " auto" ] || [ " ${USERNAME} " = " automatic" ]; then
32- USERNAME=" "
33- POSSIBLE_USERS=(" vscode" " node" " codespace" " $( awk -v val=1000 -F " :" ' $3==val{print $1}' /etc/passwd) " )
34- for CURRENT_USER in " ${POSSIBLE_USERS[@]} " ; do
35- if id -u " ${CURRENT_USER} " > /dev/null 2>&1 ; then
36- USERNAME=" ${CURRENT_USER} "
37- break
38- fi
39- done
40- if [ " ${USERNAME} " = " " ]; then
41- USERNAME=root
42- fi
43- elif [ " ${USERNAME} " = " none" ] || ! id -u ${USERNAME} > /dev/null 2>&1 ; then
44- USERNAME=root
45- fi
35+ USERNAME=$( determine_user_from_input " ${USERNAME} " " root" )
4636
4737architecture=" $( uname -m) "
4838if [ " ${architecture} " != " x86_64" ]; then
Original file line number Diff line number Diff line change @@ -71,22 +71,12 @@ if [ "$(id -u)" -ne 0 ]; then
7171 exit 1
7272fi
7373
74+ # Source common helper functions
75+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
76+ source " ${SCRIPT_DIR} /../_common/common-setup.sh"
77+
7478# Determine the appropriate non-root user
75- if [ " ${USERNAME} " = " auto" ] || [ " ${USERNAME} " = " automatic" ]; then
76- USERNAME=" "
77- POSSIBLE_USERS=(" vscode" " node" " codespace" " $( awk -v val=1000 -F " :" ' $3==val{print $1}' /etc/passwd) " )
78- for CURRENT_USER in " ${POSSIBLE_USERS[@]} " ; do
79- if id -u ${CURRENT_USER} > /dev/null 2>&1 ; then
80- USERNAME=${CURRENT_USER}
81- break
82- fi
83- done
84- if [ " ${USERNAME} " = " " ]; then
85- USERNAME=root
86- fi
87- elif [ " ${USERNAME} " = " none" ] || ! id -u ${USERNAME} > /dev/null 2>&1 ; then
88- USERNAME=root
89- fi
79+ USERNAME=$( determine_user_from_input " ${USERNAME} " " root" )
9080# Add default Fluxbox config files if none are already present
9181fluxbox_apps=" $( cat \
9282<< 'EOF '
Original file line number Diff line number Diff line change 4444# See: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/shared/utils.sh
4545# ##################
4646
47+ # Source common helper functions
48+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
49+ source " ${SCRIPT_DIR} /../_common/common-setup.sh"
50+
4751# Determine the appropriate non-root user
48- if [ " ${USERNAME} " = " auto" ] || [ " ${USERNAME} " = " automatic" ]; then
49- USERNAME=" "
50- POSSIBLE_USERS=(" vscode" " node" " codespace" " $( awk -v val=1000 -F " :" ' $3==val{print $1}' /etc/passwd) " )
51- for CURRENT_USER in " ${POSSIBLE_USERS[@]} " ; do
52- if id -u ${CURRENT_USER} > /dev/null 2>&1 ; then
53- USERNAME=${CURRENT_USER}
54- break
55- fi
56- done
57- if [ " ${USERNAME} " = " " ]; then
58- USERNAME=root
59- fi
60- elif [ " ${USERNAME} " = " none" ] || ! id -u ${USERNAME} > /dev/null 2>&1 ; then
61- USERNAME=root
62- fi
52+ USERNAME=$( determine_user_from_input " ${USERNAME} " " root" )
6353
6454# Package manager update function
6555pkg_mgr_update () {
Original file line number Diff line number Diff line change @@ -39,22 +39,12 @@ if [ "$(id -u)" -ne 0 ]; then
3939 exit 1
4040fi
4141
42+ # Source common helper functions
43+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
44+ source " ${SCRIPT_DIR} /../_common/common-setup.sh"
45+
4246# Determine the appropriate non-root user
43- if [ " ${USERNAME} " = " auto" ] || [ " ${USERNAME} " = " automatic" ]; then
44- USERNAME=" "
45- POSSIBLE_USERS=(" vscode" " node" " codespace" " $( awk -v val=1000 -F " :" ' $3==val{print $1}' /etc/passwd) " )
46- for CURRENT_USER in " ${POSSIBLE_USERS[@]} " ; do
47- if id -u ${CURRENT_USER} > /dev/null 2>&1 ; then
48- USERNAME=${CURRENT_USER}
49- break
50- fi
51- done
52- if [ " ${USERNAME} " = " " ]; then
53- USERNAME=root
54- fi
55- elif [ " ${USERNAME} " = " none" ] || ! id -u ${USERNAME} > /dev/null 2>&1 ; then
56- USERNAME=root
57- fi
47+ USERNAME=$( determine_user_from_input " ${USERNAME} " " root" )
5848
5949apt_get_update ()
6050{
Original file line number Diff line number Diff line change @@ -174,22 +174,12 @@ if ! type awk >/dev/null 2>&1; then
174174 check_packages awk
175175fi
176176
177+ # Source common helper functions
178+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
179+ source " ${SCRIPT_DIR} /../_common/common-setup.sh"
180+
177181# Determine the appropriate non-root user
178- if [ " ${USERNAME} " = " auto" ] || [ " ${USERNAME} " = " automatic" ]; then
179- USERNAME=" "
180- POSSIBLE_USERS=(" vscode" " node" " codespace" " $( awk -v val=1000 -F " :" ' $3==val{print $1}' /etc/passwd) " )
181- for CURRENT_USER in " ${POSSIBLE_USERS[@]} " ; do
182- if id -u ${CURRENT_USER} > /dev/null 2>&1 ; then
183- USERNAME=${CURRENT_USER}
184- break
185- fi
186- done
187- if [ " ${USERNAME} " = " " ]; then
188- USERNAME=root
189- fi
190- elif [ " ${USERNAME} " = " none" ] || ! id -u ${USERNAME} > /dev/null 2>&1 ; then
191- USERNAME=root
192- fi
182+ USERNAME=$( determine_user_from_input " ${USERNAME} " " root" )
193183
194184export DEBIAN_FRONTEND=noninteractive
195185
Original file line number Diff line number Diff line change @@ -29,22 +29,12 @@ rm -f /etc/profile.d/00-restore-env.sh
2929echo " export PATH=${PATH// $(sh -lc ' echo $PATH' )/ \$ PATH} " > /etc/profile.d/00-restore-env.sh
3030chmod +x /etc/profile.d/00-restore-env.sh
3131
32+ # Source common helper functions
33+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
34+ source " ${SCRIPT_DIR} /../_common/common-setup.sh"
35+
3236# Determine the appropriate non-root user
33- if [ " ${USERNAME} " = " auto" ] || [ " ${USERNAME} " = " automatic" ]; then
34- USERNAME=" "
35- POSSIBLE_USERS=(" vscode" " node" " codespace" " $( awk -v val=1000 -F " :" ' $3==val{print $1}' /etc/passwd) " )
36- for CURRENT_USER in " ${POSSIBLE_USERS[@]} " ; do
37- if id -u ${CURRENT_USER} > /dev/null 2>&1 ; then
38- USERNAME=${CURRENT_USER}
39- break
40- fi
41- done
42- if [ " ${USERNAME} " = " " ]; then
43- USERNAME=root
44- fi
45- elif [ " ${USERNAME} " = " none" ] || ! id -u ${USERNAME} > /dev/null 2>&1 ; then
46- USERNAME=root
47- fi
37+ USERNAME=$( determine_user_from_input " ${USERNAME} " " root" )
4838
4939architecture=" $( uname -m) "
5040if [ " ${architecture} " != " amd64" ] && [ " ${architecture} " != " x86_64" ] && [ " ${architecture} " != " arm64" ] && [ " ${architecture} " != " aarch64" ]; then
Original file line number Diff line number Diff line change @@ -154,22 +154,12 @@ rm -f /etc/profile.d/00-restore-env.sh
154154echo " export PATH=${PATH// $(sh -lc ' echo $PATH' )/ \$ PATH} " > /etc/profile.d/00-restore-env.sh
155155chmod +x /etc/profile.d/00-restore-env.sh
156156
157+ # Source common helper functions
158+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
159+ source " ${SCRIPT_DIR} /../_common/common-setup.sh"
160+
157161# Determine the appropriate non-root user
158- if [ " ${USERNAME} " = " auto" ] || [ " ${USERNAME} " = " automatic" ]; then
159- USERNAME=" "
160- POSSIBLE_USERS=(" vscode" " node" " codespace" " $( awk -v val=1000 -F " :" ' $3==val{print $1}' /etc/passwd) " )
161- for CURRENT_USER in " ${POSSIBLE_USERS[@]} " ; do
162- if id -u ${CURRENT_USER} > /dev/null 2>&1 ; then
163- USERNAME=${CURRENT_USER}
164- break
165- fi
166- done
167- if [ " ${USERNAME} " = " " ]; then
168- USERNAME=root
169- fi
170- elif [ " ${USERNAME} " = " none" ] || ! id -u ${USERNAME} > /dev/null 2>&1 ; then
171- USERNAME=root
172- fi
162+ USERNAME=$( determine_user_from_input " ${USERNAME} " " root" )
173163
174164updaterc () {
175165 local _bashrc
Original file line number Diff line number Diff line change @@ -31,22 +31,12 @@ if [ "$(id -u)" -ne 0 ]; then
3131 exit 1
3232fi
3333
34+ # Source common helper functions
35+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
36+ source " ${SCRIPT_DIR} /../_common/common-setup.sh"
37+
3438# Determine the appropriate non-root user
35- if [ " ${USERNAME} " = " auto" ] || [ " ${USERNAME} " = " automatic" ]; then
36- USERNAME=" "
37- POSSIBLE_USERS=(" vscode" " node" " codespace" " $( awk -v val=1000 -F " :" ' $3==val{print $1}' /etc/passwd) " )
38- for CURRENT_USER in " ${POSSIBLE_USERS[@]} " ; do
39- if id -u ${CURRENT_USER} > /dev/null 2>&1 ; then
40- USERNAME=${CURRENT_USER}
41- break
42- fi
43- done
44- if [ " ${USERNAME} " = " " ]; then
45- USERNAME=root
46- fi
47- elif [ " ${USERNAME} " = " none" ] || ! id -u ${USERNAME} > /dev/null 2>&1 ; then
48- USERNAME=root
49- fi
39+ USERNAME=$( determine_user_from_input " ${USERNAME} " " root" )
5040
5141USERHOME=" /home/$USERNAME "
5242if [ " $USERNAME " = " root" ]; then
You can’t perform that action at this time.
0 commit comments