Skip to content

Instantly share code, notes, and snippets.

@rektdeckard
Last active May 17, 2022 02:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rektdeckard/2c20220b866a3b7efb2465e5172b6c24 to your computer and use it in GitHub Desktop.
Save rektdeckard/2c20220b866a3b7efb2465e5172b6c24 to your computer and use it in GitHub Desktop.
A suite of bash scripts for Android icon pack creators. Generate drawable.xml and icon-pack.xml from directory of icons, and map appfilter.xml to the other filter file formats.
#!/bin/bash
## Drawable Tool
## created 2019.6.15
## updated 2019.7.20
## author Tobias Fried <friedtm@gmail.com>
## A bash script for Android Icon Pack creators
## Create a list of drawable resources (PNGs) in the specified directory, in the format required for your drawable.xml
DRAWABLE="drawable.xml"
DESTINATION="./$DRAWABLE"
VERBOSE=1
TEST=0
# Set flags for verbose/silent and test/execute
while getopts ":hqstvx" OPT; do
case ${OPT} in
q|s )
VERBOSE=0
;;
t )
TEST=1
;;
v )
VERBOSE=1
;;
x )
TEST=0
;;
\? )
echo "Invalid option -$OPTARG" 1>&2
echo ""
;&
h )
echo "USAGE: drawable-tool [OPTIONS] [TARGET] [DESTINATION]"
echo ""
echo "OPTIONS:"
echo " -h display this help doc"
echo " -q, -s silent"
echo " -v verbose mode is set by default"
echo " -t test mode sends changes to Standard Output but does not write to $DRAWABLE"
echo " -x execute mode is set by default"
echo ""
echo "TARGET:"
echo " optional directory containing PNGs, if omitted is run in working directory"
echo ""
echo "DESTINATION:"
echo " optional destination to write $DRAWABLE, if omitted is written to working directory"
exit 1
;;
esac
done
shift $((OPTIND -1))
# Test for valid directories
pushd . > /dev/null
if [ -n "$1" ]; then
if [ -d "$1" ]; then
cd "$1"
else
echo "That directory does not exist."
popd > /dev/null
exit 1
fi
fi
if [ -n "$2" ]; then
if [ -d "$2" ]; then
DESTINATION="$(dirname $2)/$(basename $2)/$DRAWABLE"
else
echo "Invalid destination $2"
popd > /dev/null
exit 1
fi
fi
# Test if contains PNGs
if ls | grep -i .png > /dev/null; then
# Write required enclosing XML tags
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<resources>
<category title=\"All\" />" > "$DESTINATION"
# Add entry for each PNG in the directory
shopt -s nocaseglob
for FILE in *.png; do
if [ "$VERBOSE" == 1 ]; then
echo "Processing ${FILE}"
fi
if [ "$TEST" == 0 ]; then
echo " <item drawable=\"${FILE%.*}\" />" >> "$DESTINATION"
fi
done
shopt -u nocaseglob
echo "
</resources>" >> "$DESTINATION"
if [ "$VERBOSE" == 1 ]; then
echo "Done"
fi
else
echo "No PNG files found."
fi
popd > /dev/null
#!/bin/bash
## Filter Map
## created 2019.6.15
## author Tobias Fried <friedtm@gmail.com>
## A bash script for Android Icon Pack creators
## Maps drawable resources from a appfilter.xml file to appmap.xml and theme_resources.xml files
LOCATION="$1"
APPFILTER="appfilter.xml"
APPMAP="appmap.xml"
THEMERESOURCES="theme_resources.xml"
WARNING="<!-- AUTOGENERATED FILE -- DELETE THIS COMMENT AFTER REVIEW -->"
# Get confirmation to overwrite existing files
get_confirmation() {
read -n 1 -sp "This will overwrite $APPMAP and $THEMERESOURCES files in this directory, if they exist. Continue? [y]es or [n]o: " CONFIRM
echo ""
case $CONFIRM in
y|Y)
;;
n|N)
echo "Cancelled"
exit 0
;;
*)
echo "Invalid response"
get_confirmation
;;
esac
}
# Move to file location, if given
pushd . > /dev/null
echo -n "Locating $APPFILTER..."
if [[ ! -z $LOCATION ]]; then
cd $( dirname "$LOCATION")
fi
# Test if file exists
if [[ -f $APPFILTER ]]; then
echo "Done"
get_confirmation
# Extract version number
APPVERSION="$(sed -n 's/.*<version>\([0-9]*\)<\/version>.*/\1/p' $APPFILTER)"
echo "App versionCode $APPVERSION"
# Generate appmap.xml
echo -n "Generating $APPMAP..."
echo "$WARNING" > "$APPMAP"
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<appmap>
<!-- SUPPORTED LAUNCHERS -->
<!-- Atom Launcher -->
" >> "$APPMAP"
sed -e 's:<item component="ComponentInfo\([^/]*\).:<item class=":; s:}::; s:drawable=:name=:g; s/\(<.\?\)resources>/\1appmap>/g' "$APPFILTER" >> "$APPMAP"
echo "Done"
# Generate theme_resources.xml
echo -n "Generating $THEMERESOURCES..."
echo "$WARNING" > "$THEMERESOURCES"
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<Theme version=\"$APPVERSION\">
<!-- SUPPORTED LAUNCHERS -->
<!-- LG Home -->
<Label value=\"YOUR_APP_NAME\" />
<Wallpaper image=\"lg_homescreen_wallpaper\" />
<LockScreenWallpaper image=\"lockscreen_wallpaper\" />
<ThemePreview image=\"lg_homescreen_preview\" />
<ThemePreviewWork image=\"lg_homescreen_preview_work\" />
<ThemePreviewMenu image=\"lg_homescreen_preview_menu\" />
<DockMenuAppIcon selector=\"apps\" />
" >> "$THEMERESOURCES"
sed -e 's:<item component="ComponentInfo{:<AppIcon name=":; s:}::; s:drawable=:image=:g; s/\(<.\?\)resources>/\1Theme>/g' "$APPFILTER" >> "$THEMERESOURCES"
echo "Done"
else
echo "Required file appfilter.xml not found."
fi
popd > /dev/null
#!/bin/bash
## Icon-Pack Tool
## created 2019.6.19
## updated 2019.7.20
## author Tobias Fried <friedtm@gmail.com>
## A bash script for Android Icon Pack creators
## Create a list of new drawable resources (PNGs) in the specified diretory, in the format required by icon-pack.xml
ICONPACK="icon_pack.xml"
DESTINATION="./$ICONPACK"
VERBOSE=1
TEST=0
# Set flags for verbose/silent and test/execute
while getopts ":hqstvx" OPT; do
case ${OPT} in
q|s )
VERBOSE=0
;;
t )
TEST=1
;;
v )
VERBOSE=1
;;
x )
TEST=0
;;
\? )
echo "Invalid option: -$OPTARG" 1>&2
echo ""
;&
h )
echo "USAGE: iconpack-tool [OPTIONS] [TARGET] [DESTINATION]"
echo ""
echo "OPTIONS:"
echo " -h display this help doc"
echo " -q, -s silent"
echo " -v verbose mode is set by default"
echo " -t test mode sends changes to Standard Output but does not write to $ICONPACK"
echo " -x execute mode is set by default"
echo ""
echo "TARGET:"
echo " optional directory containing PNGs, if omitted is run in working directory"
echo ""
echo "DESTINATION:"
echo " optional destination to write $ICONPACK, if omitted is written to working directory"
exit 1
;;
esac
done
shift $((OPTIND -1))
# Test for valid directory
pushd . > /dev/null
if [ -n "$1" ]; then
if [ -d "$1" ]; then
cd "$1"
else
echo "That directory does not exist."
popd > /dev/null
exit 1
fi
fi
if [ -n "$2" ]; then
if [ -d "$2" ]; then
DESTINATION="$(dirname $2)/$(basename $2)/$ICONPACK"
else
echo "Invalid destination $2"
popd > /dev/null
exit 1
fi
fi
# Test if directory contains PNGs
if ls | grep -i .png > /dev/null; then
# Write required enclosing XML tags
echo '<string-array name="all">' > "$DESTINATION"
# Add entry for each PNG in the directory
shopt -s nocaseglob
for FILE in *.png; do
if [ "$VERBOSE" == 1 ]; then
echo "Processing ${FILE}"
fi
if [ "$TEST" == 0 ]; then
echo " <item>${FILE%.*}</item>" >> "$DESTINATION"
fi
done
shopt -u nocaseglob
echo "</string-array>" >> "$DESTINATION"
if [ "$VERBOSE" == 1 ]; then
echo "Done"
fi
else
echo "No PNG files found."
fi
popd > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment