Last active
October 28, 2022 06:10
-
-
Save MMK21Hub/49830ea10f487f4dcb60eb4af786a822 to your computer and use it in GitHub Desktop.
A simple bash script to install the https://github.com/IdreesInc/Monocraft font. Needs more error handling and some documentation. And the code is horrible.
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 | |
rel() { | |
echo $(echo $latest_release | jq --raw-output "$1") | |
} | |
repo="IdreesInc/Monocraft" | |
url="https://api.github.com/repos/$repo/releases/latest" | |
fonts="$HOME/.local/share/fonts" | |
if ! [ -x "$(command -v jq)" ]; then | |
echo "This script requires the jq program." | |
echo "Install it using your package manager." | |
exit 30 | |
fi | |
echo "Fetching metadata for the latest release..." | |
if ! latest_release=$(curl --silent "$url"); then | |
echo "Couldn't fetch the release metadata!" | |
echo "Check that the curl program is available and that internet access is working." | |
echo "This could also mean that GitHub is rate-limiting us. Try again tommorow?" | |
exit 32 | |
fi | |
echo "Latest version is" $(rel '.tag_name')", released on" $(rel '.published_at' | date +"%-d %B %Y" -f - ) | |
echo "Found `rel '.assets | length'` downloadable file(s) attached to the release." | |
size=`numfmt --to=iec --suffix=B $(rel '.assets[0].size')` | |
file=`rel '.assets[0].name'` | |
if [ -e "$fonts/$file" ]; then | |
echo "Note: The font appears to already be installed." | |
echo "The old font file will be replaced by the latest version of the font." | |
fi | |
read -p "About to download $file ($size). Continue? (Y/n) " response | |
# Convert $response to lower case | |
response=$(echo $response | tr '[:upper:]' '[:lower:]') | |
if ! [[ $response == y* || $response == "" ]]; then | |
echo # Blank line | |
echo "Aborted!" | |
echo "You can download the correct file manually from `rel '.html_url'`" | |
exit 10 | |
fi | |
echo # Blank line | |
# Create folder if it doesn't already exist: | |
mkdir "$fonts" 2>/dev/null | |
echo "Downloading $file to $fonts..." | |
# Run only the curl command in the fonts directory: | |
curl_result=$(cd "${fonts}" | |
curl --remote-name --silent -L `rel '.assets[0].browser_download_url'` | |
curl_res=$? | |
if [[ curl_res -ne 0 ]]; then | |
echo "" >&2 # Blank line | |
echo "Couldn't download the file!" >&2 | |
echo "Check that internet access works for github.com." >&2 | |
echo "31" | |
fi) | |
if [[ $curl_result ]]; then | |
exit $curl_result | |
fi | |
echo "Regenerating font cache..." | |
if ! fc-cache -fv >/dev/null; then | |
echo "Failed to refresh the font cache!" | |
echo "You should log out and back in again to make the font available." | |
exit 20 | |
fi | |
echo "Succesfully installed the font!" | |
echo "You will now be able to select it in any app that supports custom fonts." |
Author
MMK21Hub
commented
Oct 28, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment