Skip to content

Commit

Permalink
Merge pull request #1194 from HudsonOnHere/feat/install-script-mac-su…
Browse files Browse the repository at this point in the history
…pport

Install script fixes for better Mac support
  • Loading branch information
sundowndev committed Mar 3, 2023
2 parents 9ea1426 + 78c4478 commit 7d15bd6
Showing 1 changed file with 248 additions and 27 deletions.
275 changes: 248 additions & 27 deletions support/scripts/install
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,38 +1,259 @@
#!/bin/bash
#! /bin/bash

# Bash installation script for UNIX systems only
# Use it : curl -sSL https://raw.githubusercontent.com/sundowndev/phoneinfoga/master/support/scripts/install | bash

os="$(uname -s)_$(uname -m)"
OS="$(uname -s)_$(uname -m)"
PHONEINFOGA_VERSION=
AUTOMATIC=
SKIP_CHECKSUM=1
CURL_INSTALLED=false
WGET_INSTALLED=false

if [ $os == "Linux_x86_64" ] || [ $os == "Linux_armv6" ] || [ $os == "Darwin_x86_64" ] || [ $os == "Darwin_arm64" ] || [ $os == "Linux_arm64" ] || [ $os == "Linux_i386" ]; then
echo "Installing PhoneInfoga"
phoneinfoga_version=$(curl -s https://api.github.com/repos/sundowndev/phoneinfoga/releases/latest | grep tag_name | cut -d '"' -f 4)
echo "Found version $phoneinfoga_version"

echo "Downloading version $phoneinfoga_version..."
wget "https://github.com/sundowndev/phoneinfoga/releases/download/$phoneinfoga_version/phoneinfoga_$os.tar.gz"
choose_wget_or_curl() {

echo "Verifying checksum..."
curl -sSL "https://github.com/sundowndev/phoneinfoga/releases/download/$phoneinfoga_version/phoneinfoga_checksums.txt" -o phoneinfoga_SHA256SUMS
sha256sum --ignore-missing -c phoneinfoga_SHA256SUMS
[ $? -eq 0 ] || exit 1
which curl > /dev/null
[ $? -eq 1 ] || CURL_INSTALLED=true

tar xfv "phoneinfoga_$os.tar.gz"
[ $? -eq 0 ] || exit 1

# Clear downloaded assets
rm phoneinfoga_$os.tar.gz
rm phoneinfoga_SHA256SUMS
if $CURL_INSTALLED; then
PHONEINFOGA_VERSION=$(curl -s https://api.github.com/repos/sundowndev/phoneinfoga/releases/latest | grep tag_name | cut -d '"' -f 4)
return
fi

echo "Installation completed successfully."
echo "Check the version : ./phoneinfoga version"
echo "You can now install the program globally : sudo mv ./phoneinfoga /usr/bin/phoneinfoga"
else
echo "Your OS/Arch is not supported."
echo "Read more at https://sundowndev.github.io/phoneinfoga/install/"
exit 1
fi
which wget > /dev/null
[ $? -eq 1 ] || WGET_INSTALLED=true

exit 0
if $WGET_INSTALLED; then
PHONEINFOGA_VERSION=$(wget -q --output-document - https://api.github.com/repos/sundowndev/phoneinfoga/releases/latest | grep tag_name | cut -d '"' -f 4)
return
fi

echo "Error: You need to have either curl or wget installed to be able to use this script"
exit 1

}


usage() {

echo "PhoneInfoga Installer for version $PHONEINFOGA_VERSION"
echo
echo "DESCRIPTION: An installer script for downloading the latest release of PhoneInfoga. Without any arguments, $0 will detect your operating system and attempt to download the corresponding version of PhoneInfoga. Please submit an issue on GitHub if you encounter issues with this script." | fold -s
echo
echo "USAGE: $0 [flag...] (-h|-m|-s)"
echo
echo " -h | --help Print this message and exit"
echo
echo " -m | --manual Manually select version to download."
echo " Useful when $0 is unable to detect"
echo " your OS automatically"
echo
echo " -s | --skip-checksum [Not Reccomended] Skip checksum validation"
echo " Only use this option if $0"
echo " is failing due to missing software."
echo
}


validate_OS_type() {

if [[ -z "${OS}" ]]; then
echo "ERROR: Unable to determine your system type."
exit 1
fi
}


validate_supported_OS() {

SUPPORTED_OS_TYPES=(
"Darwin_arm64"
"Darwin_x86_64"
"Linux_arm64"
"Linux_armv6"
"Linux_armv7"
"Linux_i386"
"Linux_x86_64"
"Windows_arm64"
"Windows_armv6"
"Windows_armv7"
"Windows_i386"
"Windows_x86_64"
)

for OS_TYPE in "${SUPPORTED_OS_TYPES[@]}"; do
if [[ "$OS_TYPE" == "$OS" ]]; then
AUTOMATIC=0
return
fi
done

echo "Error: $OS is not supported, installation will attempt to proceed manually."
echo
echo "Please check the releases page for a list of supported systems."
echo "https://github.com/sundowndev/phoneinfoga/releases"
echo
echo "Read more at https://sundowndev.github.io/phoneinfoga/install/"
echo
AUTOMATIC=1

}


validate_checksum() {

echo "Validating checksum ..."
if $CURL_INSTALLED; then
curl --progress-bar -LOC - "https://github.com/sundowndev/phoneinfoga/releases/download/$PHONEINFOGA_VERSION/phoneinfoga_checksums.txt"
elif $WGET_INSTALLED; then
wget --quiet --show-progress "https://github.com/sundowndev/phoneinfoga/releases/download/$PHONEINFOGA_VERSION/phoneinfoga_checksums.txt"
fi

local SHA256SUM_INSTALLED=false
which sha256sum > /dev/null
[ $? -eq 1 ] || SHA256SUM_INSTALLED=true

if $SHA256SUM_INSTALLED; then
sha256sum --ignore-missing -c phoneinfoga_checksums.txt
[ $? -eq 0 ] || exit 1
elif ! $SHA256SUM_INSTALLED; then
shasum --ignore-missing -c phoneinfoga_checksums.txt
[ $? -eq 0 ] || exit 1
fi

rm phoneinfoga_checksums.txt
}


download_latest_release() {

echo "Downloading PhoneInfoga Version $PHONEINFOGA_VERSION for $OS"

if $CURL_INSTALLED; then
curl --progress-bar -LOC - "https://github.com/sundowndev/phoneinfoga/releases/download/$PHONEINFOGA_VERSION/phoneinfoga_$OS.tar.gz"

elif $WGET_INSTALLED; then
wget --quiet --show-progress "https://github.com/sundowndev/phoneinfoga/releases/download/$PHONEINFOGA_VERSION/phoneinfoga_$OS.tar.gz"

fi
}


manual_download_latest_release() {

if $CURL_INSTALLED; then
ASSETS=$(curl -s https://api.github.com/repos/sundowndev/phoneinfoga/releases/latest | jq --raw-output '.assets[] | .name' | grep --color=never .tar.gz)
elif $WGET_INSTALLED; then
ASSETS=$(wget -q --output-document - https://api.github.com/repos/sundowndev/phoneinfoga/releases/latest | jq --raw-output '.assets[] | .name' | grep --color=never .tar.gz)
fi

echo "Please select a version of PhoneInfoga to download."
PS3="Enter a number: "
select OPT in $ASSETS; do
case $OPT in

'')
echo "Error: Invalid option, please enter a number from the list."
;;

*)
echo "Downloading $OPT version $PHONEINFOGA_VERSION"
echo "https://github.com/sundowndev/phoneinfoga/releases/download/$PHONEINFOGA_VERSION/$OPT"

if $CURL_INSTALLED; then
curl --progress-bar -LOC - "https://github.com/sundowndev/phoneinfoga/releases/download/$PHONEINFOGA_VERSION/$OPT"

elif $WGET_INSTALLED; then
wget --quiet --show-progress "https://github.com/sundowndev/phoneinfoga/releases/download/$PHONEINFOGA_VERSION/$OPT"

fi

break
;;
esac
done
}


unpack_and_cleanup() {

local FILE
FILE=$(find . -name "phoneinfoga_*.tar.gz")

tar -xzf $FILE
[ $? -eq 0 ] || exit 1

echo "Cleaning up ..."
rm $FILE
}


main() {

validate_OS_type
validate_supported_OS
choose_wget_or_curl

if [[ -z "$1" ]]; then
echo
else
while [[ "$1" == -* ]]; do
case "$1" in

-h | --help)
usage
exit 0
;;

-m | --manual)
AUTOMATIC=1
;;

-s | --skip-checksum)
SKIP_CHECKSUM=0
;;

*)
echo
echo "ERROR: Unrecognized command '$1', run '$0 --help' for help."
exit 1
;;

esac
shift
done
fi

if [[ $AUTOMATIC == 0 ]]; then
download_latest_release
elif [[ $AUTOMATIC == 1 ]]; then
manual_download_latest_release
else
echo "something bad happened"
exit 1
fi

if [[ $SKIP_CHECKSUM == 1 ]]; then
validate_checksum
elif [[ $SKIP_CHECKSUM == 0 ]]; then
echo
echo "WARNING: Skipping checksum validation. Please be sure to verify your download manually. You can find the checksum for your software version here:" | fold -s
echo
echo "https://github.com/sundowndev/phoneinfoga/releases/download/$PHONEINFOGA_VERSION/phoneinfoga_checksums.txt"
fi

unpack_and_cleanup

echo
echo "Installation completed successfully."
echo "To check the version installed: ./phoneinfoga version"
echo
echo "Add it to your path by running"
echo "'sudo mv ./phoneinfoga /usr/local/bin/phoneinfoga'"

exit 0
}


main "${@}"

0 comments on commit 7d15bd6

Please sign in to comment.