Skip to content

Commit

Permalink
working install script
Browse files Browse the repository at this point in the history
This patch adds the working version of the install script.

Signed-off-by: Amy Parker <[email protected]>
  • Loading branch information
amyipdev committed Jul 31, 2023
1 parent 8357f6e commit ba35f4c
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 13 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
110 changes: 110 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# ssvp: server statistics viewer project
# Copyright (C) 2023 Amy Parker <[email protected]>
#
# 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?
46 changes: 46 additions & 0 deletions installer/autoinstall-deps-system.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# ssvp: server statistics viewer project
# Copyright (C) 2023 Amy Parker <[email protected]>
#
# 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
12 changes: 9 additions & 3 deletions installer/gen_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import random
import json
import string
import shutil

config = {}

Expand All @@ -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"] = {}
Expand Down Expand Up @@ -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.")
42 changes: 42 additions & 0 deletions installer/verify-deps-system.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# ssvp: server statistics viewer project
# Copyright (C) 2023 Amy Parker <[email protected]>
#
# 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
Empty file modified js/gen_make_filenames.sh
100644 → 100755
Empty file.

0 comments on commit ba35f4c

Please sign in to comment.