Skip to content

Commit 9b63ddf

Browse files
Copilotabdurriq
andcommitted
Update all feature scripts to use common-setup.sh helper for user selection
Co-authored-by: abdurriq <[email protected]>
1 parent d179eb0 commit 9b63ddf

17 files changed

Lines changed: 90 additions & 262 deletions

File tree

src/anaconda/install.sh

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,12 @@ rm -f /etc/profile.d/00-restore-env.sh
8181
echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh
8282
chmod +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

10191
architecture="$(uname -m)"
10292
# Normalize arm64 to aarch64 for consistency

src/common-utils/main.sh

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -391,25 +391,15 @@ case "${ADJUSTED_ID}" in
391391
;;
392392
esac
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
415405
fi

src/conda/install.sh

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,12 @@ rm -f /etc/profile.d/00-restore-env.sh
2727
echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh
2828
chmod +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

4737
architecture="$(uname -m)"
4838
if [ "${architecture}" != "x86_64" ]; then

src/desktop-lite/install.sh

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,12 @@ if [ "$(id -u)" -ne 0 ]; then
7171
exit 1
7272
fi
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
9181
fluxbox_apps="$(cat \
9282
<< 'EOF'

src/docker-in-docker/install.sh

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,12 @@ fi
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
6555
pkg_mgr_update() {

src/docker-outside-of-docker/install.sh

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,12 @@ if [ "$(id -u)" -ne 0 ]; then
3939
exit 1
4040
fi
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

5949
apt_get_update()
6050
{

src/go/install.sh

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,12 @@ if ! type awk >/dev/null 2>&1; then
174174
check_packages awk
175175
fi
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

194184
export DEBIAN_FRONTEND=noninteractive
195185

src/hugo/install.sh

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,12 @@ rm -f /etc/profile.d/00-restore-env.sh
2929
echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh
3030
chmod +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

4939
architecture="$(uname -m)"
5040
if [ "${architecture}" != "amd64" ] && [ "${architecture}" != "x86_64" ] && [ "${architecture}" != "arm64" ] && [ "${architecture}" != "aarch64" ]; then

src/java/install.sh

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,22 +154,12 @@ rm -f /etc/profile.d/00-restore-env.sh
154154
echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh
155155
chmod +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

174164
updaterc() {
175165
local _bashrc

src/kubectl-helm-minikube/install.sh

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,12 @@ if [ "$(id -u)" -ne 0 ]; then
3131
exit 1
3232
fi
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

5141
USERHOME="/home/$USERNAME"
5242
if [ "$USERNAME" = "root" ]; then

0 commit comments

Comments
 (0)