UpdateAuthelia.sh
From FlowerHouseWiki
#!/bin/bash
# Variables
name="Authelia"
repo="authelia/authelia"
architecture="linux-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, 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/v4.35.2/authelia-${latest}-${architecture}.tar.gz || exit 1
# Untar files
tar -xvf authelia-${latest}-${architecture}.tar.gz || exit 1
# Stop software
systemctl stop authelia || exit 1
# Move files
mv authelia-linux-amd64 /usr/bin/authelia || exit 1
mv config.template.yml /etc/authelia/config.template.yml || exit 1
mv authelia.service /etc/systemd/system/ || exit 1
# Set permission
chmod 775 /usr/bin/authelia || exit 1
chown root:root /usr/bin/authelia || exit 1
# Update systemctl daemon
systemctl daemon-reload || exit 1
# Start authelia
systemctl start authelia || exit 1
# Remove old files
rm authelia-${latest}-${architecture}.tar.gz || exit 1
# ===== FINISH INSTALLATION SCRIPT ====
echo -e "-------------------------------------------------------------------------------------------"
echo -e "- Update to ${latest} completed!"
echo -e "-------------------------------------------------------------------------------------------"