Update actualbudget.sh

This commit is contained in:
CanbiZ 2025-05-05 12:06:27 +02:00
parent 75c10ca4ba
commit 4c8b36876a

View File

@ -30,29 +30,109 @@ function update_script() {
fi fi
RELEASE=$(curl -fsSL https://api.github.com/repos/actualbudget/actual/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') RELEASE=$(curl -fsSL https://api.github.com/repos/actualbudget/actual/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
if [[ ! -f /opt/actualbudget_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/actualbudget_version.txt)" ]]; then function update_script() {
msg_info "Stopping ${APP}" header_info
systemctl stop actualbudget check_container_storage
msg_ok "${APP} Stopped" check_container_resources
msg_info "Updating ${APP} to ${RELEASE}" if [[ ! -d /opt/actualbudget ]]; then
NODE_VERSION="22" msg_error "No ${APP} Installation Found!"
install_node_and_modules exit
npm update -g @actual-app/sync-server
msg_ok "Updated ${APP} to ${RELEASE}"
systemctl daemon-reload
systemctl start actualbudget
msg_ok "Started ${APP}"
msg_info "Cleaning Up"
rm -rf /opt/actualbudget_bak
rm -rf "/tmp/v${RELEASE}.tar.gz"
msg_ok "Cleaned"
msg_ok "Updated Successfully"
else
msg_ok "No update required. ${APP} is already at ${RELEASE}"
fi fi
RELEASE=$(curl -fsSL https://api.github.com/repos/actualbudget/actual/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
if [[ -f /opt/actualbudget-data/config.json ]]; then
if [[ ! -f /opt/actualbudget_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/actualbudget_version.txt)" ]]; then
msg_info "Stopping ${APP}"
systemctl stop actualbudget
msg_ok "${APP} Stopped"
msg_info "Updating ${APP} to ${RELEASE}"
NODE_VERSION="22"
install_node_and_modules
$STD npm update -g @actual-app/sync-server
echo "${RELEASE}" >/opt/actualbudget_version.txt
msg_ok "Updated ${APP} to ${RELEASE}"
msg_info "Starting ${APP}"
systemctl start actualbudget
msg_ok "Restarted ${APP}"
else
msg_ok "No update required. ${APP} is already at ${RELEASE}"
msg_info "Ensuring latest npm version of @actual-app/sync-server"
$STD npm update -g @actual-app/sync-server
systemctl restart actualbudget
msg_ok "Restarted ${APP}"
fi
else
msg_info "Performing full migration to npm-based version (${RELEASE})"
systemctl stop actualbudget
rm -rf /opt/actualbudget
rm -rf /opt/actualbudget_bak
mkdir -p /opt/actualbudget
$STD npm install --location=global @actual-app/sync-server
mkdir -p /opt/actualbudget-data/{server-files,user-files}
chown -R root:root /opt/actualbudget-data
chmod -R 755 /opt/actualbudget-data
cat <<EOF >/opt/actualbudget-data/config.json
{
"port": 5006,
"hostname": "::",
"serverFiles": "/opt/actualbudget-data/server-files",
"userFiles": "/opt/actualbudget-data/user-files",
"trustedProxies": [
"10.0.0.0/8",
"172.16.0.0/12",
"192.168.0.0/16",
"127.0.0.1/32",
"::1/128",
"fc00::/7"
],
"https": {
"key": "/opt/actualbudget/selfhost.key",
"cert": "/opt/actualbudget/selfhost.crt"
}
}
EOF
if [[ ! -f /opt/actualbudget/selfhost.key ]]; then
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /opt/actualbudget/selfhost.key \
-out /opt/actualbudget/selfhost.crt \
-subj "/C=US/ST=California/L=San Francisco/O=My Organization/OU=My Unit/CN=localhost/emailAddress=myemail@example.com"
fi
cat <<EOF >/etc/systemd/system/actualbudget.service
[Unit]
Description=Actual Budget Service
After=network.target
[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/opt/actualbudget
Environment=ACTUAL_UPLOAD_FILE_SIZE_LIMIT_MB=20
Environment=ACTUAL_UPLOAD_SYNC_ENCRYPTED_FILE_SYNC_SIZE_LIMIT_MB=50
Environment=ACTUAL_UPLOAD_FILE_SYNC_SIZE_LIMIT_MB=20
ExecStart=/usr/local/bin/actual-server --config /opt/actualbudget-data/config.json
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
echo "${RELEASE}" >"$CURRENT_VERSION_FILE"
$STD systemctl daemon-reload
systemctl enable actualbudget
systemctl start actualbudget
msg_ok "Migrated and started ${APP} ${RELEASE}"
fi
msg_info "Cleaning Up"
msg_ok "Cleaned"
exit exit
} }