Skip to content

Commit

Permalink
Flourishes
Browse files Browse the repository at this point in the history
  • Loading branch information
crhultay authored Nov 27, 2024
1 parent 595ade9 commit f200182
Showing 1 changed file with 76 additions and 38 deletions.
114 changes: 76 additions & 38 deletions misc/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,50 @@
ENIGMA_BRANCH=${ENIGMA_BRANCH:=master}
ENIGMA_INSTALL_DIR=${ENIGMA_INSTALL_DIR:=$HOME/enigma-bbs}
ENIGMA_SOURCE=${ENIGMA_SOURCE:=https://github.com/NuSkooler/enigma-bbs.git}
ENIGMA_INSTALL_LOG=~/enigma-install.log
TIME_FORMAT=`date "+%Y-%m-%d %H:%M:%S"`

# ANSI Codes
RESET="\e[0m"
BOLD="\e[1m"
UNDERLINE="\e[4m"
INVERSE="\e7m"
FOREGROUND_BLACK="\e[30m"
FOREGROUND_RED="\e[31m"
FOREGROUND_GREEN="\e[32m"
FOREGROUND_YELLOW="\e[33m"
FOREGROUND_BLUE="\e[34m"
FOREGROUND_MAGENTA="\e[35m"
FOREGROUND_CYAN="\e[36m"
FOREGROUND_WHITE="\e[37m"
BACKGROUND_BLACK="\e[40m"
BACKGROUND_RED="\e[41m"
BACKGROUND_GREEN="\e[42m"
BACKGROUND_YELLOW="\e[43m"
BACKGROUND_BLUE="\e[44m"
BACKGROUND_MAGENTA="\e[45m"
BACKGROUND_CYAN="\e[46m"
BACKGROUND_WHITE="\e[47m"
FOREGROUND_STRONG_WHITE="\e[90m"
FOREGROUND_STRONG_RED="\e[91m"
FOREGROUND_STRONG_GREEN="\e[92m"
FOREGROUND_STRONG_YELLOW="\e[93m"
FOREGROUND_STRONG_BLUE="\e[94m"
FOREGROUND_STRONG_MAGENTA="\e[95m"
FOREGROUND_STRONG_CYAN="\e[96m"
FOREGROUND_STRONG_WHITE="\e[97m"
BACKGROUND_STRONG_BLACK="\e[100m"
BACKGROUND_STRONG_RED="\e[101m"
BACKGROUND_STRONG_GREEN="\e[102m"
BACKGROUND_STRONG_YELLOW="\e[103m"
BACKGROUND_STRONG_BLUE="\w[104m"
BACKGROUND_STRONG_MAGENTA="\e[105m"
BACKGROUND_STRONG_CYAN="\e[106m"
BACKGROUND_STRONG_WHITE="\e[107m"

enigma_header() {
clear
echo -e "$FOREGROUND_STRONG_WHITE"
cat << EndOfMessage
______
_____________________ _____ ____________________ __________\\_ /
Expand All @@ -19,18 +59,16 @@ _____________________ _____ ____________________ __________\\_ /
<*> ENiGMA½ // https://github.com/NuSkooler/enigma-bbs <*> /__/
Installing ENiGMA½:
ENiGMA½:
Source : ${ENIGMA_SOURCE} (${ENIGMA_BRANCH} branch)
Destination: ${ENIGMA_INSTALL_DIR}
>> If this isn't what you were expecting, hit CTRL-C now!
>> Installation will continue in ${WAIT_BEFORE_INSTALL} seconds...
EndOfMessage
echo -e "$RESET"
}

fatal_error() {
printf "${TIME_FORMAT} \e[41mERROR:\033[0m %b\n" "$*" >&2;
echo -e "${TIME_FORMAT} \e[41mERROR:\033[0m %b\n" "$*" >&2;
exit 1
}

Expand All @@ -39,22 +77,12 @@ check_exists() {
}

enigma_install_needs_ex() {
echo -ne "Checking for '$1'..."
echo -ne "${FOREGROUND_GREEN}Checking for '$1'...${RESET}"
if check_exists $1 ; then
echo " Found!"
echo -e "${FOREGROUND_STRONG_GREEN} Found!${RESET}"
else
echo ""
fatal_error "ENiGMA½ requires '$1' but it was not found. Please install it and/or make sure it is in your path then restart the installer.\n\n$2"
fi
}

enigma_install_needs_python() {
echo -ne "Checking for a suitable Python installation..."
if check_exists "python" || check_exists "python7" || check_exists "python3" ; then
echo " Found!"
else
echo ""
fatal_error "ENiGMA½ requires Python for node-gyp to build binaries. Please see https://www.npmjs.com/package/node-gyp for details."
fatal_error "${FOREGROUND_STRONG_RED}ENiGMA½ requires '$1' but it was not found. Please install it and/or make sure it is in your path then restart the installer.\n\n$2${RESET}"
fi
}

Expand All @@ -63,23 +91,22 @@ enigma_install_needs() {
}

enigma_has_mise() {
echo -ne "Checking for an installation of mise-en-place (https://mise.jdx.dev/)"
echo -e "${FOREGROUND_GREEN}Checking for an installation of mise-en-place (https://mise.jdx.dev/)${RESET}"
if check_exists "mise"; then
echo " Found!"
echo -e "${FOREGROUND_STRONG_GREEN} Found!${RESET}"
else
echo ""
fatal_error "ENiGMA½ requires mise-enplace to install dependencies."
fatal_error "${FOREGROUND_STRONG_RED}ENiGMA½ requires mise-enplace to install dependencies.${RESET}"
fi
}

log() {
printf "${TIME_FORMAT} %b\n" "$*";
echo -e "${TIME_FORMAT} %b\n" "$*";
}

enigma_install_init() {
enigma_install_needs git
enigma_install_needs curl
enigma_install_needs_python
enigma_install_needs_ex make "Examples:\n sudo apt install build-essential # Debian/Ubuntu\n sudo yum groupinstall 'Development Tools' # CentOS"
enigma_install_needs make
enigma_install_needs gcc
Expand All @@ -93,7 +120,7 @@ install_mise_en_place() {

cd $ENIGMA_INSTALL_DIR

mise install
mise install >> ${ENIGMA_INSTALL_LOG}

export PATH="$HOME/.local/share/mise/shims:$PATH"
}
Expand All @@ -108,14 +135,14 @@ download_enigma_source() {
INSTALL_DIR=${ENIGMA_INSTALL_DIR}

if [ -d "$INSTALL_DIR/.git" ]; then
log "ENiGMA½ is already installed in $INSTALL_DIR, trying to update using git"
log "${FOREGROUND_YELLOW}ENiGMA½ is already installed in $INSTALL_DIR, trying to update using git...${RESET}"
command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch 2> /dev/null ||
fatal_error "Failed to update ENiGMA½, run 'git fetch' in $INSTALL_DIR yourself."
fatal_error "${FOREGROUND_STRONG_RED}Failed to update ENiGMA½, run 'git fetch' in $INSTALL_DIR yourself.${RESET}"
else
log "Downloading ENiGMA½ from git to '$INSTALL_DIR'"
log "${FOREGROUND_GREEN}Downloading ENiGMA½ from git to '$INSTALL_DIR'${RESET}"
mkdir -p "$INSTALL_DIR"
command git clone ${ENIGMA_SOURCE} "$INSTALL_DIR" ||
fatal_error "Failed to clone ENiGMA½ repo. Please report this!"
fatal_error "${FOREGROUND_STRONG_RED}Failed to clone ENiGMA½ repo. Please report this!${RESET}"
fi
}

Expand All @@ -137,22 +164,23 @@ extra_npm_install_args() {
}

install_node_packages() {
log "Installing required Node packages..."
log "Note that on some systems such as RPi, this can take a VERY long time. Be patient!"
log "${FOREGROUND_GREEN}Installing required Node packages...${RESET}"
log "${FOREGROUND_YELLOW}Note that on some systems such as RPi, this can take a VERY long time. Be patient!${RESET}"

cd ${ENIGMA_INSTALL_DIR}
local EXTRA_NPM_ARGS=$(extra_npm_install_args)
git checkout ${ENIGMA_BRANCH}

npm install ${EXTRA_NPM_ARGS}
npm install ${EXTRA_NPM_ARGS} >> $ENIGMA_INSTALL_LOG
if [ $? -eq 0 ]; then
log "npm package installation complete"
log "${FOREGROUND_STRONG_GREEN}npm package installation complete${RESET}"
else
fatal_error "Failed to install ENiGMA½ npm packages. Please report this!"
fatal_error "${FOREGROUND_STRONG_RED}Failed to install ENiGMA½ npm packages. Please report this and refer to ~/enigma-install.log!{$RESET}"
fi
}

copy_template_files() {
log "${FOREGROUND_GREEN}Copying Template Files to ${ENIGMA_INSTALL_DIR}/misc/gophermap${RESET}"
echo $ENIGMA_INSTALL_DIR
if [[ ! -f "$ENIGMA_INSTALL_DIR/gopher/gophermap" ]]; then
cp "$ENIGMA_INSTALL_DIR/misc/gophermap" "$ENIGMA_INSTALL_DIR/gopher/gophermap"
Expand All @@ -161,7 +189,7 @@ copy_template_files() {

enigma_footer() {
log "ENiGMA½ installation complete!"
echo -e "\e[1;33m"
echo -e "${FOREGROUND_YELLOW}"
cat << EndOfMessage
ADDITIONAL ACTIONS ARE REQUIRED!
Expand Down Expand Up @@ -216,19 +244,23 @@ ADDITIONAL ACTIONS ARE REQUIRED!
Run 'sudo systemctl enable bbs.service'
EndOfMessage
echo -e "\e[39m"
echo -e "${RESET}"
}

post_install() {
MISE_SHIM_PATH_COMMAND='export PATH="$HOME/.local/share/mise/shims:$PATH"'
if ! grep -Fxq "$MISE_SHIM_PATH_COMMAND" ~/.bashrc
if grep -Fxq "$MISE_SHIM_PATH_COMMAND" ~/.bashrc
then
log "${FOREGROUND_STRONG_GREEN}Mise Shims found in your ~/.bashrc${RESET}"
else
echo $MISE_SHIM_PATH_COMMAND >> ~/.bashrc
echo -e "\e[0;32mInstalled Mise Shims into your ~/.bashrc\e[39m"
log "${FOREGROUND_STRONG_YELLOW}Installed Mise Shims into your ~/.bashrc${RESET}"
fi
}

install_dependencies() {
log "${FOREGROUND_GREEN}Installing Dependencies...$RESET"

enigma_install_init
install_mise_en_place
install_tools
Expand All @@ -237,11 +269,14 @@ install_dependencies() {
}

install_bbs() {
log "${FOREGROUND_GREEN}Installing ENiGMA½...$RESET"

download_enigma_source
copy_template_files
}

install_everything() {
log "${FOREGROUND_STRONG_GREEN}Installing Everything...$RESET"
download_enigma_source
install_dependencies
copy_template_files
Expand All @@ -264,13 +299,16 @@ menu() {
2) install_bbs; break;;
3) enigma_install_init; install_everything; break;;
$((${#options[@]}+1))) echo "Goodbye!"; exit 0;;
*) echo "Invalid option. Try another one.";continue;;
*) echo -e "${FOREGROUND_STRONG_RED}Invalid option.${RESET}";continue;;
esac
done < /dev/tty

unset PS3
}

# Reset Logfile
rm $ENIGMA_INSTALL_LOG

enigma_header
menu
enigma_footer
Expand Down

0 comments on commit f200182

Please sign in to comment.