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 script fixes for better Mac support #1194

Merged
270 changes: 243 additions & 27 deletions support/scripts/install
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,38 +1,254 @@
#!/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"
)

if [[ "${SUPPORTED_OS_TYPES[*]}" =~ "${OS}" ]]; then
AUTOMATIC=0
else
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
fi
}


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: "
sundowndev marked this conversation as resolved.
Show resolved Hide resolved
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=$(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 "${@}"