Update babybuddy-install.sh

This commit is contained in:
CanbiZ 2025-05-06 15:01:55 +02:00
parent 73529c6ad8
commit 4c00d96617

View File

@ -1,10 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Copyright (c) 2021-2024 tteck # Copyright (c) 2021-2024 community-scripts ORG
# Author: tteck # Author: MickLesk (CanbiZ)
# Co-Author: MickLesk (Canbiz) # License: MIT | htt
# License: MIT
# https://github.com/tteck/Proxmox/raw/main/LICENSE
# Source: https://github.com/AnalogJ/scrutiny # Source: https://github.com/AnalogJ/scrutiny
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
@ -18,49 +16,34 @@ update_os
# Installiere benötigte Pakete # Installiere benötigte Pakete
msg_info "Installing Dependencies" msg_info "Installing Dependencies"
$STD apt-get install -y \ $STD apt-get install -y \
sudo \
curl \
uwsgi \ uwsgi \
uwsgi-plugin-python3 \ uwsgi-plugin-python3 \
libopenjp2-7-dev \ libopenjp2-7-dev \
libpq-dev \ libpq-dev \
git \
nginx \ nginx \
python3 \ python3-venv
python3-pip \
python3-venv \
pipx
msg_ok "Installed Dependencies" msg_ok "Installed Dependencies"
# Installiere Python3 und PipX
#msg_info "Installing Python3 & PipX"
#$STD apt-get install -y python3 python3-dev python3-dotenv python3-pip
#source /opt/babybuddy/.venv/bin/activate
#msg_ok "Installed Python3 & PipX"
# Variablen
INSTALL_DIR="/opt/babybuddy"
APP_DIR="$INSTALL_DIR"
DATA_DIR="$INSTALL_DIR/data"
DOMAIN="babybuddy.example.com" # Ändern, falls benötigt
SECRET_KEY=$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | cut -c1-32)
# Babybuddy Repository installieren
msg_info "Installing Babybuddy" msg_info "Installing Babybuddy"
cd /opt cd /opt
RELEASE=$(curl -s https://api.github.com/repos/babybuddy/babybuddy/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') RELEASE=$(curl -fsSL https://api.github.com/repos/babybuddy/babybuddy/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
wget -q "https://github.com/babybuddy/babybuddy/archive/refs/tags/v${RELEASE}.zip" wget -q "https://github.com/babybuddy/babybuddy/archive/refs/tags/v${RELEASE}.zip"
unzip -q v${RELEASE}.zip unzip -q v${RELEASE}.zip
mv babybuddy-${RELEASE} /opt/babybuddy mv babybuddy-${RELEASE} /opt/babybuddy
rm "v${RELEASE}.zip"
cd /opt/babybuddy cd /opt/babybuddy
source /opt/babybuddy/.venv/bin/activate python3 -m venv .venv
source .venv/bin/activate
pip install -U pip wheel
export PIPENV_VENV_IN_PROJECT=1 export PIPENV_VENV_IN_PROJECT=1
pipenv install pipenv install
pipenv shell pipenv shell
cp babybuddy/settings/production.example.py babybuddy/settings/production.py cp babybuddy/settings/production.example.py babybuddy/settings/production.py
touch /opt/babybuddy/data/db.sqlite3
chown -R www-data:www-data /opt/babybuddy/data
chmod 640 /opt/babybuddy/data/db.sqlite3
chmod 750 /opt/babybuddy/data
# Production-Settings konfigurieren
SECRET_KEY=$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | cut -c1-32) SECRET_KEY=$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | cut -c1-32)
ALLOWED_HOSTS=$(hostname -I | tr ' ' ',' | sed 's/,$//')",127.0.0.1,localhost" ALLOWED_HOSTS=$(hostname -I | tr ' ' ',' | sed 's/,$//')",127.0.0.1,localhost"
sed -i \ sed -i \
@ -68,27 +51,26 @@ sed -i \
-e "s/^ALLOWED_HOSTS = \[\"\"\]/ALLOWED_HOSTS = \[$(echo \"$ALLOWED_HOSTS\" | sed 's/,/\",\"/g')\]/" \ -e "s/^ALLOWED_HOSTS = \[\"\"\]/ALLOWED_HOSTS = \[$(echo \"$ALLOWED_HOSTS\" | sed 's/,/\",\"/g')\]/" \
babybuddy/settings/production.py babybuddy/settings/production.py
# Django Migrationen durchführen
export DJANGO_SETTINGS_MODULE=babybuddy.settings.production export DJANGO_SETTINGS_MODULE=babybuddy.settings.production
python manage.py migrate python manage.py migrate
# Berechtigungen setzen # Berechtigungen setzen
sudo chown -R www-data:www-data /opt/babybuddy/data chown -R www-data:www-data /opt/babybuddy/data
sudo chmod 640 /opt/babybuddy/data/db.sqlite3 chmod 640 /opt/babybuddy/data/db.sqlite3
sudo chmod 750 /opt/babybuddy/data chmod 750 /opt/babybuddy/data
msg_ok "Installed BabyBuddy WebApp" msg_ok "Installed BabyBuddy WebApp"
# Django Admin Setup # Django Admin Setup
DJANGO_ADMIN_USER=admin DJANGO_ADMIN_USER=admin
DJANGO_ADMIN_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13) DJANGO_ADMIN_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13)
source /opt/babybuddy/bin/activate python manage.py shell <<EOF
$STD python3 /opt/babybuddy/manage.py shell << EOF
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
UserModel = get_user_model() User = get_user_model()
user = UserModel.objects.create_user('$DJANGO_ADMIN_USER', password='$DJANGO_ADMIN_PASS') if not User.objects.filter(username='$DJANGO_ADMIN_USER').exists():
user.is_superuser = True u = User.objects.create_user('$DJANGO_ADMIN_USER', password='$DJANGO_ADMIN_PASS')
user.is_staff = True u.is_superuser = True
user.save() u.is_staff = True
u.save()
EOF EOF
{ {
@ -105,9 +87,9 @@ sudo bash -c "cat > /etc/uwsgi/apps-available/babybuddy.ini" <<EOF
[uwsgi] [uwsgi]
plugins = python3 plugins = python3
project = babybuddy project = babybuddy
base_dir = $INSTALL_DIR base_dir = /opt/babybuddy
chdir = %(base_dir)/public chdir = %(base_dir)
virtualenv = %(chdir)/.venv virtualenv = %(base_dir)/.venv
module = %(project).wsgi:application module = %(project).wsgi:application
env = DJANGO_SETTINGS_MODULE=%(project).settings.production env = DJANGO_SETTINGS_MODULE=%(project).settings.production
master = True master = True
@ -119,14 +101,14 @@ sudo service uwsgi restart
# NGINX konfigurieren # NGINX konfigurieren
msg_info "Configuring NGINX" msg_info "Configuring NGINX"
sudo bash -c "cat > /etc/nginx/sites-available/babybuddy" <<EOF cat <<EOF >/etc/nginx/sites-available/babybuddy
upstream babybuddy { upstream babybuddy {
server unix:///var/run/uwsgi/app/babybuddy/socket; server unix:///var/run/uwsgi/app/babybuddy/socket;
} }
server { server {
listen 80; listen 80;
server_name $DOMAIN; server_name _;
location / { location / {
uwsgi_pass babybuddy; uwsgi_pass babybuddy;
@ -134,16 +116,13 @@ server {
} }
location /media { location /media {
alias $DATA_DIR/media; alias /opt/babybuddy/media;
} }
} }
EOF EOF
sudo ln -sf /etc/nginx/sites-available/babybuddy /etc/nginx/sites-enabled/babybuddy ln -sf /etc/nginx/sites-available/babybuddy /etc/nginx/sites-enabled/babybuddy
sudo service nginx restart service nginx restart
# Abschlussnachricht
echo "Deployment abgeschlossen! Besuche http://$DOMAIN"
# Bereinigung # Bereinigung
msg_info "Cleaning up" msg_info "Cleaning up"