ProxmoxVE/install/homarr-install.sh

127 lines
3.7 KiB
Bash
Raw Normal View History

2023-08-16 14:56:17 +02:00
#!/usr/bin/env bash
2025-01-28 16:32:44 +01:00
# Copyright (c) 2021-2025 community-scripts ORG
# Author: MickLesk (Canbiz)
2025-01-28 16:50:30 +01:00
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://github.com/homarr-labs/homarr
2023-08-16 14:56:17 +02:00
source /dev/stdin <<< "$FUNCTIONS_FILE_PATH"
color
verb_ip6
catch_errors
setting_up_container
network_check
update_os
msg_info "Installing Dependencies"
$STD apt-get install -y \
sudo \
mc \
curl \
2025-01-28 16:32:44 +01:00
redis-server \
ca-certificates \
gpg \
make \
g++ \
build-essential \
nginx \
gettext \
openssl
2023-08-16 14:56:17 +02:00
msg_ok "Installed Dependencies"
msg_info "Setting up Node.js Repository"
2023-09-02 14:36:54 +02:00
mkdir -p /etc/apt/keyrings
2023-09-01 13:19:05 +02:00
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
2025-01-28 16:32:44 +01:00
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" >/etc/apt/sources.list.d/nodesource.list
2023-08-16 14:56:17 +02:00
msg_ok "Set up Node.js Repository"
2025-01-28 16:32:44 +01:00
msg_info "Installing Node.js/pnpm"
2023-09-01 13:19:05 +02:00
$STD apt-get update
2023-08-16 14:56:17 +02:00
$STD apt-get install -y nodejs
2025-01-28 18:24:06 +01:00
$STD npm install -g pnpm@latest
2025-01-28 16:32:44 +01:00
msg_ok "Installed Node.js/pnpm"
2023-08-16 14:56:17 +02:00
msg_info "Installing Homarr (Patience)"
2025-01-28 16:32:44 +01:00
cd /opt
RELEASE=$(curl -s https://api.github.com/repos/homarr-labs/homarr/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
wget -q "https://github.com/homarr-labs/homarr/archive/refs/tags/v${RELEASE}.zip"
unzip -q v${RELEASE}.zip
mv homarr-${RELEASE} /opt/homarr
2025-01-28 16:32:44 +01:00
mkdir -p /opt/homarr_db
touch /opt/homarr_db/db.sqlite
2025-01-28 16:59:27 +01:00
SECRET_ENCRYPTION_KEY="$(openssl rand -hex 32)"
cd /opt/homarr
2024-04-15 05:53:22 +02:00
cat <<EOF >/opt/homarr/.env
2025-01-28 16:32:44 +01:00
DB_DRIVER='better-sqlite3'
DB_DIALECT='sqlite'
2025-01-28 16:59:27 +01:00
SECRET_ENCRYPTION_KEY='${SECRET_ENCRYPTION_KEY}'
2025-01-28 16:32:44 +01:00
DB_URL='/opt/homarr_db/db.sqlite'
TURBO_TELEMETRY_DISABLED=1
AUTH_PROVIDERS='credentials'
NODE_ENV='production'
2024-04-15 05:53:22 +02:00
EOF
2025-01-28 16:50:30 +01:00
$STD pnpm install
2025-01-28 16:32:44 +01:00
$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
mkdir -p /appdata/redis
cp /opt/homarr/packages/redis/redis.conf /opt/homarr/redis.conf
mkdir -p /etc/nginx/templates
rm /etc/nginx/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
chmod +x /usr/bin/homarr
mkdir /opt/homarr/build
2025-01-28 16:32:44 +01:00
cp ./node_modules/better-sqlite3/build/Release/better_sqlite3.node ./build/better_sqlite3.node
echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt"
msg_ok "Finished copying"
2023-08-16 14:56:17 +02:00
msg_info "Creating Services"
cat <<'EOF' >/opt/run_homarr.sh
#!/bin/bash
export DB_DIALECT='sqlite'
export AUTH_SECRET=$(openssl rand -base64 32)
node /opt/homarr_db/migrations/$DB_DIALECT/migrate.cjs /opt/homarr_db/migrations/$DB_DIALECT
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
2023-08-16 14:56:17 +02:00
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
2023-08-16 14:56:17 +02:00
[Install]
WantedBy=multi-user.target
EOF
2025-01-28 16:32:44 +01:00
systemctl enable -q --now homarr
2023-08-16 14:56:17 +02:00
msg_ok "Created Service"
motd_ssh
customize
msg_info "Cleaning up"
2025-01-28 16:32:44 +01:00
rm -rf /opt/v${RELEASE}.zip
2024-05-02 19:26:16 +02:00
$STD apt-get -y autoremove
$STD apt-get -y autoclean
2023-08-16 14:56:17 +02:00
msg_ok "Cleaned"