changedetection: tidy declarations and messages

This commit is contained in:
skkzsh committed 2026-11-13 00:15:59 +09:00
1 parent 429194ee23
commit 2d438a82f0
2 files changed
+26 -24

No files matched your search

+22 -22
View File
@@ -26,8 +26,7 @@ function update_script() {
check_container_storage
check_container_resources
local -r CDIO_UNIT="/etc/systemd/system/changedetection.service"
if [[ ! -f "$CDIO_UNIT" ]]; then
if [[ ! -f /etc/systemd/system/changedetection.service ]]; then
msg_error "No ${APP} Installation Found!"
exit
fi
@@ -40,19 +39,18 @@ function update_script() {
sed -i "s/^# *${l}.UTF-8 UTF-8/${l}.UTF-8 UTF-8/" /etc/locale.gen
done
$STD locale-gen
local -r CDIO_DIR="/opt/changedetection"
local -r CDIO_ENV="${CDIO_DIR}/.env"
readonly CDIO_DIR="/opt/changedetection"
readonly CDIO_ENV="${CDIO_DIR}/.env"
if ! grep -q "^LC_ALL=" "$CDIO_ENV" 2>/dev/null; then
echo "LC_ALL=en_US.UTF-8" >>"$CDIO_ENV"
fi
msg_ok "Regenerated Locales"
# sockpuppet runs as the non-root chrome user, so uv's Python must live outside /root (mode 700).
export UV_PYTHON_INSTALL_DIR=/opt/uv-python
PYTHON_VERSION="3.13" setup_uv
local -r CDIO_VENV="${CDIO_DIR}/.venv"
local -r CDIO_BIN="${CDIO_VENV}/bin/changedetection.io"
readonly CDIO_VENV="${CDIO_DIR}/.venv"
readonly CDIO_BIN="${CDIO_VENV}/bin/changedetection.io"
if [[ ! -d "$CDIO_VENV" || ! -x "$CDIO_BIN" ]]; then
msg_info "Migrating to uv/venv"
rm -rf "$CDIO_VENV"
@@ -67,9 +65,9 @@ function update_script() {
msg_ok "Updated ${APP}"
fi
if ! grep -qF "$CDIO_BIN" "$CDIO_UNIT"; then
if ! grep -qF "$CDIO_BIN" /etc/systemd/system/changedetection.service; then
msg_info "Updating systemd service"
sed -i "s|^ExecStart=.*|ExecStart=${CDIO_BIN} -d ${CDIO_DIR} -p 5000|" "$CDIO_UNIT"
sed -i "s|^ExecStart=.*|ExecStart=${CDIO_BIN} -d ${CDIO_DIR} -p 5000|" /etc/systemd/system/changedetection.service
$STD systemctl daemon-reload
msg_ok "Updated systemd service"
fi
@@ -78,19 +76,21 @@ function update_script() {
if [[ ! -f /etc/apt/sources.list.d/google-chrome.sources ]]; then
setup_deb822_repo "google-chrome" \
"https://dl.google.com/linux/linux_signing_key.pub" \
"https://dl.google.com/linux/chrome/deb/" "stable"
"https://dl.google.com/linux/chrome/deb/" \
"stable"
else
apt_update_safe
fi
$STD apt install -y google-chrome-stable
msg_ok "Updated Chrome"
msg_info "Installing Sockpuppet"
groupadd -f chrome 2>/dev/null || true
id -u chrome >/dev/null 2>&1 ||
useradd --system --create-home --shell /usr/sbin/nologin -g chrome chrome
local -r SOCKPUPPET_DIR="/opt/sockpuppet"
local -r SOCKPUPPET_VENV="${SOCKPUPPET_DIR}/.venv"
readonly SOCKPUPPET_DIR="/opt/sockpuppet"
readonly SOCKPUPPET_VENV="${SOCKPUPPET_DIR}/.venv"
if check_for_gh_branch "sockpuppet" "dgtlmoon/sockpuppetbrowser" "master"; then
systemctl stop sockpuppet 2>/dev/null || true
fetch_and_deploy_gh_branch "sockpuppet" "dgtlmoon/sockpuppetbrowser" "master"
@@ -98,9 +98,8 @@ function update_script() {
$STD uv pip install --python "$SOCKPUPPET_VENV/bin/python" -r "${SOCKPUPPET_DIR}/requirements.txt"
fi
local -r SOCKPUPPET_UNIT="/etc/systemd/system/sockpuppet.service"
if [[ ! -f "$SOCKPUPPET_UNIT" ]]; then
cat <<EOF >"$SOCKPUPPET_UNIT"
if [[ ! -f /etc/systemd/system/sockpuppet.service ]]; then
cat <<EOF >/etc/systemd/system/sockpuppet.service
[Unit]
Description=sockpuppetbrowser service
After=network.target
@@ -124,19 +123,20 @@ WantedBy=default.target
EOF
fi
systemctl enable -q sockpuppet
msg_ok "Installed Sockpuppet"
local -r BROWSERLESS_UNIT="/etc/systemd/system/browserless.service"
if [[ -f "$BROWSERLESS_UNIT" ]]; then
if [[ -f /etc/systemd/system/browserless.service ]]; then
systemctl disable --now browserless 2>/dev/null || true
fi
msg_info "Starting Sockpuppet"
if ! safe_service_restart sockpuppet ||
! curl -sS --retry 15 --retry-delay 2 --retry-connrefused --retry-max-time 30 --max-time 5 \
"http://127.0.0.1:8080/stats" | grep -qE '"chrome_version":[[:space:]]*"Google Chrome'; then
msg_error "Sockpuppet failed to start"
systemctl status sockpuppet --no-pager -l | head -20 || true
systemctl disable --now sockpuppet 2>/dev/null || true
if [[ -f "$BROWSERLESS_UNIT" ]]; then
if [[ -f /etc/systemd/system/browserless.service ]]; then
systemctl enable --now browserless 2>/dev/null || true
msg_warn "Restarted Browserless; changedetection was not switched"
fi
@@ -146,8 +146,8 @@ EOF
local -r STAMP="$(date +%Y%m%d-%H%M%S)"
if grep -q "browserless\.service" "$CDIO_UNIT"; then
sed -i."$STAMP" 's/browserless\.service/sockpuppet.service/g' "$CDIO_UNIT"
if grep -q "browserless\.service" /etc/systemd/system/changedetection.service; then
sed -i."$STAMP" 's/browserless\.service/sockpuppet.service/g' /etc/systemd/system/changedetection.service
$STD systemctl daemon-reload
fi
@@ -167,10 +167,10 @@ EOF
fi
msg_ok "Started Change Detection"
if [[ -f "$BROWSERLESS_UNIT" ]]; then
if [[ -f /etc/systemd/system/browserless.service ]]; then
msg_info "Removing Browserless"
systemctl disable --now browserless 2>/dev/null || true
rm -f "$BROWSERLESS_UNIT"
rm -f /etc/systemd/system/browserless.service
rm -rf /opt/browserless
rm -rf /root/.cache/ms-playwright
$STD systemctl daemon-reload
+4 -2
View File
@@ -50,7 +50,6 @@ done
$STD locale-gen
msg_ok "Generated Locales"
# sockpuppet runs as the non-root chrome user, so uv's Python must live outside /root (mode 700).
export UV_PYTHON_INSTALL_DIR=/opt/uv-python
PYTHON_VERSION="3.13" setup_uv
@@ -69,7 +68,8 @@ msg_ok "Installed Change Detection"
msg_info "Installing Chrome"
setup_deb822_repo "google-chrome" \
"https://dl.google.com/linux/linux_signing_key.pub" \
"https://dl.google.com/linux/chrome/deb/" "stable"
"https://dl.google.com/linux/chrome/deb/" \
"stable"
$STD apt install -y google-chrome-stable
msg_ok "Installed Chrome"
@@ -78,9 +78,11 @@ groupadd -f chrome 2>/dev/null || true
id -u chrome >/dev/null 2>&1 || useradd --system --create-home --shell /usr/sbin/nologin -g chrome chrome
msg_ok "Created Chrome User"
msg_info "Installing Sockpuppet"
fetch_and_deploy_gh_branch "sockpuppet" "dgtlmoon/sockpuppetbrowser" "master"
$STD uv venv --python 3.12 /opt/sockpuppet/.venv
$STD uv pip install --python /opt/sockpuppet/.venv/bin/python -r /opt/sockpuppet/requirements.txt
msg_ok "Installed Sockpuppet"
msg_info "Installing Font Packages"
$STD apt install -y \