2020-05-04 00:02:26 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
2020-06-22 16:23:07 +00:00
|
|
|
install_dir=/usr/local/share/advisorycircular
|
|
|
|
config_dir=/etc/advisorycircular
|
|
|
|
run_dir=/var/lib/advisorycircular
|
2020-05-04 00:02:26 +00:00
|
|
|
user=advisorycircular
|
|
|
|
|
2020-09-13 00:35:00 +00:00
|
|
|
if test `whoami` != root; then echo you must run this as root ; exit 1 ; fi
|
|
|
|
|
2020-09-13 00:59:05 +00:00
|
|
|
site="$1"
|
|
|
|
|
|
|
|
if test -z "$site"
|
|
|
|
then
|
|
|
|
echo usage: $0 sitename
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-05-04 03:10:54 +00:00
|
|
|
# Create install, config, and run directories if they doesn't exist.
|
2020-06-22 16:23:07 +00:00
|
|
|
echo Creating directories
|
|
|
|
mkdir -p "$install_dir"
|
|
|
|
mkdir -p "$config_dir"
|
|
|
|
mkdir -p "$run_dir"
|
2020-05-04 00:02:26 +00:00
|
|
|
|
|
|
|
# Create advisory-circular user if it doesn't exist.
|
2020-05-11 23:51:27 +00:00
|
|
|
if ! id -u ${user} >/dev/null 2>&1
|
2020-05-04 00:02:26 +00:00
|
|
|
then
|
2020-06-22 16:23:07 +00:00
|
|
|
echo Creating ${user} user
|
|
|
|
adduser --system --home ${install_dir} --no-create-home --quiet ${user}
|
2020-05-04 00:02:26 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Compile.
|
2020-06-22 16:23:07 +00:00
|
|
|
echo Compiling
|
2020-05-04 00:02:26 +00:00
|
|
|
npm install
|
|
|
|
npx shadow-cljs compile script
|
|
|
|
|
|
|
|
# Install
|
2020-06-22 16:23:07 +00:00
|
|
|
echo Copying files
|
|
|
|
install intervalexec.py "$install_dir"/intervalexec
|
|
|
|
install advisorycircular.sh "$install_dir"/advisorycircular
|
|
|
|
cp -r node_modules "$install_dir"
|
|
|
|
cp -r .shadow-cljs "$install_dir"
|
|
|
|
mkdir -p "$install_dir"/out
|
|
|
|
cp out/advisorycircular.js "$install_dir"/out
|
|
|
|
|
|
|
|
cp config-skel.yaml "$config_dir"
|
|
|
|
cp secrets-skel.yaml "$config_dir"
|
|
|
|
|
2020-09-13 00:59:05 +00:00
|
|
|
cp config.yaml "$config_dir"/"$site"-config.yaml
|
|
|
|
cp secrets.yaml "$config_dir"/"$site"-secrets.yaml
|
|
|
|
|
2020-06-22 16:23:07 +00:00
|
|
|
cp advisorycircular@.service /lib/systemd/system
|
2020-09-13 00:59:05 +00:00
|
|
|
cp advisorycircular@.service /lib/systemd/system/advisorycircular@"$site".service
|
2020-06-22 16:23:07 +00:00
|
|
|
|
|
|
|
# Download aircraft info DB.
|
|
|
|
echo Downloading aircraft info database
|
|
|
|
mkdir -p "$install_dir"/aircraft-info
|
|
|
|
curl 'https://www.mictronics.de/aircraft-database/indexedDB.php' > "$install_dir"/aircraft-info/db.zip
|
|
|
|
(cd "$install_dir"/aircraft-info && unzip -o db.zip)
|
|
|
|
# Convert JSON to sqlite DB.
|
|
|
|
node "$install_dir"/out/advisorycircular.js --aircraft-info-db /tmp/aircraft-info-$$.sqb --create-aircraft-info-db-from-json "$install_dir"/aircraft-info/aircrafts.json && mv /tmp/aircraft-info-$$.sqb "$install_dir"/aircraft-info/aircraft-info.sqb
|
|
|
|
|
|
|
|
chown -R "$user" "$install_dir"
|
|
|
|
chown -R "$user" "$config_dir"
|
|
|
|
chown -R "$user" "$run_dir"
|
|
|
|
|
2020-09-13 00:59:05 +00:00
|
|
|
chmod go-r "$config_dir"/secrets*.yaml
|
2020-06-22 16:23:07 +00:00
|
|
|
chmod go-w "$run_dir"
|
2020-09-13 00:59:05 +00:00
|
|
|
|
|
|
|
echo "Installation complete."
|
|
|
|
echo "You probably want to execute the following:"
|
|
|
|
echo "sudo systemctl enable advisorycircular@${site}.service"
|
|
|
|
echo "sudo systemctl start advisorycircular@${site}.service"
|