Skip to content

Commit edb8ee5

Browse files
authored
Refactor: Habitica (#5911)
1 parent d30c071 commit edb8ee5

File tree

3 files changed

+55
-45
lines changed

3 files changed

+55
-45
lines changed

ct/habitica.sh

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,61 @@ 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/habitica" ]]; then
28-
msg_error "No ${APP} Installation Found!"
29-
exit
30-
fi
31-
RELEASE=$(curl -fsSL https://api.github.com/repos/HabitRPG/habitica/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
32-
if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then
33-
msg_info "Stopping $APP"
34-
systemctl stop habitica-mongodb
35-
systemctl stop habitica
36-
systemctl stop habitica-client
37-
msg_ok "Stopped $APP"
27+
if [[ ! -d "/opt/habitica" ]]; then
28+
msg_error "No ${APP} Installation Found!"
29+
exit
30+
fi
31+
NODE_VERSION="20" NODE_MODULE="gulp-cli,mocha" setup_nodejs
32+
RELEASE=$(curl -fsSL https://api.github.com/repos/HabitRPG/habitica/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
33+
if [[ "${RELEASE}" != "$(cat ~/.habitica 2>/dev/null)" ]] || [[ ! -f ~/.habitica ]]; then
3834

39-
msg_info "Updating $APP to ${RELEASE}"
40-
temp_file=$(mktemp)
41-
curl -fsSL "https://github.com/HabitRPG/habitica/archive/refs/tags/v${RELEASE}.tar.gz" -o "$temp_file"
42-
tar zxf $temp_file
43-
cp -rf habitica-${RELEASE}/* /opt/habitica
44-
cd /opt/habitica
45-
$STD npm i
46-
echo "${RELEASE}" >/opt/${APP}_version.txt
47-
msg_ok "Updated $APP to ${RELEASE}"
35+
msg_info "Stopping $APP"
36+
systemctl stop habitica-mongodb
37+
systemctl stop habitica
38+
systemctl stop habitica-client
39+
msg_ok "Stopped $APP"
40+
41+
msg_info "Save configuration"
42+
if [[ -f /opt/habitica/config.json ]]; then
43+
cp /opt/habitica/config.json ~/config.json
44+
msg_ok "Saved configuration"
45+
else
46+
msg_warn "No configuration file found, skipping save"
47+
fi
4848

49-
msg_info "Starting $APP"
50-
systemctl start habitica-mongodb
51-
systemctl start habitica
52-
systemctl start habitica-client
53-
msg_ok "Started $APP"
49+
fetch_and_deploy_gh_release "habitica" "HabitRPG/habitica" "tarball" "latest" "/opt/habitica"
5450

55-
msg_info "Cleaning Up"
56-
rm -f $temp_file
57-
rm -rf ~/habitica-${RELEASE}
58-
msg_ok "Cleanup Completed"
51+
msg_info "Updating $APP to ${RELEASE}"
52+
cd /opt/habitica
53+
$STD npm i
54+
$STD npm run postinstall
55+
$STD npm run client:build
56+
$STD gulp build:prod
57+
msg_ok "Updated $APP to ${RELEASE}"
5958

60-
msg_ok "Update Successful"
59+
msg_info "Restoring configuration"
60+
if [[ -f ~/config.json ]]; then
61+
cp ~/config.json /opt/habitica/config.json
62+
msg_ok "Restored configuration"
6163
else
62-
msg_ok "No update required. ${APP} is already at ${RELEASE}"
64+
msg_warn "No configuration file found to restore"
6365
fi
64-
exit
66+
67+
msg_info "Starting $APP"
68+
systemctl start habitica-mongodb
69+
systemctl start habitica
70+
systemctl start habitica-client
71+
msg_ok "Started $APP"
72+
73+
msg_ok "Update Successful"
74+
else
75+
msg_ok "No update required. ${APP} is already at ${RELEASE}"
76+
fi
77+
exit
6578
}
6679

6780
start
@@ -71,4 +84,4 @@ description
7184
msg_ok "Completed Successfully!\n"
7285
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
7386
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
74-
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:8080${CL}"
87+
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:3000${CL}"

frontend/public/json/habitica.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/habitica-install.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,16 @@ curl -fsSL "http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1
2222
$STD dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
2323
msg_ok "Installed Dependencies"
2424

25-
NODE_VERSION="20" setup_nodejs
25+
NODE_VERSION="20" NODE_MODULE="gulp-cli,mocha" setup_nodejs
26+
fetch_and_deploy_gh_release "habitica" "HabitRPG/habitica" "tarball" "latest" "/opt/habitica"
2627

2728
msg_info "Setup ${APPLICATION}"
28-
temp_file=$(mktemp)
29-
RELEASE=$(curl -fsSL https://api.github.com/repos/HabitRPG/habitica/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
30-
curl -fsSL "https://github.com/HabitRPG/habitica/archive/refs/tags/v${RELEASE}.tar.gz" -o "$temp_file"
31-
tar zxf $temp_file
32-
mv habitica-${RELEASE}/ /opt/habitica
3329
cd /opt/habitica
3430
$STD npm i
31+
$STD npm run postinstall
32+
$STD npm run client:build
33+
$STD gulp build:prod
3534
cp config.json.example config.json
36-
echo "${RELEASE}" >/opt/${APPLICATION}_version.txt
3735
msg_ok "Setup ${APPLICATION}"
3836

3937
msg_info "Creating Service"
@@ -91,7 +89,6 @@ motd_ssh
9189
customize
9290

9391
msg_info "Cleaning up"
94-
rm -f $temp_file
9592
$STD apt-get -y autoremove
9693
$STD apt-get -y autoclean
9794
msg_ok "Cleaned"

0 commit comments

Comments
 (0)