mod-manager/install.sh

90 lines
2.0 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 12:33:13 -04:00
rm -rf "$DOWNLOAD_DIR"
mkdir -p "$DOWNLOAD_DIR"
# Verify compatible version of node is installed
info "Verifying node verison..."
NODE_VERSION_STR=$(node --version)
if [[ "$?" -eq 127 ]]
then
error "Node either is not installed, or is not on the root path.\n If you installed Node using NVM, see this link, ensuring links are made for node, npm and npx: https://stackoverflow.com/questions/21215059/cant-use-nvm-from-root-or-sudo"
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
npm install --save
npm install -g @vercel/ncc
2022-08-09 12:55:41 -04:00
npx tsc
2022-08-09 13:40:16 -04:00
2022-08-09 13:44:30 -04:00
if [[ -v $NVM_DIR ]]
2022-08-09 13:40:16 -04:00
then
ln -s "$NVM_DIR/versions/node/$NODE_VERSION_STR/bin/ncc" "/usr/local/bin/ncc"
fi
2022-08-09 12:33:13 -04:00
ncc build build/ts/mod-manager.js -o build/flat
# Install
info "Installing..."
rm -rf "$INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
cp -r build/flat/* "$INSTALL_DIR"
# Creating executable
info "Creating executable..."
2022-08-09 12:55:41 -04:00
echo "node $INSTALL_DIR/index.js \$\@" > $BINARY_PATH
chmod +x $BINARY_PATH
2022-08-09 12:33:13 -04:00
# Cleaning up
info "Cleaning up..."
rm -rf "$DOWNLOAD_DIR"
success "Successfully installed mod-manager. Try mod-manager -h to learn more!"