From a68f380d6b2ecb20ab441ad164cd691867bfe45a Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:34:07 +0100 Subject: [PATCH] [Bug] | [Change]: Homarr (+Script harmonized) (#124) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Bug] | [Change]: Homarr (+Script harmonized) * Update ct/homarr.sh Co-authored-by: Håvard Gjøby Thom <34199185+havardthom@users.noreply.github.com> * add ttekc Signed-off-by: CanbiZ <47820557+MickLesk@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Håvard Gjøby Thom <34199185+havardthom@users.noreply.github.com> * fix echo Signed-off-by: CanbiZ <47820557+MickLesk@users.noreply.github.com> * Final Fix Signed-off-by: CanbiZ <47820557+MickLesk@users.noreply.github.com> * remove cd /opt Signed-off-by: CanbiZ <47820557+MickLesk@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Håvard Gjøby Thom <34199185+havardthom@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Håvard Gjøby Thom <34199185+havardthom@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Håvard Gjøby Thom <34199185+havardthom@users.noreply.github.com> --------- Signed-off-by: CanbiZ <47820557+MickLesk@users.noreply.github.com> Co-authored-by: Håvard Gjøby Thom <34199185+havardthom@users.noreply.github.com> --- ct/homarr.sh | 50 +++++++++++++++++++++++++++++---------- install/homarr-install.sh | 11 ++++++--- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/ct/homarr.sh b/ct/homarr.sh index dcb55148b..aa1fedd93 100644 --- a/ct/homarr.sh +++ b/ct/homarr.sh @@ -2,6 +2,7 @@ source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) # Copyright (c) 2021-2024 tteck # Author: tteck (tteckster) +# Co-Author: MickLesk (Canbiz) # License: MIT # https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE @@ -54,20 +55,43 @@ function default_settings() { function update_script() { header_info -if [[ ! -d /opt/homarr ]]; then msg_error "No ${APP} Installation Found!"; exit; fi -msg_info "Updating $APP (Patience)" -systemctl stop homarr -cd /opt/homarr -if ! git pull; then - echo "Already up to date." - systemctl start homarr - echo "No update required." - exit +if [[ ! -d /opt/homarr]]; then msg_error "No ${APP} Installation Found!"; exit; fi +if (( $(df /boot | awk 'NR==2{gsub("%","",$5); print $5}') > 80 )); then + read -r -p "Warning: Storage is dangerously low, continue anyway? " prompt + [[ ${prompt,,} =~ ^(y|yes)$ ]] || exit +fi +RELEASE=$(curl -s https://api.github.com/repos/ajnart/homarr/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') +if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then + msg_info "Stopping Services" + systemctl stop homarr + msg_ok "Services Stopped" + + msg_info "Updating ${APP} to ${RELEASE}" + cp /opt/homarr/.env /opt/.env + cp -a /opt/homarr/data /opt/ + rm -rf /opt/homarr + wget -q "https://github.com/ajnart/homarr/archive/refs/tags/v${RELEASE}.zip" + unzip -q v${RELEASE}.zip + mv homarr-${RELEASE} /opt/homarr + mv /opt/.env /opt/homarr/.env + mv /opt/data /opt/homarr/ + yarn install &>/dev/null + yarn build &>/dev/null + yarn db:migrate &>/dev/null + echo "${RELEASE}" >/opt/${APP}_version.txt + msg_ok "Updated ${APP}" + + msg_info "Starting Services" + systemctl start homarr + msg_ok "Started Services" + + msg_info "Cleaning Up" + rm -rf v${RELEASE}.zip + msg_ok "Cleaned" + msg_ok "Updated Successfully" +else + msg_ok "No update required. ${APP} is already at ${RELEASE}" fi -yarn install -yarn build -systemctl start homarr -msg_ok "Updated $APP" exit } diff --git a/install/homarr-install.sh b/install/homarr-install.sh index 791c37a77..b0561b993 100644 --- a/install/homarr-install.sh +++ b/install/homarr-install.sh @@ -2,8 +2,10 @@ # Copyright (c) 2021-2024 tteck # Author: tteck (tteckster) +# Co-Author: MickLesk (Canbiz) # License: MIT # https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/ajnart/homarr source /dev/stdin <<< "$FUNCTIONS_FILE_PATH" color @@ -17,7 +19,6 @@ msg_info "Installing Dependencies" $STD apt-get install -y curl $STD apt-get install -y sudo $STD apt-get install -y mc -$STD apt-get install -y git $STD apt-get install -y ca-certificates $STD apt-get install -y gnupg msg_ok "Installed Dependencies" @@ -31,12 +32,14 @@ msg_ok "Set up Node.js Repository" msg_info "Installing Node.js/Yarn" $STD apt-get update $STD apt-get install -y nodejs -$STD npm install -g npm@latest $STD npm install -g yarn msg_ok "Installed Node.js/Yarn" msg_info "Installing Homarr (Patience)" -$STD git clone -b dev https://github.com/ajnart/homarr.git /opt/homarr +RELEASE=$(curl -s https://api.github.com/repos/ajnart/homarr/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') +wget -q "https://github.com/ajnart/homarr/archive/refs/tags/v${RELEASE}.zip" +unzip -q v${RELEASE}.zip +mv homarr-${RELEASE} /opt/homarr cat </opt/homarr/.env DATABASE_URL="file:./database/db.sqlite" NEXTAUTH_URL="http://localhost:3000" @@ -48,6 +51,7 @@ cd /opt/homarr $STD yarn install $STD yarn build $STD yarn db:migrate +echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt" msg_ok "Installed Homarr" msg_info "Creating Service" @@ -72,6 +76,7 @@ motd_ssh customize msg_info "Cleaning up" +rm -rf v${RELEASE}.zip $STD apt-get -y autoremove $STD apt-get -y autoclean msg_ok "Cleaned"