From edb8ee5980d19157e8333db591896ef6a042dabc Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Thu, 10 Jul 2025 14:00:04 +0200 Subject: [PATCH] Refactor: Habitica (#5911) --- ct/habitica.sh | 95 +++++++++++++++++------------- frontend/public/json/habitica.json | 2 +- install/habitica-install.sh | 13 ++-- 3 files changed, 60 insertions(+), 50 deletions(-) diff --git a/ct/habitica.sh b/ct/habitica.sh index 5c1f29289..75c64648c 100644 --- a/ct/habitica.sh +++ b/ct/habitica.sh @@ -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" - - 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 "Starting $APP" - systemctl start habitica-mongodb - systemctl start habitica - systemctl start habitica-client - msg_ok "Started $APP" - - msg_info "Cleaning Up" - rm -f $temp_file - rm -rf ~/habitica-${RELEASE} - msg_ok "Cleanup Completed" - - msg_ok "Update Successful" - else - msg_ok "No update required. ${APP} is already at ${RELEASE}" - fi + 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 "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 + + fetch_and_deploy_gh_release "habitica" "HabitRPG/habitica" "tarball" "latest" "/opt/habitica" + + 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_info "Restoring configuration" + if [[ -f ~/config.json ]]; then + cp ~/config.json /opt/habitica/config.json + msg_ok "Restored configuration" + else + msg_warn "No configuration file found to restore" + fi + + 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 @@ -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}" \ No newline at end of file +echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:3000${CL}" diff --git a/frontend/public/json/habitica.json b/frontend/public/json/habitica.json index f4305ff51..76690b9dc 100644 --- a/frontend/public/json/habitica.json +++ b/frontend/public/json/habitica.json @@ -8,7 +8,7 @@ "type": "ct", "updateable": true, "privileged": false, - "interface_port": 8080, + "interface_port": 3000, "documentation": "https://github.com/HabitRPG/habitica/wiki", "website": "https://habitica.com/", "logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/habitica.webp", diff --git a/install/habitica-install.sh b/install/habitica-install.sh index 17443d621..d1915be03 100644 --- a/install/habitica-install.sh +++ b/install/habitica-install.sh @@ -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" @@ -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"