From 9072459066315236b6c42f83880153dc1763ffff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Slavi=C5=A1a=20Are=C5=BEina?= <58952836+tremor021@users.noreply.github.com> Date: Sat, 5 Jul 2025 18:03:36 +0200 Subject: [PATCH] Refactor (#5724) --- ct/cryptpad.sh | 78 ++++++++++++++++++------------------- install/cryptpad-install.sh | 13 ++----- 2 files changed, 41 insertions(+), 50 deletions(-) diff --git a/ct/cryptpad.sh b/ct/cryptpad.sh index ebb21fa58..466af1c0c 100644 --- a/ct/cryptpad.sh +++ b/ct/cryptpad.sh @@ -20,48 +20,46 @@ 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/cryptpad" ]]; then - msg_error "No ${APP} Installation Found!" - exit - fi - RELEASE=$(curl -fsSL https://api.github.com/repos/cryptpad/cryptpad/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') - if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then - msg_info "Stopping $APP" - systemctl stop cryptpad - msg_ok "Stopped $APP" - - msg_info "Updating $APP to ${RELEASE}" - temp_dir=$(mktemp -d) - cp -f /opt/cryptpad/config/config.js /opt/config.js - curl -fsSL "https://github.com/cryptpad/cryptpad/archive/refs/tags/${RELEASE}.tar.gz" -o "$temp_dir/cryptpad-${RELEASE}.tar.gz" - cd "$temp_dir" - tar zxf "cryptpad-${RELEASE}.tar.gz" - cp -rf "cryptpad-${RELEASE}"/* /opt/cryptpad - cd /opt/cryptpad - $STD npm ci - $STD npm run install:components - $STD npm run build - cp -f /opt/config.js /opt/cryptpad/config/config.js - echo "${RELEASE}" >/opt/${APP}_version.txt - msg_ok "Updated $APP to ${RELEASE}" - - msg_info "Cleaning Up" - rm -rf $temp_dir - msg_ok "Cleanup Completed" - - msg_info "Starting $APP" - systemctl start cryptpad - msg_ok "Started $APP" - - msg_ok "Update Successful" - else - msg_ok "No update required. ${APP} is already at ${RELEASE}" - fi + if [[ ! -d "/opt/cryptpad" ]]; then + msg_error "No ${APP} Installation Found!" exit + fi + RELEASE=$(curl -fsSL https://api.github.com/repos/cryptpad/cryptpad/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') + if [[ "${RELEASE}" != "$(cat ~/.cryptpad 2>/dev/null)" ]] || [[ ! -f ~/.cryptpad ]]; then + msg_info "Stopping $APP" + systemctl stop cryptpad + msg_ok "Stopped $APP" + + msg_info "Backing up configuration" + [ -f /opt/cryptpad/config/config.js ] && mv /opt/cryptpad/config/config.js /opt/ + msg_ok "Backed up configuration" + + fetch_and_deploy_gh_release "cryptpad" "cryptpad/cryptpad" + + msg_info "Updating $APP to ${RELEASE}" + cd /opt/cryptpad + $STD npm ci + $STD npm run install:components + $STD npm run build + msg_ok "Updated $APP to ${RELEASE}" + + msg_info "Restoring configuration" + mv /opt/config.js /opt/cryptpad/config/ + msg_ok "Configuration restored" + + msg_info "Starting $APP" + systemctl start cryptpad + msg_ok "Started $APP" + + msg_ok "Update Successful" + else + msg_ok "No update required. ${APP} is already at ${RELEASE}" + fi + exit } start diff --git a/install/cryptpad-install.sh b/install/cryptpad-install.sh index 044c8f3ee..d7615a71b 100644 --- a/install/cryptpad-install.sh +++ b/install/cryptpad-install.sh @@ -14,20 +14,15 @@ network_check update_os msg_info "Installing Dependencies" -$STD apt-get install -y \ - git +$STD apt-get install -y git msg_ok "Installed Dependencies" NODE_VERSION="22" setup_nodejs -read -p "${TAB3}Install OnlyOffice components instead of CKEditor? (Y/N): " onlyoffice +read -rp "${TAB3}Install OnlyOffice components instead of CKEditor? (Y/N): " onlyoffice +fetch_and_deploy_gh_release "cryptpad" "cryptpad/cryptpad" msg_info "Setup ${APPLICATION}" -temp_file=$(mktemp) -RELEASE=$(curl -fsSL https://api.github.com/repos/cryptpad/cryptpad/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') -curl -fsSL "https://github.com/cryptpad/cryptpad/archive/refs/tags/${RELEASE}.tar.gz" -o "$temp_file" -tar zxf $temp_file -mv cryptpad-$RELEASE /opt/cryptpad cd /opt/cryptpad $STD npm ci $STD npm run install:components @@ -39,7 +34,6 @@ sed -i "80s#//httpAddress: 'localhost'#httpAddress: '0.0.0.0'#g" /opt/cryptpad/c if [[ "$onlyoffice" =~ ^[Yy]$ ]]; then $STD bash -c "./install-onlyoffice.sh --accept-license" fi -echo "${RELEASE}" >/opt/${APPLICATION}_version.txt msg_ok "Setup ${APPLICATION}" msg_info "Creating Service" @@ -69,7 +63,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"