Files
ProxmoxVE/install/mediamanager-install.sh
T
CanbiZ (MickLesk) 54c8b2393e install: answer every prompt from the environment, survive a closed stdin (#18121)
* install: answer every prompt from the environment, survive a closed stdin

Every interactive prompt takes a var_<app>_<name> override and treats a
closed stdin like Enter (`|| true`), so an install keeps going after the
console that started it is gone. Values the script cannot do without end
with exit 64 and name the variable to set. Validation loops stop asking
when nobody can answer instead of spinning on an empty read.

* mongodb, paperless-gpt: accept yes as well as y
2026-10-24 17:55:50 +02:00

102 lines
2.9 KiB
Bash

#!/usr/bin/env bash
# Copyright (c) 2021-2026 community-scripts ORG
# Author: vhsdream
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://github.com/maxdorninger/MediaManager
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
color
verb_ip6
catch_errors
setting_up_container
network_check
update_os
admin_email="${var_mediamanager_admin_email:-}"
[[ -n "$admin_email" ]] || read -r -p "${TAB3}Enter the email address of your first admin user: " admin_email || true
[[ -n "$admin_email" ]] || { msg_error "No admin e-mail given; set var_mediamanager_admin_email or answer the prompt"; exit 64; }
if [[ "$admin_email" ]]; then
EMAIL="$admin_email"
fi
setup_yq
NODE_VERSION="24" setup_nodejs
PG_VERSION="17" setup_postgresql
PG_DB_NAME="mm_db" PG_DB_USER="mm_user" setup_postgresql_db
fetch_and_deploy_gh_release "MediaManager" "maxdorninger/MediaManager" "tarball" "latest" "/opt/mediamanager"
UV_PROJECT_DIR="/opt/mediamanager" setup_uv
msg_info "Configuring MediaManager"
MM_DIR="/opt/mm"
MEDIA_DIR="${MM_DIR}/media"
export CONFIG_DIR="${MM_DIR}/config"
export FRONTEND_FILES_DIR="${MM_DIR}/web/build"
export PUBLIC_VERSION=""
export PUBLIC_API_URL=""
export BASE_PATH="/web"
cd /opt/mediamanager/web
$STD npm install --no-fund --no-audit
$STD npm run build
mkdir -p {"$MM_DIR"/web,"$MEDIA_DIR","$CONFIG_DIR"}
cp -r build "$FRONTEND_FILES_DIR"
export BASE_PATH=""
export VIRTUAL_ENV="${MM_DIR}/venv"
cd /opt/mediamanager
cp -r {media_manager,alembic*} "$MM_DIR"
$STD /usr/local/bin/uv sync --locked --active -n -p cpython3.13 --managed-python
msg_ok "Configured MediaManager"
msg_info "Creating config and start script"
SECRET="$(openssl rand -hex 32)"
sed -e "s/localhost:8/$LOCAL_IP:8/g" \
-e "s|/data/|$MEDIA_DIR/|g" \
-e 's/"db"/"localhost"/' \
-e "s/user = \"MediaManager\"/user = \"mm_user\"/" \
-e "s/password = \"MediaManager\"/password = \"$PG_DB_PASS\"/" \
-e "s/dbname = \"MediaManager\"/dbname = \"mm_db\"/" \
-e "/^token_secret/s/=.*/= \"$SECRET\"/" \
-e "s/admin@example.com/$EMAIL/" \
-e '/^admin_emails/s/, .*/]/' \
/opt/mediamanager/config.example.toml >"$CONFIG_DIR"/config.toml
mkdir -p "$MEDIA_DIR"/{images,tv,movies,torrents}
cat <<EOF >"$MM_DIR"/start.sh
#!/usr/bin/env bash
export CONFIG_DIR="$CONFIG_DIR"
export FRONTEND_FILES_DIR="$FRONTEND_FILES_DIR"
export LOG_FILE="$CONFIG_DIR/media_manager.log"
export BASE_PATH=""
cd $MM_DIR
source ./venv/bin/activate
/usr/local/bin/uv run alembic upgrade head
/usr/local/bin/uv run fastapi run ./media_manager/main.py --port 8000
EOF
chmod +x "$MM_DIR"/start.sh
msg_ok "Created config and start script"
msg_info "Creating service"
cat <<EOF >/etc/systemd/system/mediamanager.service
[Unit]
Description=MediaManager Backend Service
After=network.target
[Service]
Type=simple
WorkingDirectory=${MM_DIR}
ExecStart=/usr/bin/bash start.sh
[Install]
WantedBy=multi-user.target
EOF
systemctl enable -q --now mediamanager
msg_ok "Created service"
motd_ssh
customize
cleanup_lxc