homarr script V3
This commit is contained in:
parent
01edca0355
commit
2d5450c27b
44
ct/homarr.sh
44
ct/homarr.sh
@ -32,12 +32,22 @@ function update_script() {
|
|||||||
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"
|
|
||||||
mkdir -p /opt/homarr-data-backup
|
if ! grep -q '^REDIS_IS_EXTERNAL=' /opt/homarr/.env; then
|
||||||
cp /opt/homarr/.env /opt/homarr-data-backup/.env
|
msg_info "Fixing old structure"
|
||||||
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
|
||||||
|
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
|
||||||
|
# TODO: change in json
|
||||||
|
systemctl daemon-reload
|
||||||
|
cp /opt/homarr/.env /opt/homarr.env
|
||||||
|
msg_ok "Fixed old structure"
|
||||||
|
fi
|
||||||
|
|
||||||
msg_info "Updating Nodejs"
|
msg_info "Updating Nodejs"
|
||||||
$STD apt update
|
$STD apt update
|
||||||
@ -45,44 +55,26 @@ function update_script() {
|
|||||||
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
|
||||||
|
|
||||||
rm -rf /opt/homarr
|
rm -rf /opt/homarr
|
||||||
fetch_and_deploy_gh_release "homarr" "homarr-labs/homarr"
|
fetch_and_deploy_gh_release "homarr" "homarr-labs/homarr"
|
||||||
|
|
||||||
msg_info "Updating and rebuilding ${APP} (Patience)"
|
msg_info "Updating Homarr to v${RELEASE}"
|
||||||
mv /opt/homarr-data-backup/.env /opt/homarr/.env
|
cp /opt/homarr/redis.conf /etc/redis/redis.conf
|
||||||
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
|
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
|
|
||||||
cp ./node_modules/better-sqlite3/build/Release/better_sqlite3.node ./build/better_sqlite3.node
|
|
||||||
msg_ok "Updated ${APP}"
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,21 +20,22 @@ $STD apt install -y \
|
|||||||
build-essential \
|
build-essential \
|
||||||
nginx \
|
nginx \
|
||||||
gettext \
|
gettext \
|
||||||
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"
|
||||||
|
|
||||||
msg_info "Installing Homarr (Patience)"
|
msg_info "Installing Homarr (Patience)"
|
||||||
|
ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1
|
||||||
cd /opt
|
cd /opt
|
||||||
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}'
|
||||||
@ -42,54 +43,20 @@ 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/redis.conf /etc/redis/redis.conf
|
||||||
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
|
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
|
|
||||||
#!/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
|
|
||||||
cat <<EOF >/etc/systemd/system/homarr.service
|
cat <<EOF >/etc/systemd/system/homarr.service
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Homarr Service
|
Description=Homarr Service
|
||||||
@ -98,14 +65,16 @@ 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 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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user