Compare commits
13 Commits
docker-for
...
docker-rev
Author | SHA1 | Date | |
---|---|---|---|
67075a0094 | |||
be1a59d959 | |||
84a69ac66a | |||
e240561fb9 | |||
1643156ee4 | |||
e3c9d87e61 | |||
31d9a027bb | |||
00992e16c0 | |||
c7a970dadf | |||
02a74081c1 | |||
65865ea2f6 | |||
53a5525de4 | |||
55143adcf6 |
@ -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 chmod 755 /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", "coder"]
|
||||
|
||||
|
||||
|
80
Dockerfile.pwsh.fedora
Normal file
80
Dockerfile.pwsh.fedora
Normal file
@ -0,0 +1,80 @@
|
||||
# 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
|
||||
|
||||
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 chmod 755 /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
|
||||
|
||||
RUN usermod -s /usr/bin/pwsh coder
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
USER coder
|
||||
ENV USER=coder
|
||||
WORKDIR /home/coder
|
||||
ENTRYPOINT ["/usr/bin/entrypoint.sh", "coder"]
|
||||
|
||||
|
81
Dockerfile.pwsh.ubuntu
Normal file
81
Dockerfile.pwsh.ubuntu
Normal file
@ -0,0 +1,81 @@
|
||||
# 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 curl -sSL https://packages.microsoft.com/config/ubuntu/24.04/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
|
||||
|
||||
ARG WPILIB_DL_URL
|
||||
ARG WPILIB_FILE_NAME=wpilib.tar.gz
|
||||
|
||||
RUN chmod 755 /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 \
|
||||
&& mkdir -p /home/ubuntu/.config/powershell \
|
||||
&& chown -R ubuntu:ubuntu /home/ubuntu/.config \
|
||||
&& 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
|
||||
|
||||
RUN usermod -s /usr/bin/pwsh ubuntu
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
USER ubuntu
|
||||
ENV USER=ubuntu
|
||||
WORKDIR /home/ubuntu
|
||||
ENTRYPOINT ["/usr/bin/entrypoint.sh", "ubuntu"]
|
||||
|
||||
|
@ -17,25 +17,17 @@ 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
|
||||
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 chmod 755 /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 +59,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 +67,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", "ubuntu"]
|
||||
|
||||
|
||||
|
23
README.md
Normal file
23
README.md
Normal file
@ -0,0 +1,23 @@
|
||||
# Code Server for WPILIB
|
||||
|
||||
This project provides Dockerfiles that can be used to create container images that serve a web based version of the VSCode programming environment for WPILIB programming.
|
||||
|
||||
This is NOT a replacement for a decent programming computer for your build space (see the Caveats section), but more a way to provide the ability to program to students who may not have access to a computer where they are allowed to install software (school computers, family computers, etc.)
|
||||
|
||||
### Getting Started
|
||||
|
||||
You have to built the container images yourself before you can start. (See the Why Don't You Provide the Container Images? section for why).
|
||||
|
||||
You need to select which overarching distro you want the container to be based on. For most users this isn't super important, but the option is there for those who care. There are currently two stable options:
|
||||
|
||||
- Dockerfile.ubuntu (which is likely what most people will want, as it'll be very similar to existing experiences with distros like Raspberry Pi OS)
|
||||
- Dockerfile.fedora (for those in the community who prefer/are familar with RHEL/OracleLinux or similar)
|
||||
|
||||
1. Install [Docker](https://docs.docker.com/engine/install/)
|
||||
2. Open your terminal of choice
|
||||
3. Clone this project using git, and "cd" to the cloned folder
|
||||
4. Run the following command
|
||||
```docker build --build-arg WPILIB_DL_URL=<DL_URL> -f <DockerFile> -t code-server-wpilib:latest .```
|
||||
The <DL_URL> should be the Linux image appropriate to your platform from the [releases page](https://github.com/wpilibsuite/allwpilib/releases). The <DockerFile> will either be Dockerfile.ubuntu or Dockerfile.fedora
|
||||
5. Start an instance of the container ```docker run -d -p 8080:8080 --name <instance_name> code-server-wpilib:latest```
|
||||
|
34
entrypoint.sh
Normal file
34
entrypoint.sh
Normal file
@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
CURRENT_GID=$(id -g $1)
|
||||
echo "Current GID: $CURRENT_GID"
|
||||
|
||||
if [ -n "$USER_GID" ] && [ "$USER_GID" != "$CURRENT_GID" ]; then
|
||||
echo "Changing GID to $USER_GID"
|
||||
groupmod -g $USER_GID $1
|
||||
find / -group $CURRENT_GID -exec chgrp -h $1 {} \;
|
||||
fi
|
||||
|
||||
CURRENT_UID=$(id -u $1)
|
||||
echo "Current UID: $CURRENT_UID"
|
||||
|
||||
if [ -n "$USER_UID" ] && [ "$USER_UID" != "$CURRENT_UID" ]; then
|
||||
echo "Changing UID to $USER_UID"
|
||||
usermod -u $USER_UID $1
|
||||
find / -user $CURRENT_UID -exec chown -h $1 {} \;
|
||||
fi
|
||||
|
||||
CURRENT_PASSWD=$(grep -E "^password: .*$" /home/$1/.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
|
||||
echo "Changing password"
|
||||
if [ -z "$USER_PASSWD" ]; then
|
||||
echo "Setting a new password at random"
|
||||
USER_PASSWD=$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 20; echo)
|
||||
fi
|
||||
|
||||
sed -i "s/^password: .*$/password: $USER_PASSWD/g" /home/$1/.config/code-server/config.yaml
|
||||
echo "Result of sed call: $?"
|
||||
fi
|
||||
|
||||
/usr/bin/code-server --bind-addr 0.0.0.0:8080 .
|
@ -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)"
|
126
setup_user.sh
126
setup_user.sh
@ -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
|
Loading…
Reference in New Issue
Block a user