mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2025-12-15 19:53:31 +01:00
refactor: homarr-install
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright (c) 2021-2025 community-scripts ORG
|
||||
# Author: MickLesk (Canbiz)
|
||||
# Author: CrazyWolf13
|
||||
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
|
||||
# Source: https://github.com/homarr-labs/homarr
|
||||
|
||||
@ -16,28 +16,23 @@ update_os
|
||||
msg_info "Installing Dependencies"
|
||||
$STD apt install -y \
|
||||
redis-server \
|
||||
ca-certificates \
|
||||
make \
|
||||
g++ \
|
||||
build-essential \
|
||||
nginx \
|
||||
gettext \
|
||||
jq \
|
||||
openssl
|
||||
openssl \
|
||||
musl-dev
|
||||
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_MODULE="pnpm@$(curl -s https://raw.githubusercontent.com/homarr-labs/homarr/dev/package.json | jq -r '.packageManager | split("@")[1]')"
|
||||
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)"
|
||||
cd /opt
|
||||
msg_info "Installing Homarr"
|
||||
ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1
|
||||
mkdir -p /opt/homarr_db
|
||||
touch /opt/homarr_db/db.sqlite
|
||||
SECRET_ENCRYPTION_KEY="$(openssl rand -hex 32)"
|
||||
cd /opt/homarr
|
||||
cat <<EOF >/opt/homarr/.env
|
||||
cat <<EOF >/opt/homarr.env
|
||||
DB_DRIVER='better-sqlite3'
|
||||
DB_DIALECT='sqlite'
|
||||
SECRET_ENCRYPTION_KEY='${SECRET_ENCRYPTION_KEY}'
|
||||
@ -45,54 +40,28 @@ DB_URL='/opt/homarr_db/db.sqlite'
|
||||
TURBO_TELEMETRY_DISABLED=1
|
||||
AUTH_PROVIDERS='credentials'
|
||||
NODE_ENV='production'
|
||||
REDIS_IS_EXTERNAL='true'
|
||||
EOF
|
||||
$STD pnpm install --recursive --frozen-lockfile --shamefully-hoist
|
||||
$STD pnpm build
|
||||
msg_ok "Installed Homarr"
|
||||
|
||||
msg_info "Copying build and 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
|
||||
msg_info "Copying config files"
|
||||
mkdir -p /appdata/redis
|
||||
cp /opt/homarr/packages/redis/redis.conf /opt/homarr/redis.conf
|
||||
mkdir -p /etc/nginx/templates
|
||||
chown -R redis:redis /appdata/redis
|
||||
chmod 755 /appdata/redis
|
||||
cp /opt/homarr/redis.conf /etc/redis/redis.conf
|
||||
rm /etc/nginx/nginx.conf
|
||||
mkdir -p /etc/nginx/templates
|
||||
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
|
||||
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 "Finished copying"
|
||||
msg_ok "Copied config files"
|
||||
|
||||
msg_info "Creating Services"
|
||||
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
|
||||
mkdir -p /etc/systemd/system/redis-server.service.d/
|
||||
cat > /etc/systemd/system/redis-server.service.d/override.conf << 'EOF'
|
||||
[Service]
|
||||
ReadWritePaths=-/appdata/redis -/var/lib/redis -/var/log/redis -/var/run/redis -/etc/redis
|
||||
EOF
|
||||
chmod +x /opt/run_homarr.sh
|
||||
cat <<EOF >/etc/systemd/system/homarr.service
|
||||
[Unit]
|
||||
Description=Homarr Service
|
||||
@ -101,14 +70,17 @@ After=network.target
|
||||
[Service]
|
||||
Type=exec
|
||||
WorkingDirectory=/opt/homarr
|
||||
EnvironmentFile=-/opt/homarr/.env
|
||||
ExecStart=/opt/run_homarr.sh
|
||||
EnvironmentFile=-/opt/homarr.env
|
||||
ExecStart=/opt/homarr/run.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
chmod +x /opt/homarr/run.sh
|
||||
systemctl daemon-reload
|
||||
systemctl enable -q --now redis-server && sleep 5
|
||||
systemctl enable -q --now homarr
|
||||
msg_ok "Created Service"
|
||||
msg_ok "Created Services"
|
||||
|
||||
motd_ssh
|
||||
customize
|
||||
|
||||
Reference in New Issue
Block a user