Created
August 23, 2021 07:57
-
-
Save 0inp/2e855eae126400458537d653ac033ff2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ -z "$GITHUBAPI_TOKEN" ]]; then | |
echo "Go to https://github.com/" | |
echo "Log in" | |
echo "Go to: Settings->Developpers Settings->Personal Access Token" | |
echo "Create a token with full control of private repositories" | |
echo "Finally export GITHUBAPI_TOKEN=<token>" | |
exit | |
fi | |
echo "--Variables initialization--" | |
TOKEN="$GITHUBAPI_TOKEN" | |
REPO="MeilleursAgents/MA-Integration" | |
GITHUB_API_ENDPOINT="api.github.com" | |
sys_name=`uname -s` | |
machine_name=`uname -m` | |
sys_machine_key="${sys_name}_${machine_name}" | |
echo "$sys_machine_key" | |
echo -e "\n--Get latest mactl releases--" | |
curl -u "0inp:$TOKEN" "https://$GITHUB_API_ENDPOINT/repos/$REPO/releases/latest" -o response.txt | |
echo -e "\n--Find right release to dl--" | |
parser=".assets[] | {name: .name, url: .url}" | |
curl_cmd=$(cat response.txt | jq "$parser") | |
flag_correct_asset=false | |
while read line; do | |
if [[ $line =~ $sys_machine_key ]]; then | |
echo "$line" | |
flag_correct_asset=true | |
fi | |
if [[ $flag_correct_asset = true ]]; then | |
if [[ $line =~ "url" ]]; then | |
url=$(echo "$line" | cut -d : -f 2,3 | tr -d \" | xargs) | |
break | |
fi | |
fi | |
done <<< "$curl_cmd" | |
echo -e "\n--Download the release--" | |
echo "$url" | |
curl -L -s -H "Accept: application/octet-stream" "$url?access_token=$TOKEN" > mactl_release.tar.gz | |
echo -e "\n--Untar the archive--" | |
if [[ "$sys_name" == "Linux"* ]]; then | |
mactl_dir='/usr/local' | |
elif [[ "$sys_name" == "Darwin"* ]]; then | |
mactl_dir='/usr/local/bin' | |
fi | |
tar -xzvf mactl_release.tar.gz -C "$mactl_dir" | |
echo -e "\n--Open the CLI--" | |
"$mactl_dir"/mactl | |
echo -e "\n--Clean--" | |
rm -f response.txt | |
rm -f mactl_release.tar.gz | |
rm -f mactl_release.tar.gz | |
echo -e "\n--Done !--" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment