diff --git a/ct/watchstate.sh b/ct/watchstate.sh new file mode 100644 index 000000000..0238436f0 --- /dev/null +++ b/ct/watchstate.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +_cs_boot="${COMMUNITY_SCRIPTS_CORE_DIR:-$(dirname "${BASH_SOURCE[0]}")/../../core}/core/build.func" +source "$_cs_boot" 2>/dev/null || source <(curl -fsSL "${COMMUNITY_SCRIPTS_CORE_URL:-https://raw.githubusercontent.com/community-scripts/core/main}/core/build.func") +# Copyright (c) 2021-2026 community-scripts ORG +# Author: MickLesk (CanbiZ) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/arabcoders/watchstate + +APP="WatchState" +var_tags="${var_tags:-media;plex;jellyfin;emby}" +var_cpu="${var_cpu:-2}" +var_ram="${var_ram:-2048}" +var_disk="${var_disk:-6}" +var_os="${var_os:-debian}" +var_version="${var_version:-13}" +var_arm64="${var_arm64:-yes}" +var_unprivileged="${var_unprivileged:-1}" + +header_info "$APP" +variables +color +catch_errors + +function update_script() { + header_info + check_container_storage + check_container_resources + + if [[ ! -d /opt/watchstate ]]; then + msg_error "No ${APP} Installation Found!" + exit + fi + + if check_for_gh_release "watchstate" "arabcoders/watchstate" "" "" "v"; then + msg_info "Stopping WatchState" + systemctl stop watchstate-worker php8.5-fpm + msg_ok "Stopped WatchState" + + create_backup /opt/watchstate/.env + setup_composer + NODE_VERSION="24" NODE_MODULE="bun" setup_nodejs + CLEAN_INSTALL=1 fetch_and_deploy_gh_release "watchstate" "arabcoders/watchstate" "tarball" "latest" "/opt/watchstate" "" "v" + restore_backup + + msg_info "Building WatchState" + cd /opt/watchstate + sed -i "s/'version' => 'dev-master'/'version' => 'v$(cat ~/.watchstate)'/" config/config.php + $STD composer install --no-dev --optimize-autoloader --no-interaction + cd /opt/watchstate/frontend + $STD bun install --frozen-lockfile --production + NODE_ENV=production $STD bun run generate + mv /opt/watchstate/frontend/exported /opt/watchstate/public/exported + rm -rf /opt/watchstate/frontend/node_modules /opt/watchstate/frontend/.nuxt + msg_ok "Built WatchState" + + msg_info "Migrating WatchState Database" + $STD php /opt/watchstate/bin/console db:migrate --execute + $STD php /opt/watchstate/bin/console db:index + chown -R www-data:www-data /opt/watchstate_data + msg_ok "Migrated WatchState Database" + + msg_info "Starting WatchState" + systemctl start php8.5-fpm watchstate-worker + msg_ok "Started WatchState" + msg_ok "Updated successfully!" + fi + exit +} + +start +build_container +description + +msg_ok "Completed Successfully!\n" +echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" +echo -e "${INFO}${YW}Access it using the following URL:${CL}" +echo -e "${GATEWAY}${BGN}http://${IP}:8080${CL}" diff --git a/install/watchstate-install.sh b/install/watchstate-install.sh new file mode 100644 index 000000000..40cd6785f --- /dev/null +++ b/install/watchstate-install.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021-2026 community-scripts ORG +# Author: MickLesk (CanbiZ) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/arabcoders/watchstate + +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +msg_info "Installing Dependencies" +$STD apt install -y \ + nginx \ + redis-server \ + ripgrep \ + sqlite3 +msg_ok "Installed Dependencies" + +PHP_VERSION="8.5" PHP_FPM="YES" setup_php +setup_composer +setup_ffmpeg +NODE_VERSION="24" NODE_MODULE="bun" setup_nodejs +fetch_and_deploy_gh_release "watchstate" "arabcoders/watchstate" "tarball" "latest" "/opt/watchstate" "" "v" + +msg_info "Building WatchState" +cd /opt/watchstate +sed -i "s/'version' => 'dev-master'/'version' => 'v$(cat ~/.watchstate)'/" config/config.php +$STD composer install --no-dev --optimize-autoloader --no-interaction +cd /opt/watchstate/frontend +$STD bun install --frozen-lockfile --production +NODE_ENV=production $STD bun run generate +mv /opt/watchstate/frontend/exported /opt/watchstate/public/exported +rm -rf /opt/watchstate/frontend/node_modules /opt/watchstate/frontend/.nuxt +msg_ok "Built WatchState" + +msg_info "Configuring WatchState" +# loaded first by CLI, worker and php-fpm alike; the default data dir is /opt/watchstate/var, which every update wipes +cat </opt/watchstate/.env +WS_DATA_PATH=/opt/watchstate_data +EOF +$STD php /opt/watchstate/bin/console db:migrate --execute +$STD php /opt/watchstate/bin/console system:apikey +chown -R www-data:www-data /opt/watchstate_data +msg_ok "Configured WatchState" + +msg_info "Configuring Nginx" +PHP_SOCK=$(get_php_fpm_socket) +cat </etc/nginx/sites-available/watchstate +server { + listen 8080; + server_name _; + root /opt/watchstate/public; + index index.php; + client_max_body_size 100M; + + location / { + try_files \$uri /index.php\$is_args\$args; + } + + location ~ \.php\$ { + fastcgi_pass unix:${PHP_SOCK}; + fastcgi_param SCRIPT_FILENAME \$realpath_root\$fastcgi_script_name; + include fastcgi_params; + fastcgi_read_timeout 600; + } +} +EOF +nginx_enable_site "watchstate" +msg_ok "Configured Nginx" + +msg_info "Creating Service" +cat </etc/systemd/system/watchstate-worker.service +[Unit] +Description=WatchState Worker +After=network.target redis-server.service + +[Service] +Type=simple +User=www-data +Group=www-data +WorkingDirectory=/opt/watchstate +ExecStart=/usr/bin/php /opt/watchstate/bin/console system:worker -v +Restart=always +RestartSec=5 + +[Install] +WantedBy=multi-user.target +EOF +systemctl enable -q --now watchstate-worker +msg_ok "Created Service" + +motd_ssh +customize +cleanup_lxc