code-server-wpilib/setup_cswpilib.sh

66 lines
1.6 KiB
Bash

#!/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)"