mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2024-12-23 00:36:25 +00:00
use sudo if ran as user, use case instead of if
This commit is contained in:
parent
48fa20b482
commit
14d8f7cb44
57
install.sh
57
install.sh
@ -1,36 +1,41 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# Check if the script is running as root
|
||||||
|
[ "$EUID" -eq 0 ] || exec sudo bash "$0" "$@"
|
||||||
set -e -o pipefail
|
set -e -o pipefail
|
||||||
shopt -s nocaseglob
|
shopt -s nocaseglob
|
||||||
|
|
||||||
OUT_FILE=/usr/local/bin/autorestic
|
OUT_FILE=/usr/local/bin/autorestic
|
||||||
|
TMP_FILE=/tmp/autorestic
|
||||||
|
|
||||||
# Type
|
# Type
|
||||||
NATIVE_OS=$(uname | tr '[:upper:]' '[:lower:]')
|
NATIVE_OS=$(uname | tr '[:upper:]' '[:lower:]')
|
||||||
if [[ $NATIVE_OS == *"linux"* ]]; then
|
case $NATIVE_OS in
|
||||||
OS=linux
|
*linux*)
|
||||||
elif [[ $NATIVE_OS == *"darwin"* ]]; then
|
OS=linux;;
|
||||||
OS=darwin
|
*darwin*)
|
||||||
elif [[ $NATIVE_OS == *"freebsd"* ]]; then
|
OS=darwin;;
|
||||||
OS=freebsd
|
*freebsd*)
|
||||||
else
|
OS=freebsd;;
|
||||||
echo "Could not determine OS automatically, please check the release page manually: https://github.com/cupcakearmy/autorestic/releases"
|
*)
|
||||||
|
echo "Could not determine OS automatically, please check the release page"\
|
||||||
|
"manually: https://github.com/cupcakearmy/autorestic/releases"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
echo $OS
|
echo $OS
|
||||||
|
|
||||||
NATIVE_ARCH=$(uname -m | tr '[:upper:]' '[:lower:]')
|
NATIVE_ARCH=$(uname -m | tr '[:upper:]' '[:lower:]')
|
||||||
if [[ $NATIVE_ARCH == *"x86_64"* || $NATIVE_ARCH == *"amd64"* ]]; then
|
case $NATIVE_ARCH in
|
||||||
ARCH=amd64
|
*x86_64*|*amd64*) ARCH=amd64 ;;
|
||||||
elif [[ $NATIVE_ARCH == *"arm64"* || $NATIVE_ARCH == *"aarch64"* ]]; then
|
*arm64*|*aarch64*) ARCH=arm64 ;;
|
||||||
ARCH=arm64
|
*x86*) ARCH=386 ;;
|
||||||
elif [[ $NATIVE_ARCH == *"x86"* ]]; then
|
*armv7*) ARCH=arm ;;
|
||||||
ARCH=386
|
*)
|
||||||
elif [[ $NATIVE_ARCH == *"armv7"* ]]; then
|
echo "Could not determine Architecure automatically, please check the"\
|
||||||
ARCH=arm
|
"release page manually: https://github.com/cupcakearmy/autorestic/releases"
|
||||||
else
|
exit 1
|
||||||
echo "Could not determine Architecure automatically, please check the release page manually: https://github.com/cupcakearmy/autorestic/releases"
|
;;
|
||||||
exit 1
|
esac
|
||||||
fi
|
|
||||||
echo $ARCH
|
echo $ARCH
|
||||||
|
|
||||||
if ! command -v bzip2 &>/dev/null; then
|
if ! command -v bzip2 &>/dev/null; then
|
||||||
@ -40,11 +45,11 @@ fi
|
|||||||
|
|
||||||
wget -qO - https://api.github.com/repos/cupcakearmy/autorestic/releases/latest \
|
wget -qO - https://api.github.com/repos/cupcakearmy/autorestic/releases/latest \
|
||||||
| grep "browser_download_url.*_${OS}_${ARCH}" \
|
| grep "browser_download_url.*_${OS}_${ARCH}" \
|
||||||
| cut -d : -f 2,3 \
|
| xargs | cut -d ' ' -f 2 \
|
||||||
| tr -d \" \
|
| wget -O "${TMP_FILE}.bz2" -i -
|
||||||
| wget -O "${OUT_FILE}.bz2" -i -
|
bzip2 -cd "${TMP_FILE}.bz2" > "${OUT_FILE}"
|
||||||
bzip2 -fd "${OUT_FILE}.bz2"
|
|
||||||
chmod +x ${OUT_FILE}
|
chmod +x ${OUT_FILE}
|
||||||
|
rm "${TMP_FILE}.bz2"
|
||||||
|
|
||||||
autorestic install
|
autorestic install
|
||||||
echo "Successfully installed autorestic"
|
echo "Successfully installed autorestic under ${OUT_FILE}"
|
||||||
|
Loading…
Reference in New Issue
Block a user