81 lines
2.0 KiB
Bash
81 lines
2.0 KiB
Bash
#!/bin/bash
|
|
|
|
set -eu
|
|
|
|
# Check if apache class is set and activate apache modules that will be needed
|
|
grep -q '^apache' /etc/dsv/computed_classes || { echo "Please set the apache class"; exit 1; }
|
|
a2enmod rewrite proxy proxy_http proxy_wstunnel
|
|
|
|
# Check if mariadb class is set
|
|
grep -q '^mariadb' /etc/dsv/computed_classes || { echo "Please set the apache class"; exit 1; }
|
|
|
|
# Set up variables that will be needed
|
|
proj_name="proxmox-web-portal"
|
|
#proj_dir="$(cd "$(dirname "$0")" && pwd)"
|
|
proj_dir="$(pwd)"
|
|
service_file="/etc/systemd/system/${proj_name}.service"
|
|
log_dir="/var/log/${proj_name}"
|
|
log_rotate="/etc/logrotate.d/${proj_name}"
|
|
db_path="${proj_dir}/app.db"
|
|
schema_path="${proj_dir}/schema.sql"
|
|
|
|
# Set up log directory with permissions along with logrotate
|
|
mkdir -p "$log_dir"
|
|
chown www-data:www-data "$log_dir"
|
|
chmod 755 "$log_dir"
|
|
touch "$log_rotate"
|
|
cat <<EOL > "$log_rotate"
|
|
${log_dir}/*.log {
|
|
daily
|
|
missingok
|
|
rotate 14
|
|
compress
|
|
delaycompress
|
|
notifempty
|
|
create 0640 www-data www-data
|
|
sharedscripts
|
|
postrotate
|
|
systemctl restart ${proj_name} > /dev/null 2>&1 || true
|
|
endscript
|
|
}
|
|
EOL
|
|
|
|
# Installing dependencies from apt before setting up python venv
|
|
apt update -y
|
|
apt install -y python3-venv libmariadb-dev
|
|
|
|
# Set up the venv
|
|
cd "$proj_dir"
|
|
python3 -m venv env
|
|
source env/bin/activate
|
|
pip install .
|
|
|
|
cp config.ini.example config.ini
|
|
|
|
# Get the novnc repo
|
|
git submodule update --init --recursive
|
|
|
|
# Create systemd service
|
|
touch "$service_file"
|
|
cat <<EOF >"$service_file"
|
|
[Unit]
|
|
Description=Proxmox Web Portal
|
|
After=network.target
|
|
|
|
[Service]
|
|
Environment={proj_dir}/env/bin
|
|
WorkingDirectory=${proj_dir}
|
|
ExecStart={proj_dir}/env/bin/fastapi ${proj_dir}/server.js
|
|
Restart=always
|
|
RestartSec=10
|
|
User=www-data
|
|
Group=www-data
|
|
StandardOutput=append:${log_dir}/output.log
|
|
StandardError=append:${log_dir}/error.log
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOL
|
|
|
|
echo "Setup is finished, please configure config.ini, mariadb followed by importing schema.sql, apache and start with systemctl start proxmox-web-portal"
|