Skip to content

Instantly share code, notes, and snippets.

@A248
Last active January 6, 2020 18:04
Show Gist options
  • Save A248/bb73e1577df318fc358df40c6cb902f5 to your computer and use it in GitHub Desktop.
Save A248/bb73e1577df318fc358df40c6cb902f5 to your computer and use it in GitHub Desktop.
Manual updater script for NamelessMC v2.0.0-pr6 -> v2.0.0-pr7
#!/bin/bash
OUTPUT_FILE="NamelessManualUpdater_v2.0.0-pr6.txt"
printf "\n"
echo -n "NamelessMC Manual Updater by A248"
printf "\n\n\n"
echo "This script will generate a series of queries for you to execute on your MySQL database. You will have to login using \"mysql -u root -p\" or similar. You should copy and paste the statements in the output file, $OUTPUT_FILE, and execute them."
printf "\n\n\n"
echo -n "Version 2.0.0pr6 -> 2.0.0pr7"
printf "\n"
# parameters
# $1 - the shutdown statement.
kill_script () {
echo "$1"
printf "\n"
echo "Exiting..."
exit 1
}
echo -n "Is this the correct version? (Y/N) "
read IS_CORRECT_VER
if [ "$IS_CORRECT_VER" == "N" ] || [ "$IS_CORRECT_VER" == "n" ]; then
kill_script "Alright. Make sure to use the correct version next time."
fi
echo ""
echo -n "Database Engine (InnoDB or MyISAM): "
read DB_ENGINE
if [ "$DB_ENGINE" != "InnoDB" ] && [ "$DB_ENGINE" != "InnoDB" ]; then
kill_script "Invalid database engine specified: $DB_ENGINE."
fi
echo ""
echo -n "Charset (utf8mb4 or latin1): "
read DB_CHARSET
if [ "$DB_CHARSET" != "utf8mb4" ] && [ "$DB_CHARSET" != "latin1" ]; then
kill_script "Invalid charset specified: $DB_CHARSET."
fi
[ ! -e $OUTPUT_FILE ] || rm $OUTPUT_FILE
# parameters
# $1 - the query to execute
mysql_exec () {
echo "$1;" >> $OUTPUT_FILE
}
# parameters
# $1 - the table without the prefix
# $2 - the column name
# $3 - the new data type
mysql_alter_column () {
mysql_exec "ALTER TABLE \`nl2_$1\` MODIFY \`$2\` $3"
}
# parameters
# $1 - the table name
# $2 - the column names and types
mysql_create_table () {
mysql_exec "CREATE TABLE IF NOT EXISTS \`nl2_$1\` ($2) ENGINE=$DB_ENGINE CHARACTER SET $DB_CHARSET"
}
# parameters
# $1 - the table name
# $2 - the set expression
# $3 - the condition expression
mysql_update_value () {
mysql_exec "UPDATE \`nl2_$1\` SET $2 WHERE $3"
}
mysql_alter_column "mc_servers" "show_ip" "tinyint(1) NOT NULL DEFAULT '1'"
mysql_alter_column "users" "avatar_updated" "int(11) DEFAULT NULL"
mysql_create_table "online_guests" "\`id\` int(11) NOT NULL AUTO_INCREMENT, \`ip\` varchar(45) NOT NULL, \`last_seen\` int(11) NOT NULL, PRIMARY KEY (\`id\`)"
mysql_update_value "settings" "\`value\` = 'false'" "\`name\` = 'recaptcha_login'"
mysql_update_value "settings" "\`value\` = '2.0.0-pr7'" "\`name\` = 'nameless_version'"
mysql_update_value "settings" "\`value\` = 'false'" "\`name\` = 'version_update'"
echo "WARNING: Your recaptcha-on-login setting may have been turned off! Please check your StaffCP to ensure your recaptcha settings are correct."
echo "Update successful!"
@tadhgboyle
Copy link

This is super great. Will be helpful for lots of people

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment