Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 49 additions & 36 deletions ct/habitica.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,61 @@ color
catch_errors

function update_script() {
header_info
check_container_storage
check_container_resources
header_info
check_container_storage
check_container_resources

if [[ ! -d "/opt/habitica" ]]; then
msg_error "No ${APP} Installation Found!"
exit
fi
RELEASE=$(curl -fsSL https://api.github.com/repos/HabitRPG/habitica/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then
msg_info "Stopping $APP"
systemctl stop habitica-mongodb
systemctl stop habitica
systemctl stop habitica-client
msg_ok "Stopped $APP"
if [[ ! -d "/opt/habitica" ]]; then
msg_error "No ${APP} Installation Found!"
exit
fi
NODE_VERSION="20" NODE_MODULE="gulp-cli,mocha" setup_nodejs
RELEASE=$(curl -fsSL https://api.github.com/repos/HabitRPG/habitica/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
if [[ "${RELEASE}" != "$(cat ~/.habitica 2>/dev/null)" ]] || [[ ! -f ~/.habitica ]]; then

msg_info "Updating $APP to ${RELEASE}"
temp_file=$(mktemp)
curl -fsSL "https://github.com/HabitRPG/habitica/archive/refs/tags/v${RELEASE}.tar.gz" -o "$temp_file"
tar zxf $temp_file
cp -rf habitica-${RELEASE}/* /opt/habitica
cd /opt/habitica
$STD npm i
echo "${RELEASE}" >/opt/${APP}_version.txt
msg_ok "Updated $APP to ${RELEASE}"
msg_info "Stopping $APP"
systemctl stop habitica-mongodb
systemctl stop habitica
systemctl stop habitica-client
msg_ok "Stopped $APP"

msg_info "Save configuration"
if [[ -f /opt/habitica/config.json ]]; then
cp /opt/habitica/config.json ~/config.json
msg_ok "Saved configuration"
else
msg_warn "No configuration file found, skipping save"
fi

msg_info "Starting $APP"
systemctl start habitica-mongodb
systemctl start habitica
systemctl start habitica-client
msg_ok "Started $APP"
fetch_and_deploy_gh_release "habitica" "HabitRPG/habitica" "tarball" "latest" "/opt/habitica"

msg_info "Cleaning Up"
rm -f $temp_file
rm -rf ~/habitica-${RELEASE}
msg_ok "Cleanup Completed"
msg_info "Updating $APP to ${RELEASE}"
cd /opt/habitica
$STD npm i
$STD npm run postinstall
$STD npm run client:build
$STD gulp build:prod
msg_ok "Updated $APP to ${RELEASE}"

msg_ok "Update Successful"
msg_info "Restoring configuration"
if [[ -f ~/config.json ]]; then
cp ~/config.json /opt/habitica/config.json
msg_ok "Restored configuration"
else
msg_ok "No update required. ${APP} is already at ${RELEASE}"
msg_warn "No configuration file found to restore"
fi
exit

msg_info "Starting $APP"
systemctl start habitica-mongodb
systemctl start habitica
systemctl start habitica-client
msg_ok "Started $APP"

msg_ok "Update Successful"
else
msg_ok "No update required. ${APP} is already at ${RELEASE}"
fi
exit
}

start
Expand All @@ -71,4 +84,4 @@ description
msg_ok "Completed Successfully!\n"
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:8080${CL}"
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:3000${CL}"
2 changes: 1 addition & 1 deletion frontend/public/json/habitica.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions install/habitica-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@ curl -fsSL "http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1
$STD dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
msg_ok "Installed Dependencies"

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

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

msg_info "Creating Service"
Expand Down Expand Up @@ -91,7 +89,6 @@ motd_ssh
customize

msg_info "Cleaning up"
rm -f $temp_file
$STD apt-get -y autoremove
$STD apt-get -y autoclean
msg_ok "Cleaned"