From ba35f4c7b154e374bf087f9e42ad02a9cdcde005 Mon Sep 17 00:00:00 2001 From: Amy Parker Date: Sun, 30 Jul 2023 21:24:38 -0700 Subject: [PATCH] working install script This patch adds the working version of the install script. Signed-off-by: Amy Parker --- Makefile | 1 + README.md | 34 ++++++--- install.sh | 110 +++++++++++++++++++++++++++ installer/autoinstall-deps-system.sh | 46 +++++++++++ installer/gen_config.py | 12 ++- installer/verify-deps-system.sh | 42 ++++++++++ js/gen_make_filenames.sh | 0 7 files changed, 232 insertions(+), 13 deletions(-) create mode 100755 install.sh create mode 100755 installer/autoinstall-deps-system.sh create mode 100755 installer/verify-deps-system.sh mode change 100644 => 100755 js/gen_make_filenames.sh diff --git a/Makefile b/Makefile index eb5d040..3d2456d 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ SASS_SRCS = $(shell find scss/ -name '*.scss') # TODO: automatically compile sass instead of manual all: + mkdir -p assets/css assets/js $(SASS) scss/custom.scss:assets/css/custom_bootstrap.css $(SASS_OPTIONS) $(MAKE) -C js diff --git a/README.md b/README.md index 2e4eaad..d8c2a2c 100644 --- a/README.md +++ b/README.md @@ -20,16 +20,30 @@ The main thing that differs SSVP from other status pages is that it's designed f ## Installation -> These installation instructions will be better developed in the future. For now, they are meant for advanced users only. - -A more streamlined way to install SSVP is currently in development. Until then, you can: -1. Install the libpq and python development headers. (If not using PostgreSQL, you can ignore these, and remove psycopg2 from requirements.txt or install requirements manually) -2. Install the npm and Python dependencies (in a venv). -3. Copy `srv/ssvp-config.json.example` to `srv/ssvp-config.json`, and configure it. -4. Run `make` to compile the Sass and Typescript. -5. Insert ghost entries into your database (for mysql, postgresql, sqlite3) for cached_stats. -6. Add a runner for `srv/interval.py` to run on intervals (ideally every 1-5 minutes) in your crontab. -7. Launch `python3 srv/app.py` (dev) or `srv/gunicorn.sh` (prod) in a persistent environment (such as tmux). +Clone the repostiory: + +```sh +git clone --depth=1 https://github.com/amyipdev/ssvp +``` + +Install a database software (mysql or postgres) +> If you can't, and just want to test out SSVP, use the `sqlite3` database type + +Run the installer: +```sh +cd ssvp +./install.sh +``` + +Set up a cron job by inserting the following line (edit with `crontab -e`): +```cronexp +*/5 * * * * /path/to/ssvp/venv/bin/python3 /path/to/ssvp/srv/interval.py +``` + +Open up a `tmux` session, source the venv (`source venv/bin/activate`), and run either: + +- Development server: `python3 srv/app.py` +- Production server: `srv/gunicorn.sh` ## Configuration diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..930d206 --- /dev/null +++ b/install.sh @@ -0,0 +1,110 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# +# ssvp: server statistics viewer project +# Copyright (C) 2023 Amy Parker +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA or visit the +# GNU Project at https://gnu.org/licenses. The GNU Affero General Public +# License version 3 is available at, for your convenience, +# https://www.gnu.org/licenses/agpl-3.0.en.html. + +set -e + +cd "$(dirname "$0")" + +if [ $(id -u) -ne 0 ]; then + which sudo > /dev/null + if [ $? -ne 0 ]; then + echo "Either run as root, or have sudo installed" + exit 1 + else + PREROOT="sudo" + fi +fi + +echo -e "SSVP Setup and Installer\n\nPlease ensure that you are logged in as the user you wish to install SSVP as.\n" + +echo -n "Autoinstall system dependencies? (Debian and Fedora derivatives only) y/[n] " +read AILDPDS +if [ "$AILDPDS" == "y" ]; then + bash -c "$PREROOT installer/autoinstall-deps-system.sh $USER" +else + echo -n "Verify system dependencies? y/[n] " + read VFYDPS + if [ "$VFYDPS" == "y" ]; then + bash installer/verify-deps-system.sh + fi +fi + +if [ ! -d "venv" ]; then + echo -n "Create virtual environment? (recommended) n/[y] " + read CRVENV + if [ "$CRVENV" != "n" ]; then + python3 -m venv venv + fi +fi + +if [ "$VIRTUAL_ENV" == "" ]; then + if [ -d "venv" ]; then + echo -n "Source detected venv? (recommended) n/[y] " + read SRVENV + if [ "$SRVENV" != "n" ]; then + source venv/bin/activate + fi + fi +fi + +echo -n "Install PyPI dependencies? n/[y] " +read INSPYPI +if [ "$INSPYPI" != "n" ]; then + pip3 install -r requirements.txt +fi + +echo -n "Install NPM dependencies? n/[y] " +read INSNPM +if [ "$INSNPM" != "n" ]; then + npm i +fi + +echo -n "Compile site dependencies? n/[y] " +read CMPSDP +if [ "$CMPSDP" != "n" ]; then + make +fi + +echo -n "Initialize database system for SSVP? (use defaults when generating configuration) y/[n] " +read INIDBS +if [ "$INIDBS" == "y" ]; then + bash installer/initialize-databases.sh + echo "For mysql and postgres: make sure to change the database password after finishing install/setup." +fi + +echo -n "Generate ssvp config file? n/[y] " +read GENCF +if [ "$GENCF" != "n" ]; then + python3 installer/gen_config.py +fi + +echo -n "Initialize the cached statistics table? n/[y] " +read INISCS +if [ "$INISCS" != "n" ]; then + python3 srv/initialized_cached_stats.py +fi + +echo "Installation finished. Remember to set up a cron job for srv/interval.py to run every 5 minutes (this will be automated in the future)" + +# next todo: cron (also implement systemd timers) +# next todo: get install directory (default: /opt/ssvp), `make install` +# next todo: systemd service for web server? \ No newline at end of file diff --git a/installer/autoinstall-deps-system.sh b/installer/autoinstall-deps-system.sh new file mode 100755 index 0000000..8b9c8be --- /dev/null +++ b/installer/autoinstall-deps-system.sh @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# +# ssvp: server statistics viewer project +# Copyright (C) 2023 Amy Parker +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA or visit the +# GNU Project at https://gnu.org/licenses. The GNU Affero General Public +# License version 3 is available at, for your convenience, +# https://www.gnu.org/licenses/agpl-3.0.en.html. + +# support existing rustup installs +su - $1 -c "which cargo" +if [ $? -ne 0 ]; then + CARGO_INSTALL="cargo" +fi + +su - $1 -c "which crontab" +if [ $? -ne 0 ]; then + CRONTAB_INSTALL_APT = "cron" + CRONTAB_INSTALL_DNF = "cronie" +fi + +# NOTE: This doesn't work on dual-platform systems (if both, say, apt and dnf are installed) +if [ -f "/usr/bin/apt" ]; then + apt update + apt install python3 python3-pip python3-dev python3-venv libpq-dev nodejs npm sass jq make gcc g++ $CARGO_INSTALL tmux $CRONTAB_INSTALL_APT +elif [ -f "/usr/bin/dnf" ]; then + dnf install python3 python3-pip python3-devel libpq libpq-devel nodejs nodejs-npm jq make gcc gcc-c++ $CARGO_INSTALL tmux $CRONTAB_INSTALL_DNF +elif [ -f "/usr/bin/yum" ]; then + yum install python3 python3-pip python3-devel libpq libpq-devel nodejs nodejs-npm jq make gcc gcc-c++ $CARGO_INSTALL tmux $CRONTAB_INSTALL_DNF +else + echo "Unsupported OS for system package autoinstall" + exit 1 +fi \ No newline at end of file diff --git a/installer/gen_config.py b/installer/gen_config.py index bc5778f..8755ab9 100644 --- a/installer/gen_config.py +++ b/installer/gen_config.py @@ -23,6 +23,7 @@ import random import json import string +import shutil config = {} @@ -47,12 +48,12 @@ else: config["ssl"] = None -if x := input("Server port number (leave blank to autodetect): ") != "": +if (x := input("Server port number (leave blank to autodetect): ")) != "": config["port"] = int(x) config["instance_name"] = input("Name of SSVP instance: ") -if x := input("Splash text (leave blank for no splash): ") != "": +if (x := input("Splash text (leave blank for no splash): ")) != "": config["splash"] = x config["servers"] = {} @@ -82,9 +83,14 @@ config["database"]["database"] = x if (x := input("Database name [ssvp]: ")) != "" else "ssvp" config["database"]["username"] = x if (x := input("Database username [ssvp]: ")) != "" else "ssvp" config["database"]["password"] = input("Database password: ") + config["database"]["port"] = int(input("Database port: ")) filename = "srv/ssvp-config." + "".join(random.choice(string.hexdigits) for _ in range(8)) + ".json" json.dump(config, open(filename, "w"), indent=4, separators=(',', ': ')) print(f"\nConfig succesfully printed to srv/{filename}.\n" f"When you're ready to use this config, run:\n" - f" cp srv/{filename} srv/ssvp-config.json") + f" cp srv/{filename} srv/ssvp-config.json\n\n" + f"Would you like to do so now? y/[n] ", end="") +if input() == "y": + shutil.copy2(filename, "srv/ssvp-config.json") + print("Copied file.") diff --git a/installer/verify-deps-system.sh b/installer/verify-deps-system.sh new file mode 100755 index 0000000..7b6fba9 --- /dev/null +++ b/installer/verify-deps-system.sh @@ -0,0 +1,42 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# +# ssvp: server statistics viewer project +# Copyright (C) 2023 Amy Parker +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA or visit the +# GNU Project at https://gnu.org/licenses. The GNU Affero General Public +# License version 3 is available at, for your convenience, +# https://www.gnu.org/licenses/agpl-3.0.en.html. + +# LIMITATION: We can't actually really check for libpq-dev(el). +# It could technically be installed *anywhere* with some tricks. +# Same goes for python3-dev(el). Let's just presume it's installed, +# setup.py will fail if things go wrong anyways... + +if [ ! -f "/usr/bin/pip3" ]; then + echo "No system pip3 detected" + exit 1 +fi + +declare -a deps=( "python3" "jq" "gcc" "g++" "cargo" "tmux" "npx" "npm" "crontab" ) + +for dep in "${deps[@]}" +do + which $dep + if [ $? -ne 0 ]; then + echo "Missing required dependency $dep" + exit 1 + fi +done \ No newline at end of file diff --git a/js/gen_make_filenames.sh b/js/gen_make_filenames.sh old mode 100644 new mode 100755