Skip to content

Commit f3579ac

Browse files
committed
Create install_pokestack helper script
1 parent 052fafd commit f3579ac

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

scripts/install_pokestack.sh

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
if (( EUID != 0 )); then
6+
echo "[install_pokestack] You must run this script as root." 1>&2
7+
exit 1
8+
fi
9+
10+
vergte () {
11+
if [[ $1 == $2 ]]
12+
then
13+
return 0
14+
fi
15+
local IFS=.
16+
local i ver1=($1) ver2=($2)
17+
# fill empty fields in ver1 with zeros
18+
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
19+
do
20+
ver1[i]=0
21+
done
22+
for ((i=0; i<${#ver1[@]}; i++))
23+
do
24+
if [[ -z ${ver2[i]} ]]
25+
then
26+
# fill empty fields in ver2 with zeros
27+
ver2[i]=0
28+
fi
29+
if ((10#${ver1[i]} > 10#${ver2[i]}))
30+
then
31+
return 0
32+
fi
33+
if ((10#${ver1[i]} < 10#${ver2[i]}))
34+
then
35+
return 1
36+
fi
37+
done
38+
return 0
39+
}
40+
41+
USER=$(who am i | cut -d ' ' -f 1)
42+
NODE_VERSION="$(node --version | cut -c 2-)"
43+
44+
if [ $? = 0 ] && vergte "$NODE_VERSION" "6.0"; then
45+
echo "[install_pokestack] NodeJS >=6.0 (v$NODE_VERSION) already installed, skipping"
46+
else
47+
echo "[install_pokestack] Installing NodeJS >=6.x and native build tools"
48+
curl -sL https://deb.nodesource.com/setup_6.x | bash -
49+
apt-get install -y nodejs build-essential
50+
fi
51+
52+
echo "[install_pokestack] Downloading latest pokestack release"
53+
LATEST_URL=$(curl -s https://api.github.com/repos/v1ct04/benchstack/releases | grep browser_download_url | cut -d '"' -f 4 | grep pokestack | grep .tar.gz)
54+
55+
echo "[install_pokestack] URL: $LATEST_URL"
56+
FILENAME="${LATEST_URL##*/}"
57+
DIRNAME="${FILENAME%.tar.gz}"
58+
59+
if [[ $? != 0 || -z "$LATEST_URL" || -z "$DIRNAME" ]]; then
60+
echo "[install_pokestack] Failed to get release URL or filename."
61+
exit 1
62+
fi
63+
64+
if [ -d "$DIRNAME" ]; then
65+
echo "[install_pokestack] Latest release already downloaded. Skipping."
66+
else
67+
curl -SL "$LATEST_URL" | sudo -u "$USER" tar -xz
68+
fi
69+
cd "$DIRNAME"
70+
71+
echo "[install_pokestack] Installing npm dependencies as user $USER"
72+
sudo -u "$USER" npm install
73+
74+
# Set up system service
75+
76+
echo "[install_pokestack] Installing pm2 and enabling auto-start behavior"
77+
npm install -g pm2
78+
pm2 startup
79+
80+
echo "[install_pokestack] Restarting pokestack service in pm2"
81+
pm2 delete pokestack > /dev/null || true
82+
if [ $# -gt 0 ]; then
83+
pm2 start bin/www --name="pokestack" -- "$@"
84+
else
85+
pm2 start bin/www --name="pokestack"
86+
fi
87+
pm2 save
88+
89+
echo "[install_pokestack] Waiting for service initialization"
90+
sleep 5
91+
92+
if pm2 status | grep pokestack | grep online > /dev/null; then
93+
echo "[install_pokestack] Success! Pokestack service is up and running"
94+
else
95+
echo "[install_pokestack] Failed! Check pm2 logs for fixing."
96+
exit 1
97+
fi

0 commit comments

Comments
 (0)