Skip to content

Commit ff5b793

Browse files
authored
BREAKING CHANGE: Fix PocketID for v1.0.0 (#4711)
1 parent 4044790 commit ff5b793

File tree

3 files changed

+74
-139
lines changed

3 files changed

+74
-139
lines changed

ct/pocketid.sh

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -20,63 +20,62 @@ color
2020
catch_errors
2121

2222
function update_script() {
23-
header_info
24-
check_container_storage
25-
check_container_resources
23+
header_info
24+
check_container_storage
25+
check_container_resources
2626

27-
if [[ ! -d /opt/pocket-id ]]; then
28-
msg_error "No ${APP} Installation Found!"
29-
exit
30-
fi
31-
32-
RELEASE=$(curl -fsSL https://api.github.com/repos/pocket-id/pocket-id/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
33-
if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then
34-
msg_info "Updating $APP"
35-
36-
msg_info "Stopping $APP"
37-
systemctl stop pocketid-backend.service
38-
systemctl stop pocketid-frontend.service
39-
systemctl stop caddy.service
40-
msg_ok "Stopped $APP"
41-
42-
msg_info "Updating $APP to v${RELEASE}"
43-
cd /opt
44-
cp -r /opt/pocket-id/backend/data /opt/data
45-
cp /opt/pocket-id/backend/.env /opt/backend.env
46-
cp /opt/pocket-id/frontend/.env /opt/frontend.env
47-
rm -r /opt/pocket-id
48-
curl -fsSL "https://github.com/pocket-id/pocket-id/archive/refs/tags/v${RELEASE}.zip" -o $(basename "https://github.com/pocket-id/pocket-id/archive/refs/tags/v${RELEASE}.zip")
49-
unzip -q v${RELEASE}.zip
50-
mv pocket-id-${RELEASE} /opt/pocket-id
51-
mv /opt/data /opt/pocket-id/backend/data
52-
mv /opt/backend.env /opt/pocket-id/backend/.env
53-
mv /opt/frontend.env /opt/pocket-id/frontend/.env
54-
55-
cd /opt/pocket-id/backend/cmd
56-
go build -o ../pocket-id-backend
57-
cd ../../frontend
58-
npm install
59-
npm run build
60-
msg_ok "Updated $APP to ${RELEASE}"
61-
62-
msg_info "Starting $APP"
63-
systemctl start pocketid-backend.service
64-
systemctl start pocketid-frontend.service
65-
systemctl start caddy.service
66-
sleep 2
67-
msg_ok "Started $APP"
68-
69-
# Cleaning up
70-
msg_info "Cleaning Up"
71-
rm -f /opt/v${RELEASE}.zip
72-
msg_ok "Cleanup Completed"
27+
if [[ ! -d /opt/pocket-id ]]; then
28+
msg_error "No ${APP} Installation Found!"
29+
exit
30+
fi
7331

74-
echo "${RELEASE}" >/opt/${APP}_version.txt
75-
msg_ok "Update Successful"
32+
RELEASE=$(curl -fsSL https://api.github.com/repos/pocket-id/pocket-id/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
33+
if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then
34+
if [[ "$(cat /opt/${APP}_version.txt)" < "1.0.0" ]]; then
35+
msg_info "Migrating ${APP} to v${RELEASE}"
36+
systemctl -q disable --now pocketid-backend pocketid-frontend caddy
37+
mv /etc/caddy/Caddyfile ~/Caddyfile.bak
38+
$STD apt remove --purge caddy nodejs -y
39+
$STD apt autoremove -y
40+
rm /etc/apt/{keyrings/nodesource.gpg,sources.list.d/nodesource.list}
41+
rm -r /usr/local/go
42+
cp -r /opt/pocket-id/backend/data /opt/data
43+
cp /opt/pocket-id/backend/.env /opt/env
44+
sed -i -e 's/PUBLIC_//g' \
45+
-e '/^SQLITE_DB_PATH/d' \
46+
-e '/^POSTGRES/s/^/# /' \
47+
-e '/^UPLOAD_PATH/d' \
48+
-e 's/8080/1411/' /opt/env
49+
rm -r /opt/pocket-id
50+
rm /etc/systemd/system/pocketid-frontend.service
51+
BACKEND="/etc/systemd/system/pocketid-backend.service"
52+
sed -i -e 's/Backend/Service/' \
53+
-e 's/\/backend\|-backend//g' "$BACKEND"
54+
mv "$BACKEND" ${BACKEND//-backend/}
55+
systemctl daemon-reload
56+
systemctl -q enable pocketid
57+
mkdir /opt/pocket-id
58+
mv /opt/data /opt/pocket-id
59+
msg_ok "Migration complete. The reverse proxy port has been changed to 1411."
7660
else
77-
msg_ok "No update required. ${APP} is already at ${RELEASE}"
61+
msg_info "Updating $APP to v${RELEASE}"
62+
systemctl stop pocketid
63+
cp /opt/pocket-id/.env /opt/env
7864
fi
79-
exit
65+
curl -fsSL "https://github.com/pocket-id/pocket-id/releases/download/v${RELEASE}/pocket-id-linux-amd64" -o /opt/pocket-id/pocket-id
66+
chmod u+x /opt/pocket-id/pocket-id
67+
mv /opt/env /opt/pocket-id/.env
68+
69+
msg_info "Starting $APP"
70+
systemctl start pocketid
71+
msg_ok "Started $APP"
72+
73+
echo "${RELEASE}" >/opt/${APP}_version.txt
74+
msg_ok "Update Successful"
75+
else
76+
msg_ok "No update required. ${APP} is already at ${RELEASE}"
77+
fi
78+
exit
8079
}
8180

8281
start
@@ -85,6 +84,6 @@ description
8584

8685
msg_ok "Completed Successfully!\n"
8786
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
88-
echo -e "${INFO}${YW} Configure your reverse proxy to point to:${BGN} ${IP}:80${CL}"
87+
echo -e "${INFO}${YW} Configure your reverse proxy to point to:${BGN} ${IP}:1411${CL}"
8988
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
9089
echo -e "${TAB}${GATEWAY}${BGN}https://{PUBLIC_URL}/login/setup${CL}"

frontend/public/json/pocketid.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"type": "ct",
99
"updateable": true,
1010
"privileged": false,
11-
"interface_port": 80,
11+
"interface_port": 1411,
1212
"documentation": "https://pocket-id.org/docs/",
1313
"website": "https://github.com/pocket-id/pocket-id",
1414
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/pocket-id.webp",
15-
"config_path": "/opt/pocket-id/backend/.env and /opt/pocket-id/frontend/.env",
15+
"config_path": "/opt/pocket-id/.env",
1616
"description": "Pocket ID is a simple OIDC provider that allows users to authenticate with their passkeys to your services.",
1717
"install_methods": [
1818
{
@@ -35,10 +35,6 @@
3535
{
3636
"text": "Pocket ID requires https to work.",
3737
"type": "warning"
38-
},
39-
{
40-
"text": "Configuration Path: `/opt/pocket-id/backend/.env`, `/opt/pocket-id/frontend/.env`.",
41-
"type": "info"
4238
}
4339
]
4440
}

install/pocketid-install.sh

Lines changed: 19 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -13,94 +13,37 @@ setting_up_container
1313
network_check
1414
update_os
1515

16-
msg_info "Installing Dependencies"
17-
$STD apt-get install -y \
18-
gpg \
19-
caddy \
20-
gcc
21-
msg_ok "Installed Dependencies"
22-
23-
msg_info "Setting up Node.js Repository"
24-
mkdir -p /etc/apt/keyrings
25-
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
26-
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
27-
msg_ok "Set up Node.js Repository"
28-
29-
msg_info "Installing Node.js"
30-
$STD apt-get update
31-
$STD apt-get install -y nodejs
32-
msg_ok "Installed Node.js"
33-
34-
msg_info "Installing Golang"
35-
set +o pipefail
36-
temp_file=$(mktemp)
37-
golang_tarball=$(curl -fsSL https://go.dev/dl/ | grep -oP 'go[\d\.]+\.linux-amd64\.tar\.gz' | head -n 1)
38-
curl -fsSL "https://golang.org/dl/${golang_tarball}" -o "$temp_file"
39-
tar -C /usr/local -xzf "$temp_file"
40-
ln -sf /usr/local/go/bin/go /usr/local/bin/go
41-
rm -f "$temp_file"
42-
set -o pipefail
43-
msg_ok "Installed Golang"
44-
4516
read -r -p "${TAB3}What public URL do you want to use (e.g. pocketid.mydomain.com)? " public_url
4617
msg_info "Setup Pocket ID"
47-
cd /opt
4818
RELEASE=$(curl -fsSL https://api.github.com/repos/pocket-id/pocket-id/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
49-
curl -fsSL "https://github.com/pocket-id/pocket-id/archive/refs/tags/v${RELEASE}.zip" -o $(basename "https://github.com/pocket-id/pocket-id/archive/refs/tags/v${RELEASE}.zip")
50-
unzip -q v${RELEASE}.zip
51-
mv pocket-id-${RELEASE}/ /opt/pocket-id
52-
53-
cd /opt/pocket-id/backend
54-
cp .env.example .env
55-
sed -i "s/PUBLIC_APP_URL=http:\/\/localhost/PUBLIC_APP_URL=https:\/\/${public_url}/" .env
56-
cd cmd
57-
CGO_ENABLED=1
58-
GOOS=linux
59-
$STD go build -o ../pocket-id-backend
60-
61-
cd ../../frontend
62-
cp .env.example .env
63-
sed -i "s/PUBLIC_APP_URL=http:\/\/localhost/PUBLIC_APP_URL=https:\/\/${public_url}/" .env
64-
$STD npm install
65-
$STD npm run build
66-
67-
cd ..
68-
cp reverse-proxy/Caddyfile /etc/caddy/Caddyfile
19+
mkdir -p /opt/pocket-id
20+
curl -fsSL "https://github.com/pocket-id/pocket-id/releases/download/v${RELEASE}/pocket-id-linux-amd64" -o /opt/pocket-id/pocket-id
21+
chmod u+x /opt/pocket-id/pocket-id
22+
23+
cat <<EOF >/opt/pocket-id/.env
24+
APP_ENV=production
25+
APP_URL=https://${public_url}
26+
TRUST_PROXY=false
27+
# MAXMIND_LICENSE_KEY=
28+
PORT=1411
29+
HOST=0.0.0.0
30+
EOF
6931
echo "${RELEASE}" >/opt/${APPLICATION}_version.txt
7032
msg_ok "Setup Pocket ID"
7133

7234
msg_info "Creating Service"
73-
cat <<EOF >/etc/systemd/system/pocketid-backend.service
74-
[Unit]
75-
Description=Pocket ID Backend
76-
After=network.target
77-
78-
[Service]
79-
Type=simple
80-
User=root
81-
Group=root
82-
WorkingDirectory=/opt/pocket-id/backend
83-
EnvironmentFile=/opt/pocket-id/backend/.env
84-
ExecStart=/opt/pocket-id/backend/pocket-id-backend
85-
Restart=always
86-
RestartSec=10
87-
88-
[Install]
89-
WantedBy=multi-user.target
90-
EOF
91-
92-
cat <<EOF >/etc/systemd/system/pocketid-frontend.service
35+
cat <<EOF >/etc/systemd/system/pocketid.service
9336
[Unit]
94-
Description=Pocket ID Frontend
37+
Description=Pocket ID Service
9538
After=network.target
9639
9740
[Service]
9841
Type=simple
9942
User=root
10043
Group=root
101-
WorkingDirectory=/opt/pocket-id/frontend
102-
EnvironmentFile=/opt/pocket-id/frontend/.env
103-
ExecStart=/usr/bin/node build/index.js
44+
WorkingDirectory=/opt/pocket-id
45+
EnvironmentFile=/opt/pocket-id/.env
46+
ExecStart=/opt/pocket-id/pocket-id
10447
Restart=always
10548
RestartSec=10
10649
@@ -109,17 +52,14 @@ WantedBy=multi-user.target
10952
EOF
11053
msg_ok "Created Service"
11154

112-
msg_info "Starting Services"
113-
systemctl enable -q --now pocketid-backend
114-
systemctl enable -q --now pocketid-frontend
115-
systemctl restart caddy
55+
msg_info "Starting Service"
56+
systemctl enable -q --now pocketid
11657
msg_ok "Started Services"
11758

11859
motd_ssh
11960
customize
12061

12162
msg_info "Cleaning up"
122-
rm -f /opt/v${RELEASE}.zip
12363
$STD apt-get -y autoremove
12464
$STD apt-get -y autoclean
12565
msg_ok "Cleaned"

0 commit comments

Comments
 (0)