You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.1 KiB
Bash
80 lines
2.1 KiB
Bash
5 years ago
|
#!/bin/bash
|
||
|
set -euxo pipefail;
|
||
|
|
||
|
# Constants
|
||
|
readonly ARCHITECTURE={{ binary_architecture | quote }};
|
||
|
readonly BINARIES=( "cleanup" "genkey" "server" );
|
||
|
readonly BIN_DIR={{ installation_directory | quote }};
|
||
|
readonly PREFIX="linx";
|
||
|
readonly SYSTEM_USER={{ system_user | quote }};
|
||
|
|
||
|
# Helper building filenames
|
||
|
function getFile() {
|
||
|
echo "$PREFIX-$2-$1_$ARCHITECTURE";
|
||
|
}
|
||
|
|
||
|
# Helper modifing owners and permissions
|
||
|
function correctPermissions() {
|
||
|
chown --no-dereference "root":"$SYSTEM_USER" "$1";
|
||
|
chmod u=rwx,g=rx,o= "$1";
|
||
|
}
|
||
|
|
||
|
# Check newest version installed
|
||
|
installed="$(
|
||
|
(ls "$BIN_DIR" |
|
||
|
grep --only-matching --perl-regexp '(?<=-)v\d+(\.\d+)*(?=_)' |
|
||
|
sort --version-sort --reverse --unique |
|
||
|
head --lines=1) ||
|
||
|
true
|
||
|
)";
|
||
|
|
||
|
# Check version from upstream
|
||
|
version="$(
|
||
|
curl --silent https://github.com/andreimarcu/linx-server/releases.atom |
|
||
|
grep --only-matching --perl-regexp '(?<=/releases/tag/)v\d+(\.\d+)*(?=")' |
|
||
|
head --lines=1
|
||
|
)";
|
||
|
|
||
|
# Check for missing version numbers
|
||
|
if [[ -z "$installed" ]]; then
|
||
|
installed="v0";
|
||
|
fi
|
||
|
if [[ -z "$version" ]]; then
|
||
|
error "Missing version available";
|
||
|
exit 2;
|
||
|
fi
|
||
|
|
||
|
# Check if version is already installed
|
||
|
if [[ "$installed" = "$version" ]]; then
|
||
|
exit 0;
|
||
|
fi
|
||
|
|
||
|
# Remove version and redownloading (only applies on fallback)
|
||
|
for binary in "${BINARIES[@]}"; do
|
||
|
fileName="$(getFile "$version" "$binary")";
|
||
|
filePath="$BIN_DIR/$fileName";
|
||
|
url="https://github.com/andreimarcu/linx-server/releases/download/$version/$fileName";
|
||
|
rm --force "$filePath";
|
||
|
wget --quiet --output-document="$filePath" "$url";
|
||
|
correctPermissions "$filePath";
|
||
|
done
|
||
|
|
||
|
# Relink new binaries
|
||
|
for binary in "${BINARIES[@]}"; do
|
||
|
toLinkPath="$BIN_DIR/$(getFile "$version" "$binary")";
|
||
|
linkPath="$BIN_DIR/$PREFIX-$binary";
|
||
|
ln --force --symbolic "$toLinkPath" "$linkPath";
|
||
|
correctPermissions "$linkPath";
|
||
|
done
|
||
|
|
||
|
# Remove old version
|
||
|
for binary in "${BINARIES[@]}"; do
|
||
|
fileName="$(getFile "$installed" "$binary")";
|
||
|
rm --force "$BIN_DIR/$fileName";
|
||
|
done
|
||
|
|
||
|
# Restart service
|
||
|
if systemctl is-enabled {{ service_name | quote }}; then
|
||
|
systemctl restart {{ service_name | quote }};
|
||
|
fi
|