2023-08-25 10:29:22 -06:00
|
|
|
#!/bin/bash
|
2024-02-14 10:55:47 -06:00
|
|
|
#if [[ -z "${HOME_USER}" ]]; then
|
|
|
|
#HOME_USER="vscode"
|
|
|
|
#fi
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# use specified user name or use `vscode` if not specified
|
|
|
|
HOME_USER="${HOME_USER:-vscode}"
|
|
|
|
|
|
|
|
# use specified group name or use the same user name also as the group name
|
|
|
|
MY_GROUP="${MY_GROUP:-${HOME_USER}}"
|
|
|
|
|
|
|
|
# use the specified UID for the user
|
|
|
|
MY_UID="${MY_UID:-1000}"
|
|
|
|
|
|
|
|
# use the specified GID for the user
|
|
|
|
MY_GID="${MY_GID:-${MY_UID}}"
|
|
|
|
|
|
|
|
|
|
|
|
# check to see if group exists; if not, create it
|
|
|
|
if grep -q -E "^${MY_GROUP}:" /etc/group > /dev/null 2>&1
|
|
|
|
then
|
|
|
|
echo "INFO: Group exists; skipping creation"
|
|
|
|
else
|
|
|
|
echo "INFO: Group doesn't exist; creating..."
|
|
|
|
# create the group
|
2024-02-14 11:51:26 -06:00
|
|
|
sudo addgroup -g "${MY_GID}" "${MY_GROUP}" || (echo "INFO: Group exists but with a different name; renaming..."; sudo groupmod -g "${MY_GID}" -n "${MY_GROUP}" "$(awk -F ':' '{print $1":"$3}' < /etc/group | grep ":${MY_GID}$" | awk -F ":" '{print $1}')")
|
2024-02-14 10:55:47 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# check to see if user exists; if not, create it
|
|
|
|
if id -u "${HOME_USER}" > /dev/null 2>&1
|
|
|
|
then
|
|
|
|
echo "INFO: User exists; skipping creation"
|
|
|
|
else
|
|
|
|
echo "INFO: User doesn't exist; creating..."
|
|
|
|
# create the user
|
2024-02-14 11:51:26 -06:00
|
|
|
sudo adduser -u "${MY_UID}" -G "${MY_GROUP}" -h "/home/${HOME_USER}" -s /bin/sh -D "${HOME_USER}"
|
2023-08-25 12:20:22 -06:00
|
|
|
fi
|
|
|
|
|
2024-02-14 10:55:47 -06:00
|
|
|
# addgroup nonroot
|
|
|
|
#adduser --disabled-password --gecos "" ${HOME_USER}
|
|
|
|
# echo "${HOME_USER} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
2023-08-25 19:20:38 -06:00
|
|
|
|
2023-08-29 10:11:28 -06:00
|
|
|
#Creating extensions folder
|
2023-08-29 11:15:51 -06:00
|
|
|
sudo mkdir /home/${HOME_USER}/.config/Code
|
|
|
|
sudo chmod -R a+rwX /home/${HOME_USER}/.config/Code
|
2023-08-29 10:11:28 -06:00
|
|
|
sudo mkdir /home/${HOME_USER}/.vscode-server
|
|
|
|
sudo chmod -R a+rwX /home/${HOME_USER}/.vscode-server
|
2023-08-29 13:39:54 -06:00
|
|
|
sudo mkdir /home/${HOME_USER}/.vscode-server-insiders
|
|
|
|
sudo chmod -R a+rwX /home/${HOME_USER}/.vscode-server-insiders
|
2023-08-29 10:11:28 -06:00
|
|
|
|
2023-08-29 06:56:31 -06:00
|
|
|
# Check if the data.json file exists
|
|
|
|
if [ -f "/home/extensions.json" ]; then
|
|
|
|
# Read the JSON file into a variable
|
|
|
|
jsonExtensions=$(cat /home/extensions.json)
|
|
|
|
|
2023-09-01 11:07:46 -06:00
|
|
|
# Use jq to extract the extension parameter from the JSON array
|
2023-09-01 12:11:04 -06:00
|
|
|
extensions=$(echo $jsonExtensions | jq -r '.[].extensionsGroup.extensions[].uniqueIdentifier')
|
2023-08-29 06:56:31 -06:00
|
|
|
|
|
|
|
# Loop through the extensions and process each element
|
|
|
|
for extension in $extensions; do
|
|
|
|
echo "Installing extension: $extension"
|
2023-08-29 10:17:01 -06:00
|
|
|
sudo su - ${HOME_USER} -c "code --install-extension $extension"
|
2023-08-29 06:56:31 -06:00
|
|
|
done
|
2023-08-29 13:39:54 -06:00
|
|
|
sudo cp -R /home/${HOME_USER}/.vscode/* /home/${HOME_USER}/.vscode-server
|
2023-08-29 21:55:28 -06:00
|
|
|
sudo cp -R /home/${HOME_USER}/.vscode/* /home/${HOME_USER}/.vscode-server-insiders
|
2023-08-29 13:39:54 -06:00
|
|
|
sudo chmod -R a+rwX /home/${HOME_USER}/.vscode
|
|
|
|
sudo chmod -R a+rwX /home/${HOME_USER}/.vscode-server
|
|
|
|
sudo chmod -R a+rwX /home/${HOME_USER}/.vscode-server-insiders
|
2023-08-29 06:56:31 -06:00
|
|
|
else
|
|
|
|
echo "File extensions.json not found"
|
|
|
|
fi
|
|
|
|
|
2023-08-25 12:20:22 -06:00
|
|
|
if [[ -z "${VSCODE_TUNNEL_NAME}" ]]; then
|
2023-08-26 22:53:21 -06:00
|
|
|
sudo su - ${HOME_USER} -c "code tunnel --accept-server-license-terms"
|
2023-08-25 12:20:22 -06:00
|
|
|
else
|
2023-08-26 22:53:21 -06:00
|
|
|
sudo su - ${HOME_USER} -c "code tunnel --accept-server-license-terms --name ${VSCODE_TUNNEL_NAME}"
|
2023-08-25 12:20:22 -06:00
|
|
|
fi
|