# This script will allow you to create an installation script, which will download a release from a GitHub repository,
# and install it on /usr/local/bin, accessible by user's PATH. The release file should include an executable, without any
# subfolders. After tweaking this file, you may now add it to your
# repository at your root as `install.sh` in the master branch. Users may run this script with:
#
# curl -s https://raw.githubusercontent.com/<user>/<repo>/master/install.sh | sh
#
# Custom configuration
github_release_filename="<your release filename>.tar.gz"
github_release_version_tag="v0.0.1"
github_user="<username>"
github_repo="<repository name>"
executable_name="<your executable file inside your compressed package>"
executable_target_folder="/usr/local/bin"
# -----------------------
# Fixed variables.
download_url="https://github.com/$github_user/$github_repo/releases/download/$github_release_version_tag/$github_release_filename"
tmp_file="tmp/$github_release_filename"
executable_path="$executable_target_folder/$executable_name"
# Download the compressed file.
echo "Downloading $github_user/$github_repo $github_release_version_tag from $download_url ..."
curl -L -o $tmp_file $download_url
# Extract its content.
echo "Extracting executable into $executable_target_folder ..."
sudo tar -xvzf $tmp_file -C $executable_target_folder >> /dev/null
# Add executable permissions.
echo "Adding executable permissions to $executable_path ..."
sudo chmod +x $executable_path
# After install content (run help or man).
echo "Done! $github_user/$github_repo is now installed."
printf "\n\n"
$executable_name --help