Skip to content

Instantly share code, notes, and snippets.

@mimicmod
Last active December 25, 2023 23:14
Show Gist options
  • Save mimicmod/617fe20487beea0e0dfb to your computer and use it in GitHub Desktop.
Save mimicmod/617fe20487beea0e0dfb to your computer and use it in GitHub Desktop.
uHub MiMic Mod install and config script
#!/bin/bash
# uHub MiMic Mod install and config script
# Dependencies:
# - bash
# - git
# - all other uhub dependencies
echo -e "\e[1;34mHello, this script will install uhub MiMic Mod on your machine and configure your hub.\e[0m"
echo
echo -n "Proceed? [Y/n]:"
read -n 1 response
if [[ $response =~ ^(N|n) ]]; then
echo
echo -e "\e[1;31mYou answered NO, exiting ...\e[0m"
exit 1
fi
if [[ ! $response =~ ^(Y|y|N|n) ]]; then
echo
echo -e "\e[1;31mYour answer is invalid, defaulting to answer NO, exiting ...\e[0m"
exit 1
fi
if [[ $response =~ ^(Y|y) ]]; then
cwd=$(pwd)
echo
echo
echo -e "\e[1;34mStep 1 - Clone from git\e[0m"
echo
echo -n "Specify source code clone destination directory (default: $cwd/uhub):"
read srcpath
if [ -z $srcpath ]; then
srcpath="$cwd/uhub"
fi
echo -e "\e[1;35mRunning git clone...\e[0m"
git clone git://github.com/mimicmod/uhub $srcpath || { echo -e "\e[1;31mGit clone failed.\e[0m"; exit 1; }
echo
echo -e "\e[1;32mGit clone successful.\e[0m"
echo
echo -e "\e[1;34mStep 2 - Install uHub\e[0m"
echo
cd $srcpath
echo
echo -e "\e[1;35mConfiguring build...\e[0m"
cmake CMakeLists.txt || { echo -e "\e[1;31mBuild configuration failed.\e[0m"; exit 1; }
echo
echo -e "\e[1;35mRunning make install...\e[0m"
echo
make install || { echo -e "\e[1;31mMake install failed.\e[0m"; exit 1; }
echo
echo -e "\e[1;32muHub install successful."
echo
echo -e "\e[1;34mStep 3 - Hub configuration"
echo
echo -e "\e[1;31mWarning: This script uses these defaults:"
echo -e "\e[1;31m1) /etc/uhub as default directory for all config files and databases,"
echo -e "\e[1;31m2) /etc/uhub/uhub.conf as the main hub config file"
echo -e "\e[1;31m3) /etc/uhub/plugins.conf as plugin configuration file"
echo -e "\e[1;31m4) /usr/lib/uhub as path to plugin libraries.\e[0m"
echo
echo -n "Continue? [Y/n]:"
read -n 1 response_paths
if [[ ! $response_paths =~ ^(Y|y|N|n) ]]; then
echo
echo -e "\e[1;31mYour answer is invalid, defaulting to answer NO, exiting ...\e[0m"
exit 1
fi
if [[ $response_paths =~ ^(N|n) ]]; then
echo
echo -e "\e[1;31mYou answered NO, exiting ...\e[0m"
exit 1
fi
if [[ $response_paths =~ ^(Y|y) ]]; then
echo
echo -n "Hub name (default: my hub):"
read hubname
echo -n "Hub description (default: Powered by uHub):"
read hubdesc
echo -n "Bind IP. Specifies IP address the hub uses to listen for connections. Enter a valid IPv4 or IPv6 or any. Any uses 0.0.0.0 or ::1 (default: any):"
read hublistenaddr
echo -n "Listen port. Specifies the port the hub uses to listen for connections. Enter a valid number from interval between 1 and 65535 (default: 1511):"
read hublistenport
echo -n "Maximum users. Enter a valid number greater than zero (default: 500):"
read hubmaxusers
echo
echo -e "\e[1;35mCommiting changes to config file /etc/uhub/uhub.conf...\e[0m"
if [ -z "$hubname" ]; then
hubname="my hub"
fi
if [ -z "$hubdesc" ]; then
hubdesc="Powered by uHub"
fi
if [ -z $hublistenaddr ]; then
hublistenaddr="any"
fi
if [ -z $hublistenport ]; then
hublistenport="1511"
fi
if [ -z $hubmaxusers ]; then
hubmaxusers="500"
fi
sed -i "s/hub_name=my hub/hub_name=$hubname/g" /etc/uhub/uhub.conf || { echo -e "\e[1;31mChange hub_name variable failed.\e[0m"; exit 1; }
sed -i "s/hub_description=Powered by uHub/hub_description=$hubdesc/g" /etc/uhub/uhub.conf || { echo -e "\e[1;31mChange hub_description variable failed.\e[0m"; exit 1; }
sed -i "s/server_bind_addr=any/server_bind_addr=$hublistenaddr/g" /etc/uhub/uhub.conf || { echo -e "\e[1;31mChange server_bind_addr variable failed.\e[0m"; exit 1; }
sed -i "s/server_port=1511/server_port=$hublistenport/g" /etc/uhub/uhub.conf || { echo -e "\e[1;31mChange server_port variable failed.\e[0m"; exit 1; }
sed -i "s/max_users=500/max_users=$hubmaxusers/g" /etc/uhub/uhub.conf || { echo -e "\e[1;31mChange max_users variable failed.\e[0m"; exit 1; }
echo
echo -e "\e[1;32mChanges to /etc/uhub/uhub.conf commited successfully.\e[0m"
echo
echo -e "\e[1;34mStep 4 - Plugins configuration\e[0m"
echo
echo -n "Enable sqlite based user authentication? (Default: YES) [Y/n]:"
read -n 1 modsqliteauth
echo
echo -n "Enable topic/description commands? (Default: NO) [Y/n]:"
read -n 1 modtopic
echo
echo -n "Enable logging user info on login/logout? (Default: NO) [Y/n]:"
read -n 1 modlogging
if [[ $modlogging =~ ^(Y|y) ]]; then
echo
echo -n "Log user info to sqlite database? Answer NO logs user info to a text file (recommended: YES) [Y/n]:"
read -n 1 modloggingsqlite
fi
echo
echo -n "Enable common welcome message and rules? (Default: NO) [Y/n]:"
read -n 1 modwelcome
echo
echo -n "Enable individual login messages? (Default: NO) [Y/n]:"
read -n 1 modjoins
echo
echo -n "Enable main chat logging? (Default: NO) [Y/n]:"
read -n 1 modchathist
if [[ $modchathist =~ ^(Y|y) ]]; then
echo
echo -n "Log min chat to sqlite database? Answer NO logs to memory and is discarded on hub reload/restart (recommended: YES) [Y/n]:"
read -n 1 modchathistsqlite
fi
echo
echo -n "Enable extras? Provides hubnews, friendly hubs list and releases list (default: NO) [Y/n]:"
read -n 1 modextras
echo
echo -n "Enable restricted hub? Offers admins to restrict some user rights (default: NO) [Y/n]:"
read -n 1 modrestrict
echo
echo -n "Enable antispam? Offers basic antispam for main chat and private messages based on PCRE patterns (default: NO) [Y/n]:"
read -n 1 modpatterns
echo
echo
echo -e "\e[1;35mCommiting changes to plugins config file /etc/uhub/plugins.conf...\e[0m"
needsadmin=1
if [[ $modsqliteauth =~ ^(N|n) ]]; then
needsadmin=0
sed -i 's/plugin \/usr\/lib\/uhub\/mod_auth_sqlite.so/#plugin \/usr\/lib\/uhub\/mod_auth_sqlite.so/g' /etc/uhub/plugins.conf || { echo -e "\e[1;31mFailed to enable mod_auth_sqlite.so.\e[0m"; exit 1; }
fi
if [[ $modtopic =~ ^(Y|y) ]]; then
sed -i 's/#plugin \/usr\/lib\/uhub\/mod_topic.so/plugin \/usr\/lib\/uhub\/mod_topic.so/g' /etc/uhub/plugins.conf || { echo -e "\e[1;31mFailed to enable mod_topic.so.\e[0m"; exit 1; }
fi
if [[ $modlogging =~ ^(Y|y) ]]; then
if [[ $modloggingsqlite =~ ^(Y|y) ]]; then
sed -i 's/#plugin \/usr\/lib\/uhub\/mod_logging_sqlite.so/plugin \/usr\/lib\/uhub\/mod_logging_sqlite.so/g' /etc/uhub/plugins.conf || { echo -e "\e[1;31mFailed to enablemod_logging_sqlite.so.\e[0m"; exit 1; }
else
sed -i 's/#plugin \/usr\/lib\/uhub\/mod_logging_.so/plugin \/usr\/lib\/uhub\/mod_logging.so/g' /etc/uhub/plugins.conf || { echo -e "\e[1;31mFailed to enable mod_logging.so.\e[0m"; exit 1; }
fi
fi
if [[ $modwelcome =~ ^(Y|y) ]]; then
sed -i 's/#plugin \/usr\/lib\/uhub\/mod_welcome.so/plugin \/usr\/lib\/uhub\/mod_welcome.so/g' /etc/uhub/plugins.conf || { echo -e "\e[1;31mFailed to enable mod_welcome.so.\e[0m"; exit 1; }
fi
if [[ $modjoins =~ ^(Y|y) ]]; then
sed -i 's/#plugin \/usr\/lib\/uhub\/mod_joins.so/plugin \/usr\/lib\/uhub\/mod_joins.so/g' /etc/uhub/plugins.conf || { echo -e "\e[1;31mFailed to enable mod_joins.so.\e[0m"; exit 1; }
fi
if [[ $modchathist =~ ^(Y|y) ]]; then
if [[ $modchathistsqlite =~ ^(Y|y) ]]; then
sed -i 's/#plugin \/usr\/lib\/uhub\/mod_chat_history_sqlite.so/plugin \/usr\/lib\/uhub\/mod_chat_history_sqlite.so/g' /etc/uhub/plugins.conf || { echo -e "\e[1;31mFailed to enable mod_chat_history_sqlite.so.\e[0m"; exit 1; }
else
sed -i 's/#plugin \/usr\/lib\/uhub\/mod_chat_history.so/plugin \/usr\/lib\/uhub\/mod_chat_history.so/g' /etc/uhub/plugins.conf || { echo -e "\e[1;31mFailed to enable mod_chat_history.so.\e[0m"; exit 1; }
fi
fi
if [[ $modextras =~ ^(Y|y) ]]; then
sed -i 's/#plugin \/usr\/lib\/uhub\/mod_extras.so/plugin \/usr\/lib\/uhub\/mod_extras.so/g' /etc/uhub/plugins.conf || { echo -e "\e[1;31mFailed to enable mod_extras.so.\e[0m"; exit 1; }
fi
if [[ $modrestrict =~ ^(Y|y) ]]; then
sed -i 's/#plugin \/usr\/lib\/uhub\/mod_restrict.so/plugin \/usr\/lib\/uhub\/mod_restrict.so/g' /etc/uhub/plugins.conf || { echo -e "\e[1;31mFailed to enable mod_restrict.so.\e[0m"; exit 1; }
fi
if [[ $modpatterns =~ ^(Y|y) ]]; then
sed -i 's/#plugin \/usr\/lib\/uhub\/mod_patterns.so/plugin \/usr\/lib\/uhub\/mod_patterns.so/g' /etc/uhub/plugins.conf || { echo -e "\e[1;31mFailed to enable mod_patterns.so.\e[0m"; exit 1; }
fi
echo
echo -e "\e[1;32mChanges to /etc/uhub/plugins.conf commited sucessfully.\e[0m"
echo
if [[ $needsadmin == 1 ]]; then
echo -e "\e[1;34mStep 5 - Admin account\e[0m"
echo
echo -n "Enter admin account nickname:"
read adminnick
echo -n "Set admin password:"
read adminpass
echo
echo -e "\e[1;35mCreating sqlite database and users table...\e[0m"
sqlite3 /etc/uhub/users.db <<- EOF
CREATE TABLE users(
nickname CHAR NOT NULL UNIQUE,
password CHAR NOT NULL,
credentials CHAR NOT NULL DEFAULT 'user',
created TIMESTAMP DEFAULT (DATETIME('NOW')),
activity TIMESTAMP DEFAULT (DATETIME('NOW'))
);
EOF
echo
echo -e "\e[1;35mCreating admin user account...\e[0m"
sqlite3 --line /etc/uhub/users.db "INSERT INTO users VALUES(\"$adminnick\",\"$adminpass\",\"admin\",NULL,NULL);" || { echo -e "\e[1;31mFailed to create admin user account.\e[0m"; exit 1; }
echo
echo -e "\e[1;32mAdmin user account created."
echo
fi
fi
echo -e "\e[1;34mYour hub is configured and ready to use. Enjoy.\e[0m"
exit 0
fi
# Exit with error, everything went wrong when we got here.
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment