From ee608ce0977a6c9c9d9a70a85642a4033dc5c2c6 Mon Sep 17 00:00:00 2001 From: drHyperion451 Date: Fri, 8 Mar 2024 11:58:21 +0000 Subject: [PATCH 1/2] Error handling for the icns generator script --- dist/icns_generator.sh | 73 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 13 deletions(-) diff --git a/dist/icns_generator.sh b/dist/icns_generator.sh index 8fe9f4ae4e..3f0e7fb902 100755 --- a/dist/icns_generator.sh +++ b/dist/icns_generator.sh @@ -1,14 +1,61 @@ -mkdir suyu.iconset -convert -background none -resize 16x16 suyu.svg suyu.iconset/icon_16x16.png; -convert -background none -resize 32x32 suyu.svg suyu.iconset/icon_16x16@2x.png; -convert -background none -resize 32x32 suyu.svg suyu.iconset/icon_32x32.png; -convert -background none -resize 64x64 suyu.svg suyu.iconset/icon_32x32@2x.png; -convert -background none -resize 128x128 suyu.svg suyu.iconset/icon_128x128.png; -convert -background none -resize 256x256 suyu.svg suyu.iconset/icon_256x256.png; -convert -background none -resize 256x256 suyu.svg suyu.iconset/icon_128x128@2x.png; -convert -background none -resize 512x512 suyu.svg suyu.iconset/icon_256x256@2x.png; -convert -background none -resize 512x512 suyu.svg suyu.iconset/icon_512x512.png; -convert -background none -resize 1024x1024 suyu.svg suyu.iconset/icon_512x512@2x.png; +#!/bin/bash +# icns_generator.sh GNU GPLv3 License +# Run this script when a new logo is made and the suyu.svg file inside. +# You should install Imagemagick to make the conversions: $brew install imagemagick -iconutil -c icns suyu.iconset -rm -rf suyu.iconset +# Change working dir to where this script is located. +cd "${0%/*}" + +# Error Handling Stuff: +## Check command availability +check_command() { + if ! command -v "$1" &> /dev/null; then + echo "Error: '$1' command not found. Please install $2." + exit 1 + fi +} + +## Convert image with error handling +convert_image() { + convert -background none -resize "$2" "$1" "$3" || { + echo "Error: Conversion failed for $1" + exit 1 + } +} + +# Check required commands +check_command "convert" "ImageMagick" +check_command "iconutil" "macOS" + +# Create the iconset directory +mkdir suyu.iconset || { + echo "Error: Unable to create suyu.iconset directory." + exit 1 +} + +# Convert images +convert_image suyu.svg 16x16 suyu.iconset/icon_16x16.png +convert_image suyu.svg 32x32 suyu.iconset/icon_16x16@2x.png +convert_image suyu.svg 32x32 suyu.iconset/icon_32x32.png +convert_image suyu.svg 64x64 suyu.iconset/icon_32x32@2x.png +convert_image suyu.svg 128x128 suyu.iconset/icon_128x128.png +convert_image suyu.svg 256x256 suyu.iconset/icon_256x256.png +convert_image suyu.svg 256x256 suyu.iconset/icon_128x128@2x.png +convert_image suyu.svg 512x512 suyu.iconset/icon_256x256@2x.png +convert_image suyu.svg 512x512 suyu.iconset/icon_512x512.png +convert_image suyu.svg 1024x1024 suyu.iconset/icon_512x512@2x.png + +# Create the ICNS file +iconutil -c icns suyu.iconset || { + echo "Error: Failed to create ICNS file." + exit 1 +} + +# Remove the temporary iconset directory +rm -rf suyu.iconset || { + echo "Error: Unable to remove suyu.iconset directory." + exit 1 +} + +read -s -n 1 -p "Icon generation completed successfully." +echo "" From 850876afde80da78f624baadf1f7bbe5595194bb Mon Sep 17 00:00:00 2001 From: drHyperion451 Date: Fri, 8 Mar 2024 23:41:36 +0000 Subject: [PATCH 2/2] Swapped 'echo' with 'read' instead --- dist/icns_generator.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/icns_generator.sh b/dist/icns_generator.sh index 3f0e7fb902..cad971965c 100755 --- a/dist/icns_generator.sh +++ b/dist/icns_generator.sh @@ -10,7 +10,7 @@ cd "${0%/*}" ## Check command availability check_command() { if ! command -v "$1" &> /dev/null; then - echo "Error: '$1' command not found. Please install $2." + read -s -n 1 -p "Error: '$1' command not found. Please install $2." exit 1 fi } @@ -18,7 +18,7 @@ check_command() { ## Convert image with error handling convert_image() { convert -background none -resize "$2" "$1" "$3" || { - echo "Error: Conversion failed for $1" + read -s -n 1 -p "Error: Conversion failed for $1" exit 1 } } @@ -29,7 +29,7 @@ check_command "iconutil" "macOS" # Create the iconset directory mkdir suyu.iconset || { - echo "Error: Unable to create suyu.iconset directory." + read -s -n 1 -p "Error: Unable to create suyu.iconset directory." exit 1 } @@ -47,13 +47,13 @@ convert_image suyu.svg 1024x1024 suyu.iconset/icon_512x512@2x.png # Create the ICNS file iconutil -c icns suyu.iconset || { - echo "Error: Failed to create ICNS file." + read -s -n 1 -p "Error: Failed to create ICNS file." exit 1 } # Remove the temporary iconset directory rm -rf suyu.iconset || { - echo "Error: Unable to remove suyu.iconset directory." + read -s -n 1 -p "Error: Unable to remove suyu.iconset directory." exit 1 }