diff --git a/ct/hoarder.sh b/ct/hoarder.sh new file mode 100644 index 00000000..ce4596d2 --- /dev/null +++ b/ct/hoarder.sh @@ -0,0 +1,109 @@ +#!/usr/bin/env bash +source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) +# Copyright (c) 2021-2024 tteck +# Author: vhsdream +# License: MIT +# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE + +function header_info { +clear +cat <<"EOF" + __ __ __ + / / / /___ ____ __________/ /__ _____ + / /_/ / __ \/ __ `/ ___/ __ / _ \/ ___/ + / __ / /_/ / /_/ / / / /_/ / __/ / +/_/ /_/\____/\__,_/_/ \__,_/\___/_/ + +EOF +} +header_info + +echo -e "Loading..." +APP="Hoarder" +TAGS="bookmark;links" +var_disk="8" +var_cpu="4" +var_ram="4096" +var_os="debian" +var_version="12" +variables +color +catch_errors + +function default_settings() { + CT_TYPE="1" + PW="" + CT_ID=$NEXTID + HN=$NSAPP + DISK_SIZE="$var_disk" + CORE_COUNT="$var_cpu" + RAM_SIZE="$var_ram" + BRG="vmbr0" + NET="dhcp" + GATE="" + APT_CACHER="" + APT_CACHER_IP="" + DISABLEIP6="no" + MTU="" + SD="" + NS="" + MAC="" + VLAN="" + SSH="no" + VERB="no" + echo_default +} + +function update_script() { +header_info +check_container_storage +check_container_resources +if [[ ! -d /opt/hoarder ]]; then msg_error "No ${APP} Installation Found!"; exit; fi +RELEASE=$(curl -s https://api.github.com/repos/hoarder-app/hoarder/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') +PREV_VERSION=$(cat /opt/${APP}_version.txt) +if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "${PREV_VERSION}" ]]; then + msg_info "Stopping ${APP} Services" + systemctl stop hoarder-web hoarder-workers hoarder-browser + msg_ok "Stopped ${APP} Services" + msg_info "Updating ${APP} to ${RELEASE}" + cd /opt + mv /opt/hoarder /opt/hoarder_bak + wget -q "https://github.com/hoarder-app/hoarder/archive/refs/tags/v${RELEASE}.zip" + unzip -q v${RELEASE}.zip + mv hoarder-${RELEASE} /opt/hoarder + cd /opt/hoarder/apps/web + pnpm install --frozen-lockfile >/dev/null 2>&1 + cd /opt/hoarder/apps/workers + pnpm install --frozen-lockfile >/dev/null 2>&1 + cd /opt/hoarder/apps/web + export NEXT_TELEMETRY_DISABLED=1 + pnpm exec next build --experimental-build-mode compile >/dev/null 2>&1 + cp -r /opt/hoarder/apps/web/.next/standalone/apps/web/server.js /opt/hoarder/apps/web + export DATA_DIR=/opt/hoarder_data + cd /opt/hoarder/packages/db + pnpm migrate >/dev/null 2>&1 + echo "${RELEASE}" >/opt/${APP}_version.txt + cp /opt/hoarder_bak/.env /opt/hoarder/.env + sed -i "s/SERVER_VERSION=${PREV_VERSION}/SERVER_VERSION=${RELEASE}/" /opt/hoarder/.env + msg_ok "Updated ${APP} to ${RELEASE}" + msg_info "Starting ${APP} Services" + systemctl start hoarder-browser hoarder-workers hoarder-web + msg_ok "Started ${APP}" + msg_info "Cleaning up" + rm -R /opt/v${RELEASE}.zip + rm -rf /opt/hoarder_bak + msg_ok "Cleaned" + msg_ok "Updated Successfully" +else + msg_ok "No update required. ${APP} is already at ${RELEASE}." +fi +exit +} + +start +build_container +description + +msg_ok "Completed Successfully!\n" +echo -e "${APP} Setup should be reachable by going to the following URL. + ${BL}http://${IP}:3000${CL} \n" diff --git a/install/hoarder_install.sh b/install/hoarder_install.sh new file mode 100644 index 00000000..e41aad10 --- /dev/null +++ b/install/hoarder_install.sh @@ -0,0 +1,178 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021-2024 tteck +# Author: vhsdream +# License: MIT +# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE + +source /dev/stdin <<< "$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +msg_info "Installing Dependencies" +$STD apt-get install -y \ + python3 \ + python3-distutils \ + g++ \ + build-essential \ + curl \ + git \ + sudo \ + gnupg \ + ca-certificates \ + chromium \ + libpixman-1-dev \ + libcairo2-dev \ + libjpeg-dev \ + libpango1.0-dev \ + libgif-dev \ + librsvg2-dev \ + pkg-config \ + mc +msg_ok "Installed Dependencies" + +msg_info "Installing Additional Tools" +wget -q https://github.com/Y2Z/monolith/releases/latest/download/monolith-gnu-linux-x86_64 -O /usr/bin/monolith && chmod +x /usr/bin/monolith +wget -q https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux -O /usr/bin/yt-dlp && chmod +x /usr/bin/yt-dlp +msg_ok "Installed Additional Tools" + +msg_info "Installing Meilisearch" +cd /tmp +wget -q https://github.com/meilisearch/meilisearch/releases/latest/download/meilisearch.deb +$STD dpkg -i meilisearch.deb +wget -q https://raw.githubusercontent.com/meilisearch/meilisearch/latest/config.toml -O /etc/meilisearch.toml +MASTER_KEY=$(openssl rand -base64 12) +sed -i \ + -e 's|^env =.*|env = "production"|' \ + -e "s|^# master_key =.*|master_key = \"$MASTER_KEY\"|" \ + -e 's|^db_path =.*|db_path = "/var/lib/meilisearch/data"|' \ + -e 's|^dump_dir =.*|dump_dir = "/var/lib/meilisearch/dumps"|' \ + -e 's|^snapshot_dir =.*|snapshot_dir = "/var/lib/meilisearch/snapshots"|' \ + -e 's|^# no_analytics = true|no_analytics = true|' \ + /etc/meilisearch.toml +msg_ok "Installed Meilisearch" + +msg_info "Installing Node.js" +mkdir -p /etc/apt/keyrings +curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg +echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" >/etc/apt/sources.list.d/nodesource.list +$STD apt-get update +$STD apt-get install -y nodejs +msg_ok "Installed Node.js" + +msg_info "Installing Hoarder" +cd /opt +RELEASE=$(curl -s https://api.github.com/repos/hoarder-app/hoarder/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') +wget -q "https://github.com/hoarder-app/hoarder/archive/refs/tags/v${RELEASE}.zip" +unzip -q v${RELEASE}.zip && mv hoarder-${RELEASE} /opt/hoarder + +mkdir -p /opt/hoarder_data + +cd /opt/hoarder +corepack enable +export PUPPETEER_SKIP_DOWNLOAD="true" +export NEXT_TELEMETRY_DISABLED=1 +export CI="true" +cd /opt/hoarder/apps/web && $STD pnpm install --frozen-lockfile +cd /opt/hoarder/apps/workers && $STD pnpm install --frozen-lockfile +cd /opt/hoarder/apps/web && $STD pnpm exec next build --experimental-build-mode compile +cp -r /opt/hoarder/apps/web/.next/standalone/apps/web/server.js /opt/hoarder/apps/web + +HOARDER_SECRET=$(openssl rand -base64 36 | cut -c1-24) + +cat </opt/hoarder/.env +SERVER_VERSION=$RELEASE +NEXTAUTH_SECRET="$HOARDER_SECRET" +NEXTAUTH_URL="http://localhost:3000" +DATA_DIR="/opt/hoarder_data" +MEILI_ADDR="http://127.0.0.1:7700" +MEILI_MASTER_KEY="$MASTER_KEY" +BROWSER_WEB_URL="http://127.0.0.1:9222" +#CRAWLER_FULL_PAGE_SCREENSHOT=true +#CRAWLER_FULL_PAGE_ARCHIVE=true +#CRAWLER_VIDEO_DOWNLOAD=true +EOF +echo "${RELEASE}" >"/opt/Hoarder_version.txt" +msg_ok "Installed Hoarder" + +msg_info "Running Database Migration" +cd /opt/hoarder/packages/db +pnpm migrate +msg_ok "Database Migration Completed" + +msg_info "Setting up Services" +# Meilisearch Service +cat </etc/systemd/system/meilisearch.service +[Unit] +Description=Meilisearch +After=network.target + +[Service] +ExecStart=/usr/bin/meilisearch --config-file-path /etc/meilisearch.toml +Restart=always + +[Install] +WantedBy=multi-user.target +EOF + +# Hoarder Web Service +cat </etc/systemd/system/hoarder-web.service +[Unit] +Description=Hoarder Web +Wants=network.target hoarder-workers.service meilisearch.service +After=network.target hoarder-workers.service meilisearch.service + +[Service] +ExecStart=pnpm start +WorkingDirectory=/opt/hoarder/apps/web +EnvironmentFile=/opt/hoarder/.env +Restart=always + +[Install] +WantedBy=multi-user.target +EOF + +# Hoarder Browser Service +cat </etc/systemd/system/hoarder-browser.service +[Unit] +Description=Hoarder Headless Browser +After=network.target + +[Service] +User=root +ExecStart=/usr/bin/chromium --headless --no-sandbox --disable-gpu --disable-dev-shm-usage --remote-debugging-address=127.0.0.1 --remote-debugging-port=9222 --hide-scrollbars +Restart=always + +[Install] +WantedBy=multi-user.target +EOF + +# Hoarder Workers Service +cat </etc/systemd/system/hoarder-workers.service +[Unit] +Description=Hoarder Workers +Wants=network.target hoarder-browser.service +After=network.target hoarder-browser.service + +[Service] +ExecStart=pnpm start:prod +WorkingDirectory=/opt/hoarder/apps/workers +EnvironmentFile=/opt/hoarder/.env +Restart=always + +[Install] +WantedBy=multi-user.target +EOF + +systemctl enable --now meilisearch.service hoarder-web.service hoarder-browser.service hoarder-workers.service +msg_ok "Set up Services" + +msg_info "Cleaning up" +rm -rf /tmp/meilisearch.deb +$STD apt-get autoremove -y +$STD apt-get autoclean -y +msg_ok "Cleaned"