refactor: homarr (#9948)

This commit is contained in:
Tobias 2025-12-14 23:56:45 +01:00 committed by GitHub
parent dfcaa70647
commit 2524dd1af7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 57 additions and 169 deletions

View File

@ -1,21 +1,20 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)
# Copyright (c) 2021-2025 community-scripts ORG # Copyright (c) 2021-2025 community-scripts ORG
# Author: CrazyWolf13 # Author: MickLesk (CanbiZ) | Co-Author: CrazyWolf13
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE # License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://homarr.dev/ # Source: https://homarr.dev/
APP="homarr" APP="homarr"
var_tags="${var_tags:-arr;dashboard}" var_tags="${var_tags:-arr;dashboard}"
var_cpu="${var_cpu:-3}" var_cpu="${var_cpu:-2}"
var_ram="${var_ram:-6144}" var_ram="${var_ram:-1024}"
var_disk="${var_disk:-8}" var_disk="${var_disk:-8}"
var_os="${var_os:-debian}" var_os="${var_os:-debian}"
var_version="${var_version:-13}" var_version="${var_version:-13}"
var_unprivileged="${var_unprivileged:-1}" var_unprivileged="${var_unprivileged:-1}"
header_info "$APP" header_info "$APP"
variables variables
color color
catch_errors catch_errors
@ -28,69 +27,33 @@ function update_script() {
msg_error "No ${APP} Installation Found!" msg_error "No ${APP} Installation Found!"
exit exit
fi fi
if [[ -f /opt/homarr/database/db.sqlite ]]; then
msg_error "Old Homarr detected due to existing database file (/opt/homarr/database/db.sqlite)."
msg_error "Update not supported. Refer to:"
msg_error " - https://github.com/community-scripts/ProxmoxVE/discussions/1551"
msg_error " - https://homarr.dev/docs/getting-started/after-the-installation/#importing-a-zip-from-version-before-100"
exit
fi
if [[ ! -f /opt/run_homarr.sh ]]; then
msg_info "Detected outdated and missing service files"
msg_error "Warning - The port of homarr changed from 3000 to 7575"
$STD apt-get install -y nginx gettext openssl gpg
sed -i '/^NODE_ENV=/d' /opt/homarr/.env && echo "NODE_ENV='production'" >>/opt/homarr/.env
sed -i '/^DB_DIALECT=/d' /opt/homarr/.env && echo "DB_DIALECT='sqlite'" >>/opt/homarr/.env
cat <<'EOF' >/opt/run_homarr.sh
#!/bin/bash
set -a
source /opt/homarr/.env
set +a
export DB_DIALECT='sqlite'
export AUTH_SECRET=$(openssl rand -base64 32)
export CRON_JOB_API_KEY=$(openssl rand -base64 32)
node /opt/homarr_db/migrations/$DB_DIALECT/migrate.cjs /opt/homarr_db/migrations/$DB_DIALECT
for dir in $(find /opt/homarr_db/migrations/migrations -mindepth 1 -maxdepth 1 -type d); do
dirname=$(basename "$dir")
mkdir -p "/opt/homarr_db/migrations/$dirname"
cp -r "$dir"/* "/opt/homarr_db/migrations/$dirname/" 2>/dev/null || true
done
export HOSTNAME=$(ip route get 1.1.1.1 | grep -oP 'src \K[^ ]+')
envsubst '${HOSTNAME}' < /etc/nginx/templates/nginx.conf > /etc/nginx/nginx.conf
nginx -g 'daemon off;' &
redis-server /opt/homarr/packages/redis/redis.conf &
node apps/tasks/tasks.cjs &
node apps/websocket/wssServer.cjs &
node apps/nextjs/server.js & PID=$!
wait $PID
EOF
chmod +x /opt/run_homarr.sh
rm /etc/systemd/system/homarr.service
cat <<EOF >/etc/systemd/system/homarr.service
[Unit]
Description=Homarr Service
After=network.target
[Service]
Type=exec
WorkingDirectory=/opt/homarr
EnvironmentFile=-/opt/homarr/.env
ExecStart=/opt/run_homarr.sh
[Install]
WantedBy=multi-user.target
EOF
msg_ok "Updated Services"
systemctl daemon-reload
fi
if check_for_gh_release "homarr" "homarr-labs/homarr"; then if check_for_gh_release "homarr" "homarr-labs/homarr"; then
msg_info "Stopping Services (Patience)" msg_info "Stopping Services (Patience)"
systemctl stop homarr systemctl stop homarr
systemctl stop redis-server
msg_ok "Services Stopped" msg_ok "Services Stopped"
msg_info "Backup Data" if ! { grep -q '^REDIS_IS_EXTERNAL=' /opt/homarr/.env 2>/dev/null || grep -q '^REDIS_IS_EXTERNAL=' /opt/homarr.env 2>/dev/null; }; then
mkdir -p /opt/homarr-data-backup msg_info "Fixing old structure"
cp /opt/homarr/.env /opt/homarr-data-backup/.env # fix musl issues because homarr compiles on alpine not debian soure: https://github.com/alexander-akhmetov/python-telegram/issues/3
msg_ok "Backup Data" $STD apt install -y musl-dev
ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1
cp /opt/homarr/.env /opt/homarr.env
echo "REDIS_IS_EXTERNAL='true'" >> /opt/homarr.env
sed -i 's|^ExecStart=.*|ExecStart=/opt/homarr/run.sh|' /etc/systemd/system/homarr.service
sed -i 's|^EnvironmentFile=.*|EnvironmentFile=-/opt/homarr.env|' /etc/systemd/system/homarr.service
chown -R redis:redis /appdata/redis
chmod 744 /appdata/redis
mkdir -p /etc/systemd/system/redis-server.service.d/
cat <<EOF >/etc/systemd/system/redis-server.service.d/override.conf
[Service]
ReadWritePaths=-/appdata/redis -/var/lib/redis -/var/log/redis -/var/run/redis -/etc/redis
EOF
systemctl daemon-reload
rm /opt/run_homarr.sh
msg_ok "Fixed old structure"
fi
msg_info "Updating Nodejs" msg_info "Updating Nodejs"
$STD apt update $STD apt update
@ -98,69 +61,21 @@ EOF
msg_ok "Updated Nodejs" msg_ok "Updated Nodejs"
NODE_VERSION=$(curl -s https://raw.githubusercontent.com/homarr-labs/homarr/dev/package.json | jq -r '.engines.node | split(">=")[1] | split(".")[0]') NODE_VERSION=$(curl -s https://raw.githubusercontent.com/homarr-labs/homarr/dev/package.json | jq -r '.engines.node | split(">=")[1] | split(".")[0]')
NODE_MODULE="pnpm@$(curl -s https://raw.githubusercontent.com/homarr-labs/homarr/dev/package.json | jq -r '.packageManager | split("@")[1]')"
setup_nodejs setup_nodejs
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "homarr" "homarr-labs/homarr" "prebuild" "latest" "/opt/homarr" "build-amd64.tar.gz"
rm -rf /opt/homarr msg_info "Updating Homarr"
fetch_and_deploy_gh_release "homarr" "homarr-labs/homarr" cp /opt/homarr/redis.conf /etc/redis/redis.conf
msg_info "Updating and rebuilding ${APP} (Patience)"
rm /opt/run_homarr.sh
cat <<'EOF' >/opt/run_homarr.sh
#!/bin/bash
set -a
source /opt/homarr/.env
set +a
export DB_DIALECT='sqlite'
export AUTH_SECRET=$(openssl rand -base64 32)
export CRON_JOB_API_KEY=$(openssl rand -base64 32)
node /opt/homarr_db/migrations/$DB_DIALECT/migrate.cjs /opt/homarr_db/migrations/$DB_DIALECT
for dir in $(find /opt/homarr_db/migrations/migrations -mindepth 1 -maxdepth 1 -type d); do
dirname=$(basename "$dir")
mkdir -p "/opt/homarr_db/migrations/$dirname"
cp -r "$dir"/* "/opt/homarr_db/migrations/$dirname/" 2>/dev/null || true
done
export HOSTNAME=$(ip route get 1.1.1.1 | grep -oP 'src \K[^ ]+')
envsubst '${HOSTNAME}' < /etc/nginx/templates/nginx.conf > /etc/nginx/nginx.conf
nginx -g 'daemon off;' &
redis-server /opt/homarr/packages/redis/redis.conf &
node apps/tasks/tasks.cjs &
node apps/websocket/wssServer.cjs &
node apps/nextjs/server.js & PID=$!
wait $PID
EOF
chmod +x /opt/run_homarr.sh
mv /opt/homarr-data-backup/.env /opt/homarr/.env
cd /opt/homarr
$STD pnpm install --recursive --frozen-lockfile --shamefully-hoist
$STD pnpm build
cp /opt/homarr/apps/nextjs/next.config.ts .
cp /opt/homarr/apps/nextjs/package.json .
cp -r /opt/homarr/packages/db/migrations /opt/homarr_db/migrations
cp -r /opt/homarr/apps/nextjs/.next/standalone/* /opt/homarr
mkdir -p /appdata/redis
cp /opt/homarr/packages/redis/redis.conf /opt/homarr/redis.conf
rm /etc/nginx/nginx.conf rm /etc/nginx/nginx.conf
mkdir -p /etc/nginx/templates
cp /opt/homarr/nginx.conf /etc/nginx/templates/nginx.conf cp /opt/homarr/nginx.conf /etc/nginx/templates/nginx.conf
msg_ok "Updated Homarr"
mkdir -p /opt/homarr/apps/cli
cp /opt/homarr/packages/cli/cli.cjs /opt/homarr/apps/cli/cli.cjs
echo $'#!/bin/bash\ncd /opt/homarr/apps/cli && node ./cli.cjs "$@"' >/usr/bin/homarr
chmod +x /usr/bin/homarr
mkdir /opt/homarr/build
cp ./node_modules/better-sqlite3/build/Release/better_sqlite3.node ./build/better_sqlite3.node
msg_ok "Updated ${APP}"
msg_info "Starting Services" msg_info "Starting Services"
chmod +x /opt/homarr/run.sh
systemctl start homarr systemctl start homarr
systemctl start redis-server
msg_ok "Started Services" msg_ok "Started Services"
msg_ok "Updated successfully!" msg_ok "Updated successfully!"
read -p "${TAB3}It's recommended to reboot the LXC after an update, would you like to reboot the LXC now ? (y/n): " choice
if [[ "$choice" =~ ^[Yy]$ ]]; then
reboot
fi
fi fi
exit exit
} }

View File

@ -19,8 +19,8 @@
"type": "default", "type": "default",
"script": "ct/homarr.sh", "script": "ct/homarr.sh",
"resources": { "resources": {
"cpu": 3, "cpu": 2,
"ram": 6144, "ram": 1024,
"hdd": 8, "hdd": 8,
"os": "debian", "os": "debian",
"version": "13" "version": "13"

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Copyright (c) 2021-2025 community-scripts ORG # Copyright (c) 2021-2025 community-scripts ORG
# Author: MickLesk (Canbiz) # Author: MickLesk (CanbiZ) | Co-Author: CrazyWolf13
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE # License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://github.com/homarr-labs/homarr # Source: https://github.com/homarr-labs/homarr
@ -16,28 +16,24 @@ update_os
msg_info "Installing Dependencies" msg_info "Installing Dependencies"
$STD apt install -y \ $STD apt install -y \
redis-server \ redis-server \
ca-certificates \
make \
g++ \
build-essential \
nginx \ nginx \
gettext \ gettext \
jq \ openssl \
openssl musl-dev
msg_ok "Installed Dependencies" msg_ok "Installed Dependencies"
NODE_VERSION=$(curl -s https://raw.githubusercontent.com/homarr-labs/homarr/dev/package.json | jq -r '.engines.node | split(">=")[1] | split(".")[0]') NODE_VERSION=$(curl -s https://raw.githubusercontent.com/homarr-labs/homarr/dev/package.json | jq -r '.engines.node | split(">=")[1] | split(".")[0]')
NODE_MODULE="pnpm@$(curl -s https://raw.githubusercontent.com/homarr-labs/homarr/dev/package.json | jq -r '.packageManager | split("@")[1]')"
setup_nodejs setup_nodejs
fetch_and_deploy_gh_release "homarr" "homarr-labs/homarr" fetch_and_deploy_gh_release "homarr" "homarr-labs/homarr" "prebuild" "latest" "/opt/homarr" "build-amd64.tar.gz"
msg_info "Installing Homarr (Patience)" msg_info "Installing Homarr"
cd /opt # fix musl issues because homarr compiles on alpine not debian soure: https://github.com/alexander-akhmetov/python-telegram/issues/3
ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1
mkdir -p /opt/homarr_db mkdir -p /opt/homarr_db
touch /opt/homarr_db/db.sqlite touch /opt/homarr_db/db.sqlite
SECRET_ENCRYPTION_KEY="$(openssl rand -hex 32)" SECRET_ENCRYPTION_KEY="$(openssl rand -hex 32)"
cd /opt/homarr cd /opt/homarr
cat <<EOF >/opt/homarr/.env cat <<EOF >/opt/homarr.env
DB_DRIVER='better-sqlite3' DB_DRIVER='better-sqlite3'
DB_DIALECT='sqlite' DB_DIALECT='sqlite'
SECRET_ENCRYPTION_KEY='${SECRET_ENCRYPTION_KEY}' SECRET_ENCRYPTION_KEY='${SECRET_ENCRYPTION_KEY}'
@ -45,54 +41,28 @@ DB_URL='/opt/homarr_db/db.sqlite'
TURBO_TELEMETRY_DISABLED=1 TURBO_TELEMETRY_DISABLED=1
AUTH_PROVIDERS='credentials' AUTH_PROVIDERS='credentials'
NODE_ENV='production' NODE_ENV='production'
REDIS_IS_EXTERNAL='true'
EOF EOF
$STD pnpm install --recursive --frozen-lockfile --shamefully-hoist
$STD pnpm build
msg_ok "Installed Homarr" msg_ok "Installed Homarr"
msg_info "Copying build and config files" msg_info "Copying config files"
cp /opt/homarr/apps/nextjs/next.config.ts .
cp /opt/homarr/apps/nextjs/package.json .
cp -r /opt/homarr/packages/db/migrations /opt/homarr_db/migrations
cp -r /opt/homarr/apps/nextjs/.next/standalone/* /opt/homarr
mkdir -p /appdata/redis mkdir -p /appdata/redis
cp /opt/homarr/packages/redis/redis.conf /opt/homarr/redis.conf chown -R redis:redis /appdata/redis
mkdir -p /etc/nginx/templates chmod 744 /appdata/redis
cp /opt/homarr/redis.conf /etc/redis/redis.conf
rm /etc/nginx/nginx.conf rm /etc/nginx/nginx.conf
mkdir -p /etc/nginx/templates
cp /opt/homarr/nginx.conf /etc/nginx/templates/nginx.conf cp /opt/homarr/nginx.conf /etc/nginx/templates/nginx.conf
mkdir -p /opt/homarr/apps/cli
cp /opt/homarr/packages/cli/cli.cjs /opt/homarr/apps/cli/cli.cjs
echo $'#!/bin/bash\ncd /opt/homarr/apps/cli && node ./cli.cjs "$@"' >/usr/bin/homarr echo $'#!/bin/bash\ncd /opt/homarr/apps/cli && node ./cli.cjs "$@"' >/usr/bin/homarr
chmod +x /usr/bin/homarr chmod +x /usr/bin/homarr
mkdir /opt/homarr/build msg_ok "Copied config files"
cp ./node_modules/better-sqlite3/build/Release/better_sqlite3.node ./build/better_sqlite3.node
msg_ok "Finished copying"
msg_info "Creating Services" msg_info "Creating Services"
cat <<'EOF' >/opt/run_homarr.sh mkdir -p /etc/systemd/system/redis-server.service.d/
#!/bin/bash cat <<EOF >/etc/systemd/system/redis-server.service.d/override.conf
set -a [Service]
source /opt/homarr/.env ReadWritePaths=-/appdata/redis -/var/lib/redis -/var/log/redis -/var/run/redis -/etc/redis
set +a
export DB_DIALECT='sqlite'
export AUTH_SECRET=$(openssl rand -base64 32)
export CRON_JOB_API_KEY=$(openssl rand -base64 32)
node /opt/homarr_db/migrations/$DB_DIALECT/migrate.cjs /opt/homarr_db/migrations/$DB_DIALECT
for dir in $(find /opt/homarr_db/migrations/migrations -mindepth 1 -maxdepth 1 -type d); do
dirname=$(basename "$dir")
mkdir -p "/opt/homarr_db/migrations/$dirname"
cp -r "$dir"/* "/opt/homarr_db/migrations/$dirname/" 2>/dev/null || true
done
export HOSTNAME=$(ip route get 1.1.1.1 | grep -oP 'src \K[^ ]+')
envsubst '${HOSTNAME}' < /etc/nginx/templates/nginx.conf > /etc/nginx/nginx.conf
nginx -g 'daemon off;' &
redis-server /opt/homarr/packages/redis/redis.conf &
node apps/tasks/tasks.cjs &
node apps/websocket/wssServer.cjs &
node apps/nextjs/server.js & PID=$!
wait $PID
EOF EOF
chmod +x /opt/run_homarr.sh
cat <<EOF >/etc/systemd/system/homarr.service cat <<EOF >/etc/systemd/system/homarr.service
[Unit] [Unit]
Description=Homarr Service Description=Homarr Service
@ -101,14 +71,17 @@ After=network.target
[Service] [Service]
Type=exec Type=exec
WorkingDirectory=/opt/homarr WorkingDirectory=/opt/homarr
EnvironmentFile=-/opt/homarr/.env EnvironmentFile=-/opt/homarr.env
ExecStart=/opt/run_homarr.sh ExecStart=/opt/homarr/run.sh
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
EOF EOF
chmod +x /opt/homarr/run.sh
systemctl daemon-reload
systemctl enable -q --now redis-server && sleep 5
systemctl enable -q --now homarr systemctl enable -q --now homarr
msg_ok "Created Service" msg_ok "Created Services"
motd_ssh motd_ssh
customize customize