diff options
Diffstat (limited to 'mime-archpkg.sh')
-rw-r--r-- | mime-archpkg.sh | 114 |
1 files changed, 74 insertions, 40 deletions
diff --git a/mime-archpkg.sh b/mime-archpkg.sh index f93c56c65c1f..f75e91f4d816 100644 --- a/mime-archpkg.sh +++ b/mime-archpkg.sh @@ -5,66 +5,63 @@ declare MODE=usage declare MYDIR=/usr/share/mime-archpkg -declare MYTHEME="$2" declare -r NAME=application-x-archpkg +declare MUTE=0 -update() { - local file theme elem suf abc - local -i size +add() { + # $1 = theme (if not present, add for all), $2 = [0|1] mute + local file theme elem suf abc one="$1" + local -i size mute=${2:-$MUTE} local -a taba tab if [[ -d $MYDIR ]]; then cd "$MYDIR" for file in *.svgz; do theme="/usr/share/icons/${file%.svgz}" - if [[ ${MYTHEME} ]]; then - if [[ ${file%.svgz} != $MYTHEME ]]; then + if [[ $one ]]; then + if [[ ${file%.svgz} != $one ]]; then continue fi fi if [[ -f $theme/index.theme ]]; then - echo ">> Updating mimetype icons in $theme... <<" + if [[ $mute -ne 1 ]]; then + echo ">> Adding mimetype icons for $theme... <<" + fi taba=($(grep "\[.*mimetypes.*\]" "$theme/index.theme"|sed 's/\[//; s/\]//')) for elem in "${taba[@]}"; do tab=($(echo $elem|sed 's/\//\n/')) - if [[ ${tab[0]/[0-9]/} != ${tab[0]} ]]; then - if [[ -h $theme/${tab[0]} ]]; then # skip link - continue - fi - if [[ ${tab[0]/@2x/} != ${tab[0]} ]]; then - abc=${tab[0]/@2x/} - size=${abc/x*/} - size=$size*2 + if [[ ${elem/scalable/} != ${elem} ]]; then + size=0 + else + if [[ ${tab[0]/[0-9]/} != ${tab[0]} ]]; then + abc="${tab[0]}" + elif [[ ${tab[1]/[0-9]/} != ${tab[1]} ]]; then + abc="${tab[1]}" else - size=${tab[0]/x*/} + continue fi - elif [[ ${tab[1]/[0-9]/} != ${tab[1]} ]]; then - if [[ -h $theme/${tab[1]} ]]; then # skip link + if [[ -h $theme/$abc ]]; then # skip link continue fi - if [[ ${tab[1]/@2x/} != ${tab[1]} ]]; then - abc=${tab[1]/@2x/} + if [[ ${abc/@2x/} != $abc ]]; then + abc=${abc/@2x/} size=${abc/x*/} size=$size*2 else - size=${tab[1]/x*/} + size=${abc/x*/} fi - elif [[ ${elem/scalable/} != ${elem} ]]; then - size=0 fi - if [[ $size ]]; then - if [[ $size -ne 0 ]]; then - if [[ -f $theme/$elem/package.svg ]]; then - suf=svg - else - suf=png - fi - convert -resize ${size}x${size} -background none "$file" /tmp/archpkg.$suf - install -m644 /tmp/archpkg.$suf "$theme/$elem/$NAME.$suf" + if [[ $size -ne 0 ]]; then + if [[ -f $theme/$elem/package.svg ]]; then + suf=svg else - rsvg-convert -o /tmp/archpkg.svg -f svg "$file" - install -m644 /tmp/archpkg.svg "$theme/$elem/$NAME.svg" + suf=png fi + convert -resize ${size}x${size} -background none "$file" /tmp/archpkg.$suf + install -m644 /tmp/archpkg.$suf "$theme/$elem/$NAME.$suf" + else + rsvg-convert -o /tmp/archpkg.svg -f svg "$file" + install -m644 /tmp/archpkg.svg "$theme/$elem/$NAME.svg" fi done if [[ -f $theme/icon-theme.cache ]]; then @@ -76,18 +73,21 @@ update() { } remove() { - local file theme + # $1 = theme (if not present, remove from all) + local file theme one="$1" if [[ -d $MYDIR ]]; then cd "$MYDIR" for file in *.svgz; do theme="/usr/share/icons/${file%.svgz}" - if [[ ${MYTHEME} ]]; then - if [[ ${file%.svgz} != $MYTHEME ]]; then + if [[ $one ]]; then + if [[ ${file%.svgz} != $one ]]; then continue fi fi if [[ -d $theme ]]; then - echo ">> Removing installed mimetype icons from $theme... <<" + if [[ $MUTE -ne 1 ]]; then + echo ">> Removing installed mimetype icons from $theme... <<" + fi find "$theme/" -type f -name $NAME.png -exec rm "{}" \; find "$theme/" -type f -name $NAME.svg -exec rm "{}" \; if [[ -f $theme/icon-theme.cache ]]; then @@ -98,15 +98,49 @@ remove() { fi } +update() { + # $1 = theme (if not present, update for all) + local file theme one="$1" + if [[ -d $MYDIR ]]; then + cd "$MYDIR" + for file in *.svgz; do + theme="/usr/share/icons/${file%.svgz}" + if [[ $one ]]; then + if [[ ${file%.svgz} != $one ]]; then + continue + fi + fi + if [[ -d $theme && -f $theme/index.theme ]]; then + if [[ $MUTE -ne 1 ]]; then + echo ">> Updating installed mimetype icons for $theme... <<" + fi + find "$theme/" -type f -name $NAME.png -exec rm "{}" \; + find "$theme/" -type f -name $NAME.svg -exec rm "{}" \; + add "${file%.svgz}" 1 + fi + done + fi + +} + usage() { - echo "USAGE: [-u|-r] [theme]" + echo "USAGE: [-q] <-a|-u|-r> [theme]" + echo " -q: don't comment action" + echo " -a: add archpkg mime icons" echo " -u: update archpkg mime icons" echo " -r: remove archpkg mime icons" echo " theme: action only for entered theme" } +if [[ $1 == "-q" ]]; then + MUTE=1 + shift +fi + + case "$1" in + -a) MODE=add ;; -u) MODE=update ;; -r) MODE=remove ;; esac @@ -116,6 +150,6 @@ if [[ $MODE != "usage" && $USER != "root" ]]; then exit 1 fi -eval $MODE +$MODE "$2" |