summarylogtreecommitdiffstats
path: root/mime-archpkg.sh
diff options
context:
space:
mode:
authorgrimi2017-03-27 07:34:34 +0200
committergrimi2017-03-27 07:34:34 +0200
commita0975e96cb6a027c16aaf3d04372b1c5d2f4dc98 (patch)
tree069471770688bb60e57e3ee9182811cdc301f896 /mime-archpkg.sh
parentd133b204bc74550a8fc8cb4dfde9bfe83cb37c1b (diff)
downloadaur-a0975e96cb6a027c16aaf3d04372b1c5d2f4dc98.tar.gz
Upd: 0.3.7, relative path handling, fixes, optim.
Diffstat (limited to 'mime-archpkg.sh')
-rw-r--r--mime-archpkg.sh78
1 files changed, 41 insertions, 37 deletions
diff --git a/mime-archpkg.sh b/mime-archpkg.sh
index f75e91f4d816..2b670b0e6111 100644
--- a/mime-archpkg.sh
+++ b/mime-archpkg.sh
@@ -3,10 +3,11 @@
# name: mime-archpkg
# require: grep, sed, convert (imagemagick), rsvg-convert (librsvg), gtk-update-icon-cache
-declare MODE=usage
-declare MYDIR=/usr/share/mime-archpkg
-declare -r NAME=application-x-archpkg
-declare MUTE=0
+declare MODE="usage"
+declare MYDIR="/usr/share/mime-archpkg"
+declare ICODIR="/usr/share/icons"
+declare -r NAME="application-x-archpkg"
+declare -i MUTE=0
add() {
@@ -17,33 +18,31 @@ add() {
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
+ theme="$ICODIR/${file%.svgz}"
+ if [[ $one && ${file%.svgz} != $one ]]; then
+ continue
fi
if [[ -f $theme/index.theme ]]; then
if [[ $mute -ne 1 ]]; then
echo ">> Adding mimetype icons for $theme... <<"
fi
- taba=($(grep "\[.*mimetypes.*\]" "$theme/index.theme"|sed 's/\[//; s/\]//'))
+ taba=($(grep -e "\[.*mimetypes.*\]" -e "\[.*mimes.*\]" "$theme/index.theme"|sed 's/\[//; s/\]//'))
for elem in "${taba[@]}"; do
- tab=($(echo $elem|sed 's/\//\n/'))
- if [[ ${elem/scalable/} != ${elem} ]]; then
+ tab=($(echo -e ${elem/\//\\n}))
+ if [[ $elem =~ "scalable" ]]; then
size=0
else
- if [[ ${tab[0]/[0-9]/} != ${tab[0]} ]]; then
+ if [[ ${tab[0]} =~ [0-9]{2,3} ]]; then
abc="${tab[0]}"
- elif [[ ${tab[1]/[0-9]/} != ${tab[1]} ]]; then
+ elif [[ ${tab[1]} =~ [0-9]{2,3} ]]; then
abc="${tab[1]}"
else
continue
fi
- if [[ -h $theme/$abc ]]; then # skip link
+ if [[ -h $theme/${tab[0]} ]]; then # skip link
continue
fi
- if [[ ${abc/@2x/} != $abc ]]; then
+ if [[ $elem =~ "@2x" ]]; then
abc=${abc/@2x/}
size=${abc/x*/}
size=$size*2
@@ -52,14 +51,16 @@ add() {
fi
fi
if [[ $size -ne 0 ]]; then
- if [[ -f $theme/$elem/package.svg ]]; then
- suf=svg
- else
- suf=png
+ if [[ -d $theme/$elem ]]; 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"
fi
- convert -resize ${size}x${size} -background none "$file" /tmp/archpkg.$suf
- install -m644 /tmp/archpkg.$suf "$theme/$elem/$NAME.$suf"
- else
+ elif [[ -d $theme/$elem ]]; then
rsvg-convert -o /tmp/archpkg.svg -f svg "$file"
install -m644 /tmp/archpkg.svg "$theme/$elem/$NAME.svg"
fi
@@ -78,11 +79,9 @@ remove() {
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
+ theme="$ICODIR/${file%.svgz}"
+ if [[ $one && ${file%.svgz} != $one ]]; then
+ continue
fi
if [[ -d $theme ]]; then
if [[ $MUTE -ne 1 ]]; then
@@ -104,11 +103,9 @@ update() {
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
+ theme="$ICODIR/${file%.svgz}"
+ if [[ $one && ${file%.svgz} != $one ]]; then
+ continue
fi
if [[ -d $theme && -f $theme/index.theme ]]; then
if [[ $MUTE -ne 1 ]]; then
@@ -124,11 +121,12 @@ update() {
}
usage() {
- echo "USAGE: [-q] <-a|-u|-r> [theme]"
+ echo "USAGE: [-q] [-r] <-a|-u|-d> [theme]"
echo " -q: don't comment action"
+ echo " -r: relative path (default abs.)"
echo " -a: add archpkg mime icons"
echo " -u: update archpkg mime icons"
- echo " -r: remove archpkg mime icons"
+ echo " -d: remove archpkg mime icons"
echo " theme: action only for entered theme"
}
@@ -138,11 +136,18 @@ if [[ $1 == "-q" ]]; then
shift
fi
+if [[ $1 == "-r" ]]; then
+ if [[ $PWD != "/" ]]; then
+ MYDIR="$PWD/${MYDIR:1}"
+ ICODIR="$PWD/${ICODIR:1}"
+ fi
+ shift
+fi
case "$1" in
-a) MODE=add ;;
-u) MODE=update ;;
- -r) MODE=remove ;;
+ -d) MODE=remove ;;
esac
if [[ $MODE != "usage" && $USER != "root" ]]; then
@@ -152,4 +157,3 @@ fi
$MODE "$2"
-