1+ #! /bin/bash
2+ set -e
3+
4+ # Ensure apt is in non-interactive to avoid prompts
5+ export DEBIAN_FRONTEND=noninteractive
6+
7+ USERNAME=${USERNAME:- " codespace" }
8+
9+ # Clean up
10+ rm -rf /var/lib/apt/lists/*
11+
12+ if [ " $( id -u) " -ne 0 ]; then
13+ echo -e ' Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
14+ exit 1
15+ fi
16+
17+ # Ensure that login shells get the correct path if the user updated the PATH using ENV.
18+ rm -f /etc/profile.d/00-restore-env.sh
19+ echo " export PATH=${PATH// $(sh -lc ' echo $PATH' )/ \$ PATH} " > /etc/profile.d/00-restore-env.sh
20+ chmod +x /etc/profile.d/00-restore-env.sh
21+
22+ # Determine the appropriate non-root user
23+ if [ " ${USERNAME} " = " auto" ] || [ " ${USERNAME} " = " automatic" ]; then
24+ USERNAME=" "
25+ POSSIBLE_USERS=(" vscode" " node" " codespace" " $( awk -v val=1000 -F " :" ' $3==val{print $1}' /etc/passwd) " )
26+ for CURRENT_USER in " ${POSSIBLE_USERS[@]} " ; do
27+ if id -u ${CURRENT_USER} > /dev/null 2>&1 ; then
28+ USERNAME=${CURRENT_USER}
29+ break
30+ fi
31+ done
32+ if [ " ${USERNAME} " = " " ]; then
33+ USERNAME=root
34+ fi
35+ elif [ " ${USERNAME} " = " none" ] || ! id -u ${USERNAME} > /dev/null 2>&1 ; then
36+ USERNAME=root
37+ fi
38+
39+ apt_get_update () {
40+ if [ " $( find /var/lib/apt/lists/* | wc -l) " = " 0" ]; then
41+ echo " Running apt-get update..."
42+ apt-get update -y
43+ fi
44+ }
45+
46+ # Checks if packages are installed and installs them if not
47+ check_packages () {
48+ if ! dpkg -s " $@ " > /dev/null 2>&1 ; then
49+ apt_get_update
50+ apt-get -y install --no-install-recommends " $@ "
51+ fi
52+ }
53+
54+ echo " Installing asdf-go..."
55+ check_packages wget curl tar
56+ /bin/bash " $( dirname $0 ) /install-asdf-go.sh"
57+ # Clean up
58+ rm -rf /var/lib/apt/lists/*
59+
60+ echo " Done!"
0 commit comments