Skip to content

Commit

Permalink
[FIX] Warnings/Errors after linting code with 'Shellcheck'
Browse files Browse the repository at this point in the history
  • Loading branch information
raaowx committed Jun 19, 2021
1 parent e265bfc commit 9701b24
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 115 deletions.
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
# MAIG (Mobile App Icon Generator)

<img
src="./maig.png" width="25">
src="./maig.png"
width="32">

Mobile App Icon Generator (MAIG) is a bash script to generate all necessary icons for Android or iOS apps and stores

**Table of Contents:**

- [MAIG (Mobile App Icon Generator)](#maig-mobile-app-icon-generator)
- [How it works](#how-it-works)
- [Third Party Software](#third-party-software)
- [Parameters](#parameters)
- [Usage](#usage)
- [Android Icons](#android-icons)
- [iOS Icons](#ios-icons)
- [Exit Codes](#exit-codes)
- [Credits](#credits)
- [Project Icon](#project-icon)
- [License & Copyright](#license--copyright)

---

## How it works

MAIG first analyze the parameters and look for the third party software it needs. If everything is correct, MAIG will check if the resolution of the original image is the minimal required for the selected platform. After that the generation will begin. When the scripts end, you can find all the generated icons in a folder called `MAIG` in the same location as the original image.
Expand Down Expand Up @@ -92,12 +109,14 @@ Code|Description|
10|Generic error 1: Generating app icons
255|Generic error 2: Check help using parameter `-h` for more info

## License

The script is licensed with MIT License.
## Credits

## Project Icon
### Project Icon

[Icon](https://www.flaticon.com/free-icon/layers_149243) made by [Smashicons](https://www.flaticon.com/authors/smashicons) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/)

## License & Copyright

The script is licensed with MIT License.

Copyright © 2020 **Álvaro López de Diego {raaowx}** <[email protected]>
217 changes: 107 additions & 110 deletions maig.bash
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -58,95 +58,94 @@ function help() {
}
function errorMessages() {
case $1 in
1)
echo
echo "[ERROR] MAIG script needs parameters for work correctly. Please, refer to help using '-h' parameter for more info."
echo
exit 1
;;
2)
echo
echo "[ERROR] Invalid option '-$2'. Please, refer to help using parameter '-h' for more info."
echo
exit 2
;;
3)
echo
echo "[ERROR] Option '-$2' requires an argument. Please, refere to help using parameter '-h' for more info."
echo
exit 3
;;
4)
echo
echo "[ERROR] MAIG is already set to create $2 icons. Please, run the script again using only '-A' or '-I'. Refer to help with '-h' for more info."
echo
exit 4
;;
5)
echo
echo "[ERROR] MAIG script needs utility '$2'. It can be found in the ImageMagick software. Please, install it or include it on PATH variable. Refer to help using parameter '-h' for more info."
echo
exit 5
;;
6)
echo
echo "[ERROR] MAIG script needs parameter '-i' with an input file for work correctly. Please, refer to help using parameter '-h' for more info."
echo
exit 6
;;
7)
echo
echo "[ERROR] Seems like you don't have read or write permissions over $INPUTFILE or $INPUTPATH. Please, check the permissions and try again."
echo
exit 7
;;
8)
echo
echo "[ERROR] Original image should be squared. The given image have $2x$3 pixels (WxH)."
echo
exit 8
;;
9)
echo
echo "[ERROR] For generating icons for $2 the original image should be at least $3x$3 pixels (WxH)."
echo
exit 9
;;
10)
echo
echo "[ERROR] Generating app icons. Please, try again."
echo
exit 10
;;
*)
echo
echo "[ERROR] Check 'help' using parameter '-h' for more info."
echo
exit 255
;;
1)
echo
echo "[ERROR] MAIG script needs parameters for work correctly. Please, refer to help using '-h' parameter for more info."
echo
exit 1
;;
2)
echo
echo "[ERROR] Invalid option '-$2'. Please, refer to help using parameter '-h' for more info."
echo
exit 2
;;
3)
echo
echo "[ERROR] Option '-$2' requires an argument. Please, refere to help using parameter '-h' for more info."
echo
exit 3
;;
4)
echo
echo "[ERROR] MAIG is already set to create $2 icons. Please, run the script again using only '-A' or '-I'. Refer to help with '-h' for more info."
echo
exit 4
;;
5)
echo
echo "[ERROR] MAIG script needs utility '$2'. It can be found in the ImageMagick software. Please, install it or include it on PATH variable. Refer to help using parameter '-h' for more info."
echo
exit 5
;;
6)
echo
echo "[ERROR] MAIG script needs parameter '-i' with an input file for work correctly. Please, refer to help using parameter '-h' for more info."
echo
exit 6
;;
7)
echo
echo "[ERROR] Seems like you don't have read or write permissions over $INPUTFILE or $INPUTPATH. Please, check the permissions and try again."
echo
exit 7
;;
8)
echo
echo "[ERROR] Original image should be squared. The given image have $2x$3 pixels (WxH)."
echo
exit 8
;;
9)
echo
echo "[ERROR] For generating icons for $2 the original image should be at least $3x$3 pixels (WxH)."
echo
exit 9
;;
10)
echo
echo "[ERROR] Generating app icons. Please, try again."
echo
exit 10
;;
*)
echo
echo "[ERROR] Check 'help' using parameter '-h' for more info."
echo
exit 255
;;
esac
}
function genIcons() {
echo "Starting $1 icon generation..."
echo
cd "$INPUTPATH"
cd "$INPUTPATH" || errorMessages 7
COUNT=0
for i in ${ICONLIST[@]}; do
convert "$INPUTFILE" -resize $ix$i "$OUTPUTDIR/${INPUTFILE%%.*}-${ICONNAME[$COUNT]}.${INPUTFILE#*.}"
if [[ $? -eq 0 ]]; then
echo "[SUCCESS] Generating icon with size $ix$i."
for i in "${ICONLIST[@]}"; do
if convert "$INPUTFILE" -resize "$i x $i" "$OUTPUTDIR/${INPUTFILE%%.*}-${ICONNAME[$COUNT]}.${INPUTFILE#*.}"; then
echo "[SUCCESS] Generating icon with size $i x $i."
else
echo "[ERROR] Generating icon with size $ix$i."
echo "[ERROR] Generating icon with size $i x $i."
fi
COUNT=$(( $COUNT + 1 ))
COUNT=$((COUNT + 1))
done
goodbye
goodbye $?
}
function cleanMaig() {
rmdir "$INPUTPATH/$OUTPUTDIR"
}
function goodbye() {
if [[ $? -eq 0 ]]; then
if [[ $1 -eq 0 ]]; then
echo
echo "All generated icon are stored in '$INPUTPATH/$OUTPUTDIR'."
echo
Expand All @@ -172,44 +171,42 @@ if [[ $# -eq 0 ]]; then
fi
while getopts ":AIhi:" opt; do
case ${opt} in
A)
if [[ "$IOS" == "false" ]]; then
ANDROID=true
else
errorMessages 4 iOS
fi
;;
I)
if [[ "$ANDROID" == "false" ]]; then
IOS=true
else
errorMessages 4 Android
fi
;;
h)
help
;;
i)
INPUTPATH=$(dirname "$OPTARG")
INPUTFILE=$(basename "$OPTARG")
;;
*)
if [[ "$opt" == "?" ]]; then
errorMessages 2 "$OPTARG"
elif [[ "$opt" == ":" ]]; then
errorMessages 3 "$OPTARG"
else
errorMessages
fi
;;
A)
if [[ "$IOS" == "false" ]]; then
ANDROID=true
else
errorMessages 4 iOS
fi
;;
I)
if [[ "$ANDROID" == "false" ]]; then
IOS=true
else
errorMessages 4 Android
fi
;;
h)
help
;;
i)
INPUTPATH=$(dirname "$OPTARG")
INPUTFILE=$(basename "$OPTARG")
;;
*)
if [[ "$opt" == "?" ]]; then
errorMessages 2 "$OPTARG"
elif [[ "$opt" == ":" ]]; then
errorMessages 3 "$OPTARG"
else
errorMessages
fi
;;
esac
done
which convert &> /dev/null
if [[ $? -ne 0 ]]; then
if ! which convert &>/dev/null; then
errorMessages 5 convert
fi
which identify &> /dev/null
if [[ $? -ne 0 ]]; then
if ! which identify &>/dev/null; then
errorMessages 5 identify
fi
if [[ "$INPUTPATH" == "" ]] || [[ "$INPUTFILE" == "" ]]; then
Expand Down Expand Up @@ -250,7 +247,7 @@ if [[ -w $INPUTPATH ]] && [[ -r "$INPUTPATH/$INPUTFILE" ]]; then
fi
else
cleanMaig
errorMessages 8 $W $H
errorMessages 8 "$W" "$H"
fi
else
errorMessages 7
Expand Down

0 comments on commit 9701b24

Please sign in to comment.