From f0d31d91d02205603e49bbfb09dd50da640ad5f3 Mon Sep 17 00:00:00 2001 From: Funey Date: Wed, 6 Jan 2021 15:16:36 +0000 Subject: [PATCH] add linux installer script - autogenerates to work with server --- index.js | 21 +++++++++ install.bash | 108 +++++++++++++++++++++++++++++++++++++++++++ static/install-linux | 108 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 237 insertions(+) create mode 100755 install.bash create mode 100644 static/install-linux diff --git a/index.js b/index.js index 060a876..a1fe064 100644 --- a/index.js +++ b/index.js @@ -44,6 +44,12 @@ const Cape_DefaultFile = path.join(__dirname, 'defaults', 'default_cape.png') const Java_JSON = path.join(__dirname, "java.json"); +// This is where the base Linux install script is stored. This must +// be a Bash file. + +const LinuxInstall_Bash = path.join(__dirname, "install.bash"); +const GeneratedInstall_Location = path.join(__dirname, "static", "install-linux") + // ACTUAL CODE BEYOND THIS POINT \\ // Initialise variables @@ -120,6 +126,21 @@ if (!fs.existsSync(Resources_XML_Location)) { } } +// Initialise install script. +if (fs.existsSync(LinuxInstall_Bash)) { + console.log('[INFO] Generating Linux install script...') + let file = fs.readFileSync(LinuxInstall_Bash, {encoding: 'utf8'}); + let sip = downloadFileSync('ifconfig.co/ip').toString().replace(/(\r\n|\n|\r)/gm, "");; + let new_file = file.replace('%%IP%%', sip) + try { + // try to save + fs.writeFileSync(GeneratedInstall_Location, new_file); + console.log('[INFO] Linux installer generated successfully!') + } catch { + console.log('[ERR] Failed to create linux installer.'); + process.exit(1); + } +} // Initialise functions. // add_to_java_poll diff --git a/install.bash b/install.bash new file mode 100755 index 0000000..2bca2c9 --- /dev/null +++ b/install.bash @@ -0,0 +1,108 @@ +#!/bin/bash + +# Script to initialise/de-initialise hosts file for +# ActionMC legacy skin servers. + +# Virtue, 2020 + +# Script-wide configuration + +# Actual code beyond this point. + + +# Initialise functions. +print_info () { + printf "\nThis script adds a line to your hosts file which\n" + printf "allows any legacy Minecraft client to\n" + printf "communicate with our custom skin servers.\n\n" + printf "This change intercepts connections to the website\n" + printf "s3.amazonaws.com and redirects them to our own\n" + printf "server.\n\n" + printf "If you use your machine for anything other than\n" + printf "playing Minecraft, it is best to only turn on\n" + printf "this modification when playing legacy Minecraft\n" + printf "or Action MC. A lot of the internet relies on\n" + printf "Amazon's S3 services, and we cannot provide all of\n" + printf "their services.\n\n" + printf "You will need superuser privileges in order to run\n" + printf "this script, so ensure that you are running this\n" + printf "script as a superuser.\n" +} + +print_end () { + printf "\nThe script is finished its task. Please check that\n" + printf "the server IP resolves properly by starting a web\n" + printf "browser and navigating to http://s3.amazonaws.com/statistics.\n\n" + printf "If this works, you are good to go! Launch Minecraft\n" + printf "and see everyone's skins!\n" +} + +init_skins () { + printf "\n[+] Adding line to /etc/hosts for s3.amazonaws.com...\n" + printf "\n%%IP%% s3.amazonaws.com" >> /etc/hosts + printf "[+] Added line to /etc/hosts successfully.\n\n" +} + +remove_skins () { + printf "\n" + echo [-] Removing line from /etc/hosts for s3.amazonaws.com... + grep -v "s3.amazonaws.com" /etc/hosts > tmphosts + rm /etc/hosts + mv tmphosts /etc/hosts + echo [-] Removing temporary files... + printf "\n" + echo [-] Removed line from /etc/hosts successfully. + printf "\n" +} + +obtain_sudo () { + if [ "${UID}" -eq 0 ] + then + echo "Running as root." + else + echo "Not running as root. Run this script as root." + exit 1 + fi +} + +# Program title. +printf "ActionMC Skin Server Manager\n" +echo ---------------------------- + +# Print information. +print_info + +echo ---------------------------- +printf "\n" +#printf "Please grant this script access to modify the hosts file.\n" + +# Obtain sudo before proceeding. +obtain_sudo + +# If we are this far already, we have root/sudo. +printf "Privilege obtained.\n\n----------------------------\n" + +case `grep -R "s3.amazonaws.com" /etc/hosts >/dev/null; echo $?` in + 0) + # Found S3 in the hosts. + printf "\n" + echo [!] Found reference to Amazon S3 in hosts file. + remove_skins + ;; + 1) + # Not found + printf "\n" + echo [!] Found no reference to Amazon S3 in hosts file. + init_skins + ;; + *) + # Error. + printf "\n" + echo Exception thrown trying to find S3 in the hosts file. + ;; +esac + +echo ----------------------------- +print_end + +# EOF diff --git a/static/install-linux b/static/install-linux new file mode 100644 index 0000000..549d680 --- /dev/null +++ b/static/install-linux @@ -0,0 +1,108 @@ +#!/bin/bash + +# Script to initialise/de-initialise hosts file for +# ActionMC legacy skin servers. + +# Virtue, 2020 + +# Script-wide configuration + +# Actual code beyond this point. + + +# Initialise functions. +print_info () { + printf "\nThis script adds a line to your hosts file which\n" + printf "allows any legacy Minecraft client to\n" + printf "communicate with our custom skin servers.\n\n" + printf "This change intercepts connections to the website\n" + printf "s3.amazonaws.com and redirects them to our own\n" + printf "server.\n\n" + printf "If you use your machine for anything other than\n" + printf "playing Minecraft, it is best to only turn on\n" + printf "this modification when playing legacy Minecraft\n" + printf "or Action MC. A lot of the internet relies on\n" + printf "Amazon's S3 services, and we cannot provide all of\n" + printf "their services.\n\n" + printf "You will need superuser privileges in order to run\n" + printf "this script, so ensure that you are running this\n" + printf "script as a superuser.\n" +} + +print_end () { + printf "\nThe script is finished its task. Please check that\n" + printf "the server IP resolves properly by starting a web\n" + printf "browser and navigating to http://s3.amazonaws.com/statistics.\n\n" + printf "If this works, you are good to go! Launch Minecraft\n" + printf "and see everyone's skins!\n" +} + +init_skins () { + printf "\n[+] Adding line to /etc/hosts for s3.amazonaws.com...\n" + printf "\n81.151.215.246 s3.amazonaws.com" >> /etc/hosts + printf "[+] Added line to /etc/hosts successfully.\n\n" +} + +remove_skins () { + printf "\n" + echo [-] Removing line from /etc/hosts for s3.amazonaws.com... + grep -v "s3.amazonaws.com" /etc/hosts > tmphosts + rm /etc/hosts + mv tmphosts /etc/hosts + echo [-] Removing temporary files... + printf "\n" + echo [-] Removed line from /etc/hosts successfully. + printf "\n" +} + +obtain_sudo () { + if [ "${UID}" -eq 0 ] + then + echo "Running as root." + else + echo "Not running as root. Run this script as root." + exit 1 + fi +} + +# Program title. +printf "ActionMC Skin Server Manager\n" +echo ---------------------------- + +# Print information. +print_info + +echo ---------------------------- +printf "\n" +#printf "Please grant this script access to modify the hosts file.\n" + +# Obtain sudo before proceeding. +obtain_sudo + +# If we are this far already, we have root/sudo. +printf "Privilege obtained.\n\n----------------------------\n" + +case `grep -R "s3.amazonaws.com" /etc/hosts >/dev/null; echo $?` in + 0) + # Found S3 in the hosts. + printf "\n" + echo [!] Found reference to Amazon S3 in hosts file. + remove_skins + ;; + 1) + # Not found + printf "\n" + echo [!] Found no reference to Amazon S3 in hosts file. + init_skins + ;; + *) + # Error. + printf "\n" + echo Exception thrown trying to find S3 in the hosts file. + ;; +esac + +echo ----------------------------- +print_end + +# EOF