Skip to content

Instantly share code, notes, and snippets.

@SimoTod
Last active October 13, 2023 12:19
Show Gist options
  • Save SimoTod/d4320ecda8e92e184dd0bf453b983c35 to your computer and use it in GitHub Desktop.
Save SimoTod/d4320ecda8e92e184dd0bf453b983c35 to your computer and use it in GitHub Desktop.
Genny Installer
#!/usr/bin/env bash
expandPath() {
case $1 in
~[+-]*)
local content content_q
printf -v content_q '%q' "${1:2}"
eval "content=${1:0:2}${content_q}"
printf '%s\n' "$content"
;;
~*)
local content content_q
printf -v content_q '%q' "${1:1}"
eval "content=~${content_q}"
printf '%s\n' "$content"
;;
*)
printf '%s\n' "$1"
;;
esac
}
while getopts ":i:t:" opt; do
case $opt in
i) installPath="$OPTARG"
;;
t) token="$OPTARG"
;;
\?) echo "unknown option -$OPTARG" >&2
exit 1
;;
esac
done
echo -e "\x1B[1m\x1B[4mGenny - The Code Generator\x1B[0m"
echo ""
if [ -z $(which git) ]; then
echo -e "\x1B[31mCould not find \x1B[1mgh\x1B[31m in your \$PATH.\x1B[0m"
echo "To install genny you will first need install and authenticate 'gh' tool with personal access token"
echo "Run 'gh auth login' to do this"
exit 1
fi
echo ""
if [ -z $(which git) ]; then
echo -e "\x1B[31mCould not find \x1B[1mgit\x1B[31m in your \$PATH, please install it before continuing\x1B[0m"
exit 1
fi
defaultPath=$HOME/bin
if [[ -z "${installPath}" ]]; then
echo -n "Install location [$defaultPath]: "
read -r installPath
fi;
installPath=$(expandPath $installPath)
installPath=${installPath:-$defaultPath}
if [ ! -d "$installPath" ] ; then
echo -e "\x1B[31m$installPath does not exist, please create it before continuing\x1B[0m"
exit 1
fi
if [ ! -w "$installPath" ] ; then
echo -e "\x1B[31m$installPath is not writable, please ensure you have write permissions, are the owner or have elevated to a user that has permission before continuing\x1B[0m"
exit 1
fi
if ! sed 's/:/\n/g' <<< "$PATH" | grep $installPath > /dev/null 2>&1; then
echo ""
echo -e "$installPath \x1B[31mis not in your \$PATH. Please add it to your PATH for your chosen shell.\x1B[0m"
case $SHELL in
*/zsh)
echo "Follow these instructions for adding a directory to the PATH in zsh"
echo "https://stackoverflow.com/questions/11530090/adding-a-new-entry-to-the-path-variable-in-zsh"
;;
*/bash)
echo "Follow these instructions for adding a directory to the PATH in bash"
echo "https://linuxize.com/post/how-to-add-directory-to-path-in-linux/#adding-a-directory-to-your-path"
;;
*)
# assume something else
echo "Follow these instructions for adding a directory to the PATH in $SHELL"
echo "https://www.google.com/search?q=$SHELL+add+directory+to+path"
esac
exit 1
fi
arch=$(uname -m | tr A-Z a-z )
os=$(uname -s | tr A-Z a-z )
if [ $arch == 'x86_64' ] ; then
arch='amd64'
fi
if [ $arch == 'aarch64' ] ; then
arch='arm64'
fi
osarch="$(echo $os)_$(echo $arch)"
echo "Downloading latest release for $osarch"
rm /tmp/genny-install/*
gh release --repo Gear4music/console-app-genny download --pattern "*$osarch*" -D /tmp/genny-install
echo -e "Extracting genny to $installPath"
tar -xzf /tmp/genny-install/*.tar.gz -C $installPath
echo -e "\nInstallation Complete - run \`genny init\` to setup genny config"
#!/usr/bin/env bash
expandPath() {
case $1 in
~[+-]*)
local content content_q
printf -v content_q '%q' "${1:2}"
eval "content=${1:0:2}${content_q}"
printf '%s\n' "$content"
;;
~*)
local content content_q
printf -v content_q '%q' "${1:1}"
eval "content=~${content_q}"
printf '%s\n' "$content"
;;
*)
printf '%s\n' "$1"
;;
esac
}
while getopts ":i:t:" opt; do
case $opt in
i) installPath="$OPTARG"
;;
t) token="$OPTARG"
;;
\?) echo "unknown option -$OPTARG" >&2
exit 1
;;
esac
done
echo -e "\x1B[1m\x1B[4mGenny - The Code Generator\x1B[0m"
echo ""
if [ -z $(which git) ]; then
echo -e "\x1B[31mCould not find \x1B[1mgh\x1B[31m in your \$PATH.\x1B[0m"
echo "To install genny you will first need install and authenticate 'gh' tool with personal access token"
echo "Run 'gh auth login' to do this"
exit 1
fi
echo ""
if [ -z $(which git) ]; then
echo -e "\x1B[31mCould not find \x1B[1mgit\x1B[31m in your \$PATH, please install it before continuing\x1B[0m"
exit 1
fi
defaultPath=$HOME/bin
if [[ -z "${installPath}" ]]; then
echo -n "Install location [$defaultPath]: "
read -r installPath
fi;
installPath=$(expandPath $installPath)
installPath=${installPath:-$defaultPath}
if [ ! -d "$installPath" ] ; then
echo -e "\x1B[31m$installPath does not exist, please create it before continuing\x1B[0m"
exit 1
fi
if [ ! -w "$installPath" ] ; then
echo -e "\x1B[31m$installPath is not writable, please ensure you have write permissions, are the owner or have elevated to a user that has permission before continuing\x1B[0m"
exit 1
fi
if ! sed 's/:/\n/g' <<< "$PATH" | grep $installPath > /dev/null 2>&1; then
echo ""
echo -e "$installPath \x1B[31mis not in your \$PATH. Please add it to your PATH for your chosen shell.\x1B[0m"
case $SHELL in
*/zsh)
echo "Follow these instructions for adding a directory to the PATH in zsh"
echo "https://stackoverflow.com/questions/11530090/adding-a-new-entry-to-the-path-variable-in-zsh"
;;
*/bash)
echo "Follow these instructions for adding a directory to the PATH in bash"
echo "https://linuxize.com/post/how-to-add-directory-to-path-in-linux/#adding-a-directory-to-your-path"
;;
*)
# assume something else
echo "Follow these instructions for adding a directory to the PATH in $SHELL"
echo "https://www.google.com/search?q=$SHELL+add+directory+to+path"
esac
exit 1
fi
arch=$(uname -m | tr A-Z a-z )
os=$(uname -s | tr A-Z a-z )
if [ $arch == 'x86_64' ] ; then
arch='amd64'
fi
if [ $arch == 'aarch64' ] ; then
arch='arm64'
fi
osarch="$(echo $os)_$(echo $arch)"
echo "Downloading latest release for $osarch"
rm /tmp/genny-install/*
gh release --repo Gear4music/console-app-genny download --pattern "*$osarch*" -D /tmp/genny-install
echo -e "Extracting genny to $installPath"
tar -xzf /tmp/genny-install/*.tar.gz -C $installPath
echo -e "\nInstallation Complete - run \`genny init\` to setup genny config"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment