|
| 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" |
0 commit comments