From cf1191bdc347f47b90fa443997212febcf3afb60 Mon Sep 17 00:00:00 2001 From: Julien Oculi Date: Thu, 30 May 2024 13:10:20 +0200 Subject: [PATCH] feat: prevent reinstall and upragde if available --- caddy/_install.sh | 17 +++++++++------- forgejo/_install.sh | 49 ++++++++++++++++++++++++--------------------- website/_install.sh | 28 ++++++++++++++++---------- 3 files changed, 53 insertions(+), 41 deletions(-) diff --git a/caddy/_install.sh b/caddy/_install.sh index 3c334d3..e3c38f6 100644 --- a/caddy/_install.sh +++ b/caddy/_install.sh @@ -1,9 +1,12 @@ -# Install prerequistes -nala install -y debian-keyring debian-archive-keyring apt-transport-https curl +# Check if already installed +if [[ $(which caddy) != "/usr/bin/caddy" ]]; then + # Install prerequistes + nala install -y debian-keyring debian-archive-keyring apt-transport-https curl + + # Install sources and keys + curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg + curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list +fi -# Install sources and keys -curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg -curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list - -# Install caddy +# Install or upgrade caddy nala install -y caddy diff --git a/forgejo/_install.sh b/forgejo/_install.sh index a6c53e4..66c91c8 100644 --- a/forgejo/_install.sh +++ b/forgejo/_install.sh @@ -1,28 +1,31 @@ # Get latest forgejo tag -LATEST=curl -fsS https://codeberg.org/forgejo/forgejo/releases/latest | grep -o "[0-9].[0-9].[0-9]" +LATEST=curl -fsS https://codeberg.org/forgejo/forgejo/releases/latest | grep -o "[0-9].[0-9].[0-9]" | head -1 -# Download forgejo -wget "https://codeberg.org/forgejo/forgejo/releases/download/$LATEST/forgejo-$LATEST-linux-amd64" -chmod +x "forgejo-$LATEST-linux-amd64" - -# Check GPG Keys -gpg --keyserver keys.openpgp.org --recv EB114F5E6C0DC2BCDD183550A4B61A2DC5923710 -wget "https://codeberg.org/forgejo/forgejo/releases/download/v$LATEST/forgejo-$LATEST-linux-amd64.asc" -gpg --verify "forgejo-$LATEST-linux-amd64.asc" "forgejo-$LATEST-linux-amd64" - -# Create group and user -groupadd --system forgejo - -useradd --system \ - --gid forgejo - --create-home \ - --home-dir /var/lib/forgejo \ - --shell /usr/sbin/nologin \ - --comment "Forgejo Git forge" \ - forgejo - -# Setup forgejo directories -mv "forgejo-$LATEST-linux-amd64" /usr/local/bin/forgejo +# Check if already installed +if [[ $(forgejo -v 2> /dev/null | grep -o "[0-9].[0-9].[0-9]" | head -1) != $LATEST ]]; then + # Download forgejo + wget "https://codeberg.org/forgejo/forgejo/releases/download/$LATEST/forgejo-$LATEST-linux-amd64" + chmod +x "forgejo-$LATEST-linux-amd64" + + # Check GPG Keys + gpg --keyserver keys.openpgp.org --recv EB114F5E6C0DC2BCDD183550A4B61A2DC5923710 + wget "https://codeberg.org/forgejo/forgejo/releases/download/v$LATEST/forgejo-$LATEST-linux-amd64.asc" + gpg --verify "forgejo-$LATEST-linux-amd64.asc" "forgejo-$LATEST-linux-amd64" + + # Create group and user + groupadd --system forgejo + + useradd --system \ + --gid forgejo + --create-home \ + --home-dir /var/lib/forgejo \ + --shell /usr/sbin/nologin \ + --comment "Forgejo Git forge" \ + forgejo + + # Setup forgejo directories + mv "forgejo-$LATEST-linux-amd64" /usr/local/bin/forgejo +fi ## Working directory mkdir /var/lib/forgejo diff --git a/website/_install.sh b/website/_install.sh index 1ceacbe..02a473c 100644 --- a/website/_install.sh +++ b/website/_install.sh @@ -1,16 +1,22 @@ -# Install deno -curl -fsSL https://deno.land/install.sh | DENO_INSTALL=/usr/local sh +# Check if already installed +if [[ $(which deno) == "/usr/local/bin/deno" ]]; then + # Upgrade deno + deno upgrade +else + # Install deno + curl -fsSL https://deno.land/install.sh | DENO_INSTALL=/usr/local sh -# Create group and user -groupadd --system deno + # Create group and user + groupadd --system deno -useradd --system \ - --gid deno \ - --create-home \ - --home-dir /var/lib/deno \ - --shell /usr/sbin/nologin \ - --comment "Deno js engine" \ - deno + useradd --system \ + --gid deno \ + --create-home \ + --home-dir /var/lib/deno \ + --shell /usr/sbin/nologin \ + --comment "Deno js engine" \ + deno +fi # Clone website repo mkdir -p /srv/www