UpdateAuthelia.sh

From FlowerHouseWiki
#!/bin/bash

# Variables
name="Authelia"
repo="authelia/authelia"
architecture="amd64"

binary_path="/usr/bin"
binary_name="authelia"

# ===== VERSION CHECKING, CUSTOMIZE VARIBLES FOR IT =====

# Get current version
current=$($binary_path/$binary_name --version)

# Retain everything after last space
current=${current##* }

# Get latest release tag
latest=$(curl -sL https://api.github.com/repos/$repo/releases/latest | jq -r ".tag_name")

# Check if new version available
if (("${current//[!0-9]/}" == "${latest//[!0-9]/}")); then
	echo -e "-------------------------------------------------------------------------------------------"
	echo -e "- Installed ${current} is up to date"
	echo -e "-------------------------------------------------------------------------------------------"
	exit 0
fi

# Check if repo is deprecated
if (("${current//[!0-9]/}" > "${latest//[!0-9]/}")); then
	echo -e "-------------------------------------------------------------------------------------------"
	echo -e "- Installed ${current} is newer than available version ${latest}, repository deprecated?"
	echo -e "-------------------------------------------------------------------------------------------"
	exit 0
fi

# Write information
echo -e "-------------------------------------------------------------------------------------------"
echo -e "- Update ${name} ${current} to ${latest}?"
echo -e "-------------------------------------------------------------------------------------------"

echo -e -n "Continue? [y/N]"
echo ""
read -n 1 c

if [ "${c}" != "y" ]; then
	exit 0
fi

# ===== INSTALLATION PART, CUSTOMIZE FOR EACH SOFTWARE =====
# Download files
wget https://github.com/authelia/authelia/releases/download/${latest}/authelia_${latest}_${architecture}.deb || exit 1

# Install software
apt install ./authelia_${latest}_${architecture}.deb || exit 1

# Remove old files
rm authelia_${latest}_${architecture}.deb || exit 1

# ===== FINISH INSTALLATION SCRIPT ====
echo -e "-------------------------------------------------------------------------------------------"
echo -e "- Update to ${latest} completed!"
echo -e "-------------------------------------------------------------------------------------------"