Skip to content

Commit af302d6

Browse files
authored
Add Habitica script (#2779)
1 parent bedb908 commit af302d6

File tree

3 files changed

+227
-0
lines changed

3 files changed

+227
-0
lines changed

ct/habitica.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)
3+
# Copyright (c) 2021-2025 community-scripts ORG
4+
# Author: Slaviša Arežina (tremor021)
5+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
6+
# Source: https://github.com/HabitRPG/habitica
7+
8+
APP="Habitica"
9+
var_tags="gaming"
10+
var_cpu="2"
11+
var_ram="4096"
12+
var_disk="8"
13+
var_os="debian"
14+
var_version="12"
15+
var_unprivileged="1"
16+
17+
header_info "$APP"
18+
variables
19+
color
20+
catch_errors
21+
22+
function update_script() {
23+
header_info
24+
check_container_storage
25+
check_container_resources
26+
27+
if [[ ! -d "/opt/habitica" ]]; then
28+
msg_error "No ${APP} Installation Found!"
29+
exit
30+
fi
31+
RELEASE=$(curl -s 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"
38+
39+
msg_info "Updating $APP to ${RELEASE}"
40+
temp_file=$(mktemp)
41+
wget -q "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}"
48+
49+
msg_info "Starting $APP"
50+
systemctl start habitica-mongodb
51+
systemctl start habitica
52+
systemctl start habitica-client
53+
msg_ok "Started $APP"
54+
55+
msg_info "Cleaning Up"
56+
rm -f $temp_file
57+
rm -rf ~/habitica-${RELEASE}
58+
msg_ok "Cleanup Completed"
59+
60+
msg_ok "Update Successful"
61+
else
62+
msg_ok "No update required. ${APP} is already at ${RELEASE}"
63+
fi
64+
exit
65+
}
66+
67+
start
68+
build_container
69+
description
70+
71+
msg_ok "Completed Successfully!\n"
72+
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
73+
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
74+
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:8080${CL}"

install/habitica-install.sh

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (c) 2021-2025 community-scripts ORG
4+
# Author: Slaviša Arežina (tremor021)
5+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
6+
# Source: https://github.com/HabitRPG/habitica
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+
libkrb5-dev \
22+
gnupg \
23+
build-essential \
24+
git
25+
wget -q http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
26+
$STD dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
27+
msg_ok "Installed Dependencies"
28+
29+
msg_info "Setting up Node.js Repository"
30+
mkdir -p /etc/apt/keyrings
31+
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
32+
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" >/etc/apt/sources.list.d/nodesource.list
33+
msg_ok "Set up Node.js Repository"
34+
35+
msg_info "Setup Node.js"
36+
$STD apt-get update
37+
$STD apt-get install -y nodejs
38+
msg_ok "Setup Node.js"
39+
40+
msg_info "Setup ${APPLICATION}"
41+
temp_file=$(mktemp)
42+
RELEASE=$(curl -s https://api.github.com/repos/HabitRPG/habitica/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
43+
wget -q "https://github.com/HabitRPG/habitica/archive/refs/tags/v${RELEASE}.tar.gz" -O $temp_file
44+
tar zxf $temp_file
45+
mv habitica-${RELEASE}/ /opt/habitica
46+
cd /opt/habitica
47+
$STD npm i
48+
cp config.json.example config.json
49+
echo "${RELEASE}" >/opt/${APPLICATION}_version.txt
50+
msg_ok "Setup ${APPLICATION}"
51+
52+
msg_info "Creating Service"
53+
cat <<EOF >/etc/systemd/system/habitica-mongodb.service
54+
[Unit]
55+
Description=Habitica MongoDB Service
56+
After=network.target
57+
58+
[Service]
59+
Type=simple
60+
User=root
61+
WorkingDirectory=/opt/habitica
62+
ExecStart=/usr/bin/npm run mongo:dev
63+
Restart=always
64+
65+
[Install]
66+
WantedBy=multi-user.target
67+
EOF
68+
cat <<EOF >/etc/systemd/system/habitica.service
69+
[Unit]
70+
Description=Habitica Service
71+
After=habitica-mongodb.service
72+
73+
[Service]
74+
Type=simple
75+
User=root
76+
WorkingDirectory=/opt/habitica
77+
ExecStart=/usr/bin/npm start
78+
Restart=always
79+
80+
[Install]
81+
WantedBy=multi-user.target
82+
EOF
83+
cat <<EOF >/etc/systemd/system/habitica-client.service
84+
[Unit]
85+
Description=Habitica Client Service
86+
After=habitica.service
87+
88+
[Service]
89+
Type=simple
90+
User=root
91+
WorkingDirectory=/opt/habitica
92+
ExecStart=/usr/bin/npm run client:dev
93+
Restart=always
94+
95+
[Install]
96+
WantedBy=multi-user.target
97+
EOF
98+
systemctl enable -q --now habitica-mongodb
99+
systemctl enable -q --now habitica
100+
systemctl enable -q --now habitica-client
101+
msg_ok "Created Service"
102+
103+
motd_ssh
104+
customize
105+
106+
msg_info "Cleaning up"
107+
rm -f $temp_file
108+
$STD apt-get -y autoremove
109+
$STD apt-get -y autoclean
110+
msg_ok "Cleaned"

json/habitica.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "Habitica",
3+
"slug": "habitica",
4+
"categories": [
5+
24
6+
],
7+
"date_created": "2025-03-02",
8+
"type": "ct",
9+
"updateable": true,
10+
"privileged": false,
11+
"interface_port": 8080,
12+
"documentation": "https://github.com/HabitRPG/habitica/wiki",
13+
"website": "https://habitica.com/",
14+
"logo": "https://github.com/HabitRPG/habitica/raw/refs/heads/develop/website/client/src/assets/svg/logo.svg",
15+
"description": "Habitica is an open-source habit-building program that treats your life like a role-playing game. Level up as you succeed, lose HP as you fail, and earn Gold to buy weapons and armor!",
16+
"install_methods": [
17+
{
18+
"type": "default",
19+
"script": "ct/habitica.sh",
20+
"resources": {
21+
"cpu": 2,
22+
"ram": 4096,
23+
"hdd": 8,
24+
"os": "debian",
25+
"version": "12"
26+
}
27+
}
28+
],
29+
"default_credentials": {
30+
"username": null,
31+
"password": null
32+
},
33+
"notes": [
34+
{
35+
"text": "It takes a minute or two after installation for web UI to start, please be patient.",
36+
"type": "info"
37+
},
38+
{
39+
"text": "Config file is at `/opt/habitica/config.json`",
40+
"type": "info"
41+
}
42+
]
43+
}

0 commit comments

Comments
 (0)