Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install bash scripts improvements #413

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 45 additions & 28 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
#!/bin/bash
# Check if the script is running as root
# Initialize the elevated variable to ensure we can run commands as root
if [ "$EUID" -eq 0 ]; then
elevated="bash -c" # No need for sudo or su if running as root
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elevated=""

Setting it to the empty string means it just goes away - setting it to bash means a whole new shell.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you tested it? thanks

elif command -v sudo &> /dev/null; then
elevated="sudo bash -c" # Use sudo if available
elif command -v su &> /dev/null; then
elevated="su root -c" # Use su if sudo isn't available
else
echo "Error: Neither sudo nor su is available. Unable to run command as root."
exit 1
fi
set -e -o pipefail
shopt -s nocaseglob

OUT_FILE=/usr/local/bin/autorestic
TMP_FILE=/tmp/autorestic

# Type
NATIVE_OS=$(uname | tr '[:upper:]' '[:lower:]')
if [[ $NATIVE_OS == *"linux"* ]]; then
OS=linux
elif [[ $NATIVE_OS == *"darwin"* ]]; then
OS=darwin
elif [[ $NATIVE_OS == *"freebsd"* ]]; then
OS=freebsd
else
echo "Could not determine OS automatically, please check the release page manually: https://github.com/cupcakearmy/autorestic/releases"
case $NATIVE_OS in
*linux*)
OS=linux;;
*darwin*)
OS=darwin;;
*freebsd*)
OS=freebsd;;
*)
echo "Could not determine OS automatically, please check the release page"\
"manually: https://github.com/cupcakearmy/autorestic/releases"
exit 1
fi
;;
esac
echo $OS

NATIVE_ARCH=$(uname -m | tr '[:upper:]' '[:lower:]')
if [[ $NATIVE_ARCH == *"x86_64"* || $NATIVE_ARCH == *"amd64"* ]]; then
ARCH=amd64
elif [[ $NATIVE_ARCH == *"arm64"* || $NATIVE_ARCH == *"aarch64"* ]]; then
ARCH=arm64
elif [[ $NATIVE_ARCH == *"x86"* ]]; then
ARCH=386
elif [[ $NATIVE_ARCH == *"armv7"* ]]; then
ARCH=arm
else
echo "Could not determine Architecure automatically, please check the release page manually: https://github.com/cupcakearmy/autorestic/releases"
exit 1
fi
case $NATIVE_ARCH in
*x86_64*|*amd64*) ARCH=amd64 ;;
*arm64*|*aarch64*) ARCH=arm64 ;;
*x86*) ARCH=386 ;;
*armv7*) ARCH=arm ;;
*)
echo "Could not determine Architecure automatically, please check the"\
"release page manually: https://github.com/cupcakearmy/autorestic/releases"
exit 1
;;
esac
echo $ARCH

if ! command -v bzip2 &>/dev/null; then
Expand All @@ -40,11 +55,13 @@ fi

wget -qO - https://api.github.com/repos/cupcakearmy/autorestic/releases/latest \
| grep "browser_download_url.*_${OS}_${ARCH}" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -O "${OUT_FILE}.bz2" -i -
bzip2 -fd "${OUT_FILE}.bz2"
chmod +x ${OUT_FILE}
| xargs | cut -d ' ' -f 2 \
| wget -O "${TMP_FILE}.bz2" -i -
$elevated "
bzip2 -cd ${TMP_FILE}.bz2 > ${OUT_FILE}
chmod +x ${OUT_FILE}
autorestic install
"
rm ${TMP_FILE}.bz2

autorestic install
echo "Successfully installed autorestic"
echo "Successfully installed autorestic under ${OUT_FILE}"