From 55143adcf646a7d52ea308d9244195d5a5244446 Mon Sep 17 00:00:00 2001 From: Bradley Bickford Date: Thu, 5 Dec 2024 20:00:45 -0500 Subject: [PATCH] Adding some updates to make the containers more secure, fix the password bug, and add the first version of the Powershell containers --- Dockerfile.fedora | 17 ++---- Dockerfile.pwsh.fedora | 78 +++++++++++++++++++++++++ Dockerfile.pwsh.ubuntu | 80 ++++++++++++++++++++++++++ Dockerfile.ubuntu | 17 +----- entrypoint.sh | 27 +++++++++ setup_cswpilib.sh | 66 --------------------- setup_user.sh | 126 ----------------------------------------- 7 files changed, 193 insertions(+), 218 deletions(-) create mode 100644 Dockerfile.pwsh.fedora create mode 100644 Dockerfile.pwsh.ubuntu create mode 100644 entrypoint.sh delete mode 100644 setup_cswpilib.sh delete mode 100755 setup_user.sh diff --git a/Dockerfile.fedora b/Dockerfile.fedora index b55d42f..6659333 100644 --- a/Dockerfile.fedora +++ b/Dockerfile.fedora @@ -17,24 +17,19 @@ RUN dnf update -y && dnf install -y \ && git lfs install \ && curl -fsSL https://code-server.dev/install.sh | sh -RUN useradd -u 1000 coder && echo "coder ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nopasswd - -RUN ARCH="$(uname -m | sed 's/x86_64/amd64/g' | sed 's/aarch64/arm64/g')" \ - && curl -fsSL "https://github.com/boxboat/fixuid/releases/download/v0.6.0/fixuid-0.6.0-linux-$ARCH.tar.gz" | tar -C /usr/local/bin -xzf - \ - && chown root:root /usr/local/bin/fixuid \ - && chmod 4755 /usr/local/bin/fixuid \ - && mkdir -p /etc/fixuid \ - && printf "user: coder\ngroup: coder\n" > /etc/fixuid/config.yml +RUN useradd -u 1000 coder COPY code-server.tar.gz /tmp COPY settings.json /tmp COPY config.yaml /tmp COPY project-creator.py /tmp +COPY entrypoint.sh /usr/bin ARG WPILIB_DL_URL ARG WPILIB_FILE_NAME=wpilib.tar.gz -RUN curl -fsSL ${WPILIB_DL_URL} -o /tmp/${WPILIB_FILE_NAME} \ +RUN chown 750 /usr/bin/entrypoint.sh \ + && curl -fsSL ${WPILIB_DL_URL} -o /tmp/${WPILIB_FILE_NAME} \ && tar -xzf "/tmp/${WPILIB_FILE_NAME}" -C /tmp \ && WPILIB_ARTIFACTS="$(find /tmp -type f -name 'WPILib_Linux-*-artifacts.tar.gz' -print)" \ && ARTIFACTSYEAR="$(echo $WPILIB_ARTIFACTS | cut -d '-' -f 2 | cut -d '.' -f 1)" \ @@ -66,8 +61,6 @@ RUN curl -fsSL ${WPILIB_DL_URL} -o /tmp/${WPILIB_FILE_NAME} \ && su -c "cp -f /tmp/settings.json /home/coder/.local/share/code-server/User" "coder" \ && su -c "sed -i 's/###YEAR###/$ARTIFACTSYEAR/g;' /home/coder/.local/share/code-server/User/settings.json" "coder" \ && su -c "cp -f /tmp/config.yaml /home/coder/.config/code-server" "coder" \ - && NEW_PASS="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 20; echo)" \ - && su -c "sed -i 's/PASSWORD/$NEW_PASS/g;' /home/coder/.config/code-server/config.yaml" "coder"\ && su -c "cp -f /tmp/project-creator.py /home/coder" "coder" \ && for EXTENSION in /home/coder/wpilib/$ARTIFACTSYEAR/vsCodeExtensions/*.vsix; do su -c "code-server --install-extension $EXTENSION" "coder"; done @@ -76,6 +69,6 @@ EXPOSE 8080 USER coder ENV USER=coder WORKDIR /home/coder -ENTRYPOINT ["/usr/bin/code-server", "--bind-addr", "0.0.0.0:8080", "."] +ENTRYPOINT ["/usr/bin/entrypoint.sh"] diff --git a/Dockerfile.pwsh.fedora b/Dockerfile.pwsh.fedora new file mode 100644 index 0000000..b996b50 --- /dev/null +++ b/Dockerfile.pwsh.fedora @@ -0,0 +1,78 @@ +# syntax=docker/dockerfile:experimental + +FROM fedora:39 + +RUN dnf update -y && dnf install -y \ + curl \ + git \ + git-lfs \ + htop \ + vim \ + nano \ + tar \ + bzip2 \ + unzip \ + python3-pip \ + && rm -rf /var/cache/dnf \ + && git lfs install \ + && curl -fsSL https://code-server.dev/install.sh | sh + +RUN curl -sSL https://packages.microsoft.com/config/rhel/9/packages-microsoft-prod.rpm -o /tmp/ms-prod.rpm \ + && rpm -i /tmp/ms-prod.rpm \ + && rm -f /tmp/ms-prod.rpm \ + && dnf install powershell -y \ + && rm -rf /var/cache/dnf + +RUN useradd -u 1000 coder -s /usr/bin/pwsh + +COPY code-server.tar.gz /tmp +COPY settings.json /tmp +COPY config.yaml /tmp +COPY project-creator.py /tmp +COPY entrypoint.sh /usr/bin + +ARG WPILIB_DL_URL +ARG WPILIB_FILE_NAME=wpilib.tar.gz + +RUN chown 750 /usr/bin/entrypoint.sh \ + && curl -fsSL ${WPILIB_DL_URL} -o /tmp/${WPILIB_FILE_NAME} \ + && tar -xzf "/tmp/${WPILIB_FILE_NAME}" -C /tmp \ + && WPILIB_ARTIFACTS="$(find /tmp -type f -name 'WPILib_Linux-*-artifacts.tar.gz' -print)" \ + && ARTIFACTSYEAR="$(echo $WPILIB_ARTIFACTS | cut -d '-' -f 2 | cut -d '.' -f 1)" \ + && mkdir -p /home/coder/wpilib/$ARTIFACTSYEAR \ + && tar -xzf "$WPILIB_ARTIFACTS" -C /home/coder/wpilib/$ARTIFACTSYEAR \ + && chown -R coder:coder /home/coder/wpilib \ + && rm -f /tmp/${WPILIB_FILE_NAME} \ + && rm -rf "$(find /tmp -type d -name 'WPILib_Linux-*' -print)" \ + && GRADLEZIP="$(ls /home/coder/wpilib/$ARTIFACTSYEAR/installUtils | grep 'gradle-.*-bin.zip')" \ + && GRADLEFOLDER="/home/coder/gradle-$(echo \"$GRADLEZIP\" | cut -d '-' -f 2)" \ + && unzip /home/coder/wpilib/$ARTIFACTSYEAR/installUtils/$GRADLEZIP -d /home/coder/ \ + && chown -R coder:coder $GRADLEFOLDER \ + && mkdir -p /home/coder/.config/powershell \ + && chown -R coder:coder /home/coder/.config \ + && echo "\$JAVA_HOME=/home/coder/wpilib/$ARTIFACTSYEAR/jdk" >> "/home/coder/.config/powershell/Microsoft.PowerShell_profile.ps1" \ + && echo "\$env:PATH+=:/home/coder/wpilib/$ARTIFACTSYEAR/jdk/bin" >> "/home/coder/.config/powershell/Microsoft.PowerShell_profile.ps1" \ + && echo "\$env:PATH+=:$GRADLEFOLDER/bin" >> "/home/coder/.config/powershell/Microsoft.PowerShell_profile.ps1" \ + && su -c "/home/coder/wpilib/$ARTIFACTSYEAR/jdk/bin/java -jar /home/coder/wpilib/$ARTIFACTSYEAR/maven/MavenMetaDataFixer.jar" "coder" \ + && rm -rf /home/coder/wpilib/$ARTIFACTSYEAR/advantagescope \ + && rm -f /home/coder/wpilib/$ARTIFACTSYEAR/installUtils/$GRADLEZIP \ + && rm -rf /home/coder/wpilib/$ARTIFACTSYEAR/tools \ + && rm -rf /home/coder/wpilib/$ARTIFACTSYEAR/documentation \ + && rm -rf /root/.cache \ + && su -c "mkdir -p /home/coder/.local/share" "coder" \ + && su -c "mkdir -p /home/coder/.config/code-server" "coder" \ + && su -c "tar -xzf /tmp/code-server.tar.gz -C /home/coder/.local/share" "coder" \ + && su -c "cp -f /tmp/settings.json /home/coder/.local/share/code-server/User" "coder" \ + && su -c "sed -i 's/###YEAR###/$ARTIFACTSYEAR/g;' /home/coder/.local/share/code-server/User/settings.json" "coder" \ + && su -c "cp -f /tmp/config.yaml /home/coder/.config/code-server" "coder" \ + && su -c "cp -f /tmp/project-creator.py /home/coder" "coder" \ + && for EXTENSION in /home/coder/wpilib/$ARTIFACTSYEAR/vsCodeExtensions/*.vsix; do su -c "code-server --install-extension $EXTENSION" "coder"; done + +EXPOSE 8080 + +USER coder +ENV USER=coder +WORKDIR /home/coder +ENTRYPOINT ["/usr/bin/entrypoint.sh"] + + diff --git a/Dockerfile.pwsh.ubuntu b/Dockerfile.pwsh.ubuntu new file mode 100644 index 0000000..36e6d73 --- /dev/null +++ b/Dockerfile.pwsh.ubuntu @@ -0,0 +1,80 @@ +# syntax=docker/dockerfile:experimental + +FROM ubuntu:24.04 + +RUN apt update -y && apt upgrade -y \ + curl \ + git \ + git-lfs \ + htop \ + vim \ + nano \ + tar \ + bzip2 \ + unzip \ + python3-pip \ + apt-transport-https \ + software-properties-common \ + && apt clean \ + && git lfs install \ + && curl -fsSL https://code-server.dev/install.sh | sh + +RUN source /etc/os-release \ + && curl -sSL https://packages.microsoft.com/config/ubuntu/$VERSION_ID/packages-microsoft-prod.deb -o /tmp/ms-prod.deb \ + && dpkg -i /tmp/ms-prod.deb \ + && rm -f /tmp/ms-prod.deb \ + && apt update \ + && apt install -y powershell \ + && apt clean + +COPY code-server.tar.gz /tmp +COPY settings.json /tmp +COPY config.yaml /tmp +COPY project-creator.py /tmp +COPY entrypoint.sh /usr/bin + +RUN usermod -s /usr/bin/pwsh ubuntu + +ARG WPILIB_DL_URL +ARG WPILIB_FILE_NAME=wpilib.tar.gz + +RUN chown 750 /usr/bin/entrypoint.sh \ + && curl -fsSL ${WPILIB_DL_URL} -o /tmp/${WPILIB_FILE_NAME} \ + && tar -xzf "/tmp/${WPILIB_FILE_NAME}" -C /tmp \ + && WPILIB_ARTIFACTS="$(find /tmp -type f -name 'WPILib_Linux-*-artifacts.tar.gz' -print)" \ + && ARTIFACTSYEAR="$(echo $WPILIB_ARTIFACTS | cut -d '-' -f 2 | cut -d '.' -f 1)" \ + && mkdir -p /home/ubuntu/wpilib/$ARTIFACTSYEAR \ + && tar -xzf "$WPILIB_ARTIFACTS" -C /home/ubuntu/wpilib/$ARTIFACTSYEAR \ + && chown -R ubuntu:ubuntu /home/ubuntu/wpilib \ + && rm -f /tmp/${WPILIB_FILE_NAME} \ + && rm -rf "$(find /tmp -type d -name 'WPILib_Linux-*' -print)" \ + && GRADLEZIP="$(ls /home/ubuntu/wpilib/$ARTIFACTSYEAR/installUtils | grep 'gradle-.*-bin.zip')" \ + && GRADLEFOLDER="/home/ubuntu/gradle-$(echo \"$GRADLEZIP\" | cut -d '-' -f 2)" \ + && unzip /home/ubuntu/wpilib/$ARTIFACTSYEAR/installUtils/$GRADLEZIP -d /home/ubuntu/ \ + && chown -R ubuntu:ubuntu $GRADLEFOLDER \ + && echo "\$JAVA_HOME=/home/ubuntu/wpilib/$ARTIFACTSYEAR/jdk" >> "/home/ubuntu/.config/powershell/Microsoft.PowerShell_profile.ps1" \ + && echo "\$env:PATH+=:/home/ubuntu/wpilib/$ARTIFACTSYEAR/jdk/bin" >> "/home/ubuntu/.config/powershell/Microsoft.PowerShell_profile.ps1" \ + && echo "\$env:PATH+=:$GRADLEFOLDER/bin" >> "/home/ubuntu/.config/powershell/Microsoft.PowerShell_profile.ps1" \ + && su -c "/home/ubuntu/wpilib/$ARTIFACTSYEAR/jdk/bin/java -jar /home/ubuntu/wpilib/$ARTIFACTSYEAR/maven/MavenMetaDataFixer.jar" "ubuntu" \ + && rm -rf /home/ubuntu/wpilib/$ARTIFACTSYEAR/advantagescope \ + && rm -f /home/ubuntu/wpilib/$ARTIFACTSYEAR/installUtils/$GRADLEZIP \ + && rm -rf /home/ubuntu/wpilib/$ARTIFACTSYEAR/tools \ + && rm -rf /home/ubuntu/wpilib/$ARTIFACTSYEAR/documentation \ + && rm -rf /root/.cache \ + && su -c "mkdir -p /home/ubuntu/.local/share" "ubuntu" \ + && su -c "mkdir -p /home/ubuntu/.config/code-server" "ubuntu" \ + && su -c "tar -xzf /tmp/code-server.tar.gz -C /home/ubuntu/.local/share" "ubuntu" \ + && su -c "cp -f /tmp/settings.json /home/ubuntu/.local/share/code-server/User" "ubuntu" \ + && su -c "sed -i 's/###YEAR###/$ARTIFACTSYEAR/g;s/coder/ubuntu/g;' /home/ubuntu/.local/share/code-server/User/settings.json" "ubuntu" \ + && su -c "cp -f /tmp/config.yaml /home/ubuntu/.config/code-server" "ubuntu" \ + && su -c "cp -f /tmp/project-creator.py /home/ubuntu" "ubuntu" \ + && for EXTENSION in /home/ubuntu/wpilib/$ARTIFACTSYEAR/vsCodeExtensions/*.vsix; do su -c "code-server --install-extension $EXTENSION" "ubuntu"; done + +EXPOSE 8080 + +USER ubuntu +ENV USER=ubuntu +WORKDIR /home/ubuntu +ENTRYPOINT ["/usr/bin/entrypoint.sh"] + + diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu index f73a49a..74fc86f 100644 --- a/Dockerfile.ubuntu +++ b/Dockerfile.ubuntu @@ -17,16 +17,6 @@ RUN apt update -y && apt upgrade -y \ && git lfs install \ && curl -fsSL https://code-server.dev/install.sh | sh -RUN mkdir -p /etc/sudoers.d -RUN echo "ubuntu ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nopasswd - -RUN ARCH="$(uname -m | sed 's/x86_64/amd64/g' | sed 's/aarch64/arm64/g')" \ - && curl -fsSL "https://github.com/boxboat/fixuid/releases/download/v0.6.0/fixuid-0.6.0-linux-$ARCH.tar.gz" | tar -C /usr/local/bin -xzf - \ - && chown root:root /usr/local/bin/fixuid \ - && chmod 4755 /usr/local/bin/fixuid \ - && mkdir -p /etc/fixuid \ - && printf "user: ubuntu\ngroup: ubuntu\n" > /etc/fixuid/config.yml - COPY code-server.tar.gz /tmp COPY settings.json /tmp COPY config.yaml /tmp @@ -35,7 +25,8 @@ COPY project-creator.py /tmp ARG WPILIB_DL_URL ARG WPILIB_FILE_NAME=wpilib.tar.gz -RUN curl -fsSL ${WPILIB_DL_URL} -o /tmp/${WPILIB_FILE_NAME} \ +RUN chown 750 /usr/bin/entrypoint.sh \ + && curl -fsSL ${WPILIB_DL_URL} -o /tmp/${WPILIB_FILE_NAME} \ && tar -xzf "/tmp/${WPILIB_FILE_NAME}" -C /tmp \ && WPILIB_ARTIFACTS="$(find /tmp -type f -name 'WPILib_Linux-*-artifacts.tar.gz' -print)" \ && ARTIFACTSYEAR="$(echo $WPILIB_ARTIFACTS | cut -d '-' -f 2 | cut -d '.' -f 1)" \ @@ -67,8 +58,6 @@ RUN curl -fsSL ${WPILIB_DL_URL} -o /tmp/${WPILIB_FILE_NAME} \ && su -c "cp -f /tmp/settings.json /home/ubuntu/.local/share/code-server/User" "ubuntu" \ && su -c "sed -i 's/###YEAR###/$ARTIFACTSYEAR/g;s/coder/ubuntu/g;' /home/ubuntu/.local/share/code-server/User/settings.json" "ubuntu" \ && su -c "cp -f /tmp/config.yaml /home/ubuntu/.config/code-server" "ubuntu" \ - && NEW_PASS="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 20; echo)" \ - && su -c "sed -i 's/PASSWORD/$NEW_PASS/g;' /home/ubuntu/.config/code-server/config.yaml" "ubuntu"\ && su -c "cp -f /tmp/project-creator.py /home/ubuntu" "ubuntu" \ && for EXTENSION in /home/ubuntu/wpilib/$ARTIFACTSYEAR/vsCodeExtensions/*.vsix; do su -c "code-server --install-extension $EXTENSION" "ubuntu"; done @@ -77,6 +66,6 @@ EXPOSE 8080 USER ubuntu ENV USER=ubuntu WORKDIR /home/ubuntu -ENTRYPOINT ["/usr/bin/code-server", "--bind-addr", "0.0.0.0:8080", "."] +ENTRYPOINT ["/usr/bin/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..894ca3a --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +CURRENT_GID="$(id -g coder)" + +if [ -n "${USER_GID}" ] && [ "${USER_GID}" != "${CURRENT_GID}" ]; then + groupmod -g $USER_GID coder + find / -group $CURRENT_GID -exec chgrp -h coder {} \; +fi + +CURRENT_UID="$(id -u coder)" + +if [ -n "${USER_UID}" ] && [ "${USER_UID}" != "${CURRENT_UID}" ]; then + usermod -u $USER_UID coder + find / -user $CURRENT_UID -exec chown -h coder {} \; +fi + +CURRENT_PASSWD=$(grep -E "^Password: .*$" /home/coder/.config/code-server/config.yaml | cut -d ":" -f 2 | awk '{$1=$1;print}') + +if [ -n "${USER_PASSWD}" ] && [ "${CURRENT_PASSWD}" != "${USER_PASSWD}" ] || [ "${CURRENT_PASSWD}" == "PASSWORD"]; then + if [ -n "${USER_PASSWD}" ]; then + USER_PASSWD="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 20; echo)" + fi + + sed -i "s/^PASSWORD: .*$/PASSWORD: ${USER_PASSWD}/g" /home/coder/.config/code-server/config.yaml +fi + +/usr/bin/code-server --bind-addr 0.0.0.0:8080 . \ No newline at end of file diff --git a/setup_cswpilib.sh b/setup_cswpilib.sh deleted file mode 100644 index 6c736a2..0000000 --- a/setup_cswpilib.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env bash - -HELP() { - echo "----------------------------------------------------------" - echo "setup_cswpilib.sh [options] WPILIB_DL_URL" - echo "Install and setup code-server for WPILIB use" - echo "This script needs to be run as root!" - echo "Options:" - echo "\t-h: Show this help" - echo "\t-v: Make the script tell you more about what it is doing" - echo "----------------------------------------------------------" - echo "" -} - -VERBOSE=false - -while getopts "hv" flag; do - case "$flag" in - h) - Help - exit 0;; - v) VERBOSE=true;; - \?) - echo "Unknown option $flag, run setup_cswpilib.sh -h" - exit 1;; - esac -done - -WPILIB_DL_URL = ${@:$OPTIND:1} - -if [ $WPILIB_DL_URL == '' ]; then - echo "You need to specify a WPILIB download URL" - exit 1 -fi - -if [ $(whoami) != 'root' ]; then - echo "This script must be run as root" - exit 2 -fi - -echo "Downloading WPILIB" - -WPILIB_FILE_NAME="$(echo "$WPILIB_DL_URL" | grep -o '[^/]*$')" - -curl -fsSL $WPILIB_DL_URL -o "/tmp/$WPILIB_FILE_NAME" - -echo "Unpacking WPILIB" - -tar -xzf "/tmp/$WPILIB_FILE_NAME" -C "/tmp" - -echo "Unpacking WPILIB-artifacts" - -WPILIB_ARTIFACTS=$(find /tmp -type f -name "WPILib_Linux-*-artifacts.tar.gz" -print) - -if [ ! -d "/opt/wpilib" ]; then - mkdir -p /opt/wpilib -fi - -tar -xzf "$WPILIB_ARTIFACTS" -C "/opt/wpilib" - -find /tmp -type f -name "WPILibInstallerVersion.txt" -exec cp {} /opt/wpilib \; - -echo "Cleanup excess WPILIB files" - -rm -f /tmp/$WPILIB_FILE_NAME -rm -rf "$(find /tmp -type d -name "WPILib_Linux-*" -print)" \ No newline at end of file diff --git a/setup_user.sh b/setup_user.sh deleted file mode 100755 index 0506ae5..0000000 --- a/setup_user.sh +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env bash - -Help() { - echo "------------------------------------------------------------" - echo "setup_user.sh [options] USERNAME" - echo "Configure a new user on the system to use code-server WPILIB" - echo "This script needs to be run as root!" - echo "Options:" - echo "\t-h: Show this help" - echo "\t-v: Make the script tell you more about what it is doing" - echo "------------------------------------------------------------" - echo "" -} - -VERBOSE=false -SCRIPTDIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) - -while getopts "hv" flag; do - case "$flag" in - h) - Help - exit 0;; - v) VERBOSE=true;; - \?) - echo "Unknown option $flag, run setup_user.sh -h" - exit 3;; - esac -done - -USERNAME=${@:$OPTIND:1} -PORT=${@:$OPTIND+1:1} -HOMEDIR=${@:$OPTIND+2:1} - -if [ $USERNAME == '' ]; then - echo "You need to specify a user to setup" - exit 1 -fi - -if [ $(whoami) != 'root' ]; then - echo "This script must be run as root" - exit 2 -fi - -if [ "$(grep -o "$USERNAME" /etc/passwd | uniq)" == "$USERNAME" ]; then - if $VERBOSE; then - echo "User $USERNAME already exists, skipping user creation" - fi -else - useradd -d "$HOMEDIR/$USERNAME" "$USERNAME" -fi - -echo "Unpacking WPILIB" - -HOMEDIR="$(grep "$USERNAME" /etc/passwd | cut -d ':' -f 6)" - -ARTIFACTSNAME="$(ls /opt/wpilib | grep artifacts)" -ARTIFACTSYEAR="$(echo $ARTIFACTSNAME | cut -d '-' -f 2 | cut -d '.' -f 1)" - -if [ ! -d "$HOMEDIR/wpilib/$ARTIFACTSYEAR" ]; then - su -c "mkdir -p ~/wpilib/$ARTIFACTSYEAR" "$USERNAME" -fi - -su -c "tar -xzf /opt/wpilib/$ARTIFACTSNAME -C ~/wpilib/$ARTIFACTSYEAR" "$USERNAME" - -echo "Unpacking Gradle" - -GRADLEZIP="$(ls $HOMEDIR/wpilib/$ARTIFACTSYEAR/installUtils | grep 'gradle-.*-bin.zip')" -GRADLEFOLDER="$HOMEDIR/gradle-$(echo "$GRADLEZIP" | cut -d '-' -f 2)" - -su -c "unzip $HOMEDIR/wpilib/$ARTIFACTSYEAR/installUtils/$GRADLEZIP -d ~/" "$USERNAME" - -echo "Setting up user environment variables" - -if [ -f "$HOMEDIR/.bashrc.d/wpilib.sh" ]; then - rm -f "$HOMEDIR/.bashrc.d/wpilib.sh" -fi - -if [ ! -d "$HOMEDIR/.bashrc.d" ]; then - su -c "mkdir $HOMEDIR/.bashrc.d" "$USERNAME" -fi - -su -c "touch $HOMEDIR/.bashrc.d/wpilib.sh" "$USERNAME" - -echo "export JAVA_HOME=$HOMEDIR/wpilib/$ARTIFACTSYEAR/jdk" >> "$HOMEDIR/.bashrc.d/wpilib.sh" -echo "export PATH=\$PATH:$HOMEDIR/wpilib/$ARTIFACTSYEAR/jdk/bin" >> "$HOMEDIR/.bashrc.d/wpilib.sh" -echo "export PATH=\$PATH:$GRADLEFOLDER/bin" >> "$HOMEDIR/.bashrc.d/wpilib.sh" - -echo "Setting up tools" - -su -c "$HOMEDIR/wpilib/$ARTIFACTSYEAR/jdk/bin/java -jar $HOMEDIR/wpilib/$ARTIFACTSYEAR/tools/ToolsUpdater.jar" "$USERNAME" - -echo "Setting up maven" - -su -c "$HOMEDIR/wpilib/$ARTIFACTSYEAR/jdk/bin/java -jar $HOMEDIR/wpilib/$ARTIFACTSYEAR/maven/MavenMetaDataFixer.jar" "$USERNAME" - -echo "Setting up default code-server configs" - -if [ ! -d "$HOMEDIR/.local/share" ]; then - su -c "mkdir -p ~/.local/share" "$USERNAME" -fi - -if [ ! -d "$HOMEDIR/.config/code-server" ]; then - su -c "mkdir -p ~/.config/code-server" "$USERNAME" -fi - -su -c "tar -xzf $SCRIPTDIR/code-server.tar.gz -C ~/.local/share" "$USERNAME" -su -c "cp -f $SCRIPTDIR/settings.json ~/.local/share/code-server/User" "$USERNAME" -su -c "cp -f $SCRIPTDIR/config.yaml ~/.config/code-server" "$USERNAME" - -echo "Setting specific user configs" - -IP="$(hostname -I | head -n 1 | tr -d ' ')" -NEW_PASS="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 20; echo)" - -su -c "sed -i 's/IPADDRESS:PORT/$IP:$PORT/g;s/PASSWORD/$NEW_PASS/g;' ~/.config/code-server/config.yaml" "$USERNAME" - -echo "Install user extensions" - -for EXTENSION in $HOMEDIR/wpilib/$ARTIFACTSYEAR/vsCodeExtensions/*.vsix; do - echo "Installing extension $EXTENSION" - su -c "code-server --install-extension $EXTENSION" "$USERNAME" -done - -echo "$USERNAME is configured, there password is $NEW_PASS" - -exit 0