mod-manager/install.sh

85 lines
1.9 KiB
Bash
Raw Normal View History

2022-08-09 12:33:13 -04:00
#!/bin/bash
MIN_NODE_VERSION=12
DOWNLOAD_DIR="/tmp/mod-manager-install"
INSTALL_DIR="/usr/local/lib/mod-manager"
2022-08-09 12:55:41 -04:00
BINARY_PATH="/usr/bin/mod-manager"
2022-08-09 12:33:13 -04:00
CYAN="\033[1;96m"
RED="\033[0;91m"
GREEN="\033[0;92m"
RESET='\033[0m'
print () {
echo -e "$1 $2 $RESET"
}
info () {
print "$CYAN" "$1"
}
error() {
print "$RED" "$1"
}
success() {
print "$GREEN" "$1"
}
2022-08-09 12:55:41 -04:00
if [ "$EUID" -ne 0 ]
then
error "This script must be ran as root. Please use sudo."
exit
fi
2022-08-09 13:56:14 -04:00
rm -rf "$DOWNLOAD_DIR" || exit
mkdir -p "$DOWNLOAD_DIR" || exit
2022-08-09 12:33:13 -04:00
# Verify compatible version of node is installed
info "Verifying node verison..."
2022-08-09 13:56:14 -04:00
NODE_VERSION_STR=$(node --version) || exit
if [[ "$?" -eq 127 ]]
then
2022-08-09 13:52:10 -04:00
error "Node does not appear to be installed. Please install Node version $MIN_NODE_VERSION or higher"
exit
fi
NODE_VERSION=$( (echo $NODE_VERSION_STR | sed 's/\..*//') | sed "s/v//")
2022-08-09 12:33:13 -04:00
if [[ "$NODE_VERSION" -ge "$MIN_NODE_VERSION" ]]
then
success "A version of node greater than $MIN_NODE_VERSION is installed!"
else
error "A version of node greater than $MIN_NODE_VERSION is required. Please install it and re run this install script"
exit
fi
# Download source files
info "Downloading mod-manager source..."
2022-08-09 12:55:41 -04:00
git clone "https://hogwarts.bits.team/git/Bits/mod-manager.git" "$DOWNLOAD_DIR" || exit
2022-08-09 12:33:13 -04:00
# Compile
info "Compiling..."
cd "$DOWNLOAD_DIR" || exit
2022-08-09 13:56:14 -04:00
npm install --save || exit
npm install -g @vercel/ncc || exit
npx tsc || exit
ncc build build/ts/mod-manager.js -o build/ || exit
2022-08-09 12:33:13 -04:00
# Install
info "Installing..."
2022-08-09 13:56:14 -04:00
rm -rf "$INSTALL_DIR" || exit
mkdir -p "$INSTALL_DIR" || exit
2022-08-09 12:33:13 -04:00
2022-08-09 13:56:14 -04:00
cp -r build/flat/* "$INSTALL_DIR" || exit
2022-08-09 12:33:13 -04:00
# Creating executable
info "Creating executable..."
2022-08-09 13:56:14 -04:00
echo "node $INSTALL_DIR/index.js \$\@" > $BINARY_PATH || exit
chmod +x $BINARY_PATH || exit
2022-08-09 12:33:13 -04:00
# Cleaning up
info "Cleaning up..."
2022-08-09 13:56:14 -04:00
rm -rf "$DOWNLOAD_DIR" || exit
2022-08-09 12:33:13 -04:00
success "Successfully installed mod-manager. Try mod-manager -h to learn more!"