|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2025 community-scripts ORG |
| 4 | +# Author: Snarkenfaugister |
| 5 | +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 6 | +# Source: https://github.com/stonith404/pocket-id |
| 7 | + |
| 8 | +source /dev/stdin <<< "$FUNCTIONS_FILE_PATH" |
| 9 | +color |
| 10 | +verb_ip6 |
| 11 | +catch_errors |
| 12 | +setting_up_container |
| 13 | +network_check |
| 14 | +update_os |
| 15 | + |
| 16 | +msg_info "Installing Dependencies" |
| 17 | +$STD apt-get install -y \ |
| 18 | + curl \ |
| 19 | + sudo \ |
| 20 | + mc \ |
| 21 | + gpg \ |
| 22 | + caddy \ |
| 23 | + gcc |
| 24 | +msg_ok "Installed Dependencies" |
| 25 | + |
| 26 | +msg_info "Setting up Node.js Repository" |
| 27 | +mkdir -p /etc/apt/keyrings |
| 28 | +curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg |
| 29 | +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 |
| 30 | +msg_ok "Set up Node.js Repository" |
| 31 | + |
| 32 | +msg_info "Installing Node.js" |
| 33 | +$STD apt-get update |
| 34 | +$STD apt-get install -y nodejs |
| 35 | +msg_ok "Installed Node.js" |
| 36 | + |
| 37 | +msg_info "Installing Golang" |
| 38 | +cd /tmp |
| 39 | +set +o pipefail |
| 40 | +GO_RELEASE=$(curl -s https://go.dev/dl/ | grep -o -m 1 "go.*\linux-amd64.tar.gz") |
| 41 | +wget -q https://golang.org/dl/${GO_RELEASE} |
| 42 | +tar -xzf ${GO_RELEASE} -C /usr/local |
| 43 | +ln -s /usr/local/go/bin/go /usr/bin/go |
| 44 | +set -o pipefail |
| 45 | +msg_ok "Installed Golang" |
| 46 | + |
| 47 | +read -r -p "What public URL do you want to use (e.g. pocketid.mydomain.com)? " public_url |
| 48 | +msg_info "Setup Pocket ID" |
| 49 | +cd /opt |
| 50 | +RELEASE=$(curl -s https://api.github.com/repos/stonith404/pocket-id/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') |
| 51 | +wget -q "https://github.com/stonith404/pocket-id/archive/refs/tags/v${RELEASE}.zip" |
| 52 | +unzip -q v${RELEASE}.zip |
| 53 | +mv pocket-id-${RELEASE}/ /opt/pocket-id |
| 54 | + |
| 55 | +cd /opt/pocket-id/backend |
| 56 | +cp .env.example .env |
| 57 | +sed -i "s/PUBLIC_APP_URL=http:\/\/localhost/PUBLIC_APP_URL=https:\/\/${public_url}/" .env |
| 58 | +cd cmd |
| 59 | +CGO_ENABLED=1 |
| 60 | +GOOS=linux |
| 61 | +$STD go build -o ../pocket-id-backend |
| 62 | + |
| 63 | +cd ../../frontend |
| 64 | +cp .env.example .env |
| 65 | +sed -i "s/PUBLIC_APP_URL=http:\/\/localhost/PUBLIC_APP_URL=https:\/\/${public_url}/" .env |
| 66 | +$STD npm install |
| 67 | +$STD npm run build |
| 68 | + |
| 69 | +cd .. |
| 70 | +cp reverse-proxy/Caddyfile /etc/caddy/Caddyfile |
| 71 | +echo "${RELEASE}" >/opt/${APPLICATION}_version.txt |
| 72 | +msg_ok "Setup Pocket ID" |
| 73 | + |
| 74 | +msg_info "Creating Service" |
| 75 | +cat <<EOF >/etc/systemd/system/pocketid-backend.service |
| 76 | +[Unit] |
| 77 | +Description=Pocket ID Backend |
| 78 | +After=network.target |
| 79 | +
|
| 80 | +[Service] |
| 81 | +Type=simple |
| 82 | +User=root |
| 83 | +Group=root |
| 84 | +WorkingDirectory=/opt/pocket-id/backend |
| 85 | +EnvironmentFile=/opt/pocket-id/backend/.env |
| 86 | +ExecStart=/opt/pocket-id/backend/pocket-id-backend |
| 87 | +Restart=always |
| 88 | +RestartSec=10 |
| 89 | +
|
| 90 | +[Install] |
| 91 | +WantedBy=multi-user.target |
| 92 | +EOF |
| 93 | + |
| 94 | +cat <<EOF >/etc/systemd/system/pocketid-frontend.service |
| 95 | +[Unit] |
| 96 | +Description=Pocket ID Frontend |
| 97 | +After=network.target |
| 98 | +
|
| 99 | +[Service] |
| 100 | +Type=simple |
| 101 | +User=root |
| 102 | +Group=root |
| 103 | +WorkingDirectory=/opt/pocket-id/frontend |
| 104 | +EnvironmentFile=/opt/pocket-id/frontend/.env |
| 105 | +ExecStart=/usr/bin/node build/index.js |
| 106 | +Restart=always |
| 107 | +RestartSec=10 |
| 108 | +
|
| 109 | +[Install] |
| 110 | +WantedBy=multi-user.target |
| 111 | +EOF |
| 112 | +msg_ok "Created Service" |
| 113 | + |
| 114 | +msg_info "Starting Services" |
| 115 | +systemctl enable -q --now pocketid-backend |
| 116 | +systemctl enable -q --now pocketid-frontend |
| 117 | +systemctl restart caddy |
| 118 | +msg_ok "Started Services" |
| 119 | + |
| 120 | +motd_ssh |
| 121 | +customize |
| 122 | + |
| 123 | +msg_info "Cleaning up" |
| 124 | +rm -f /opt/v${RELEASE}.zip |
| 125 | +$STD apt-get -y autoremove |
| 126 | +$STD apt-get -y autoclean |
| 127 | +msg_ok "Cleaned" |
| 128 | + |
| 129 | +motd_ssh |
| 130 | +customize |
0 commit comments