wok-6.x annotate slim/stuff/slim-theme @ rev 17061
syslinux/c32box: x86_64 auto select (again)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Aug 21 15:05:24 2014 +0200 (2014-08-21) |
parents | 05ce2fe60fcd |
children | 19477586b01f |
rev | line source |
---|---|
pankso@16119 | 1 #!/bin/sh |
al@14601 | 2 # slim-theme: manage SLiM themes |
al@16779 | 3 # Aleksej Bobylev <al.bobylev@gmail.com>, 2013-2014 |
al@14601 | 4 |
al@14601 | 5 ME=$(basename $0) |
al@14601 | 6 VERSION=20130525 |
al@14601 | 7 CONF=/etc/slim.conf |
al@14601 | 8 |
al@14601 | 9 help() |
al@14601 | 10 { |
al@14601 | 11 cat >&2 << EOT |
al@14601 | 12 $ME: Manage SLiM themes |
al@14601 | 13 |
al@14601 | 14 Usage: $ME OPTION [NAME] |
al@14601 | 15 |
al@14601 | 16 Options: |
al@14601 | 17 -h Display this short help and exit |
al@14601 | 18 -l List available themes (comma separated) |
al@14601 | 19 -g Get the name of current theme (note, it can be comma separated list) |
al@14601 | 20 -s NAME Set NAME theme as current; name of previous theme will be stored |
al@14601 | 21 (note, you can set comma separated list for random theme behavior) |
al@14601 | 22 -f NAME Forget about NAME theme and return to previous used theme |
al@14601 | 23 -V Display information about $ME version |
al@16779 | 24 -t Translate current theme\'s strings according to global LANG value |
al@14601 | 25 (note, its done auto when -s processed) |
al@14601 | 26 -T LANG Same as above, but use specified language |
al@14601 | 27 |
al@14601 | 28 Set option works like stack: you can "set" theme several times (every time you |
al@14601 | 29 install new SLiM theme). Use "forget" option at every theme uninstall to revert |
al@14601 | 30 to previous theme, if it was current. |
al@14601 | 31 EOT |
al@14601 | 32 exit 0 |
al@14601 | 33 } |
al@14601 | 34 |
al@14601 | 35 get_current() awk '/current_theme/ { print $2 }' $CONF |
al@14601 | 36 get_prev() awk '/previous_theme/ { print $2 }' $CONF |
al@14601 | 37 set_current() sed -i 's|^current_theme .*$|current_theme '$1'|' $CONF |
al@14601 | 38 set_prev() |
al@14601 | 39 { |
al@14601 | 40 sed -i '/^previous_theme/d' $CONF |
al@14601 | 41 [ x$1 != x ] && echo "previous_theme $1" >> $CONF |
al@14601 | 42 } |
al@14601 | 43 find_theme() |
al@14601 | 44 { |
al@14601 | 45 cd /usr/share/slim/themes |
al@14601 | 46 theme=$(ls -Ad $1 2>/dev/null | head -n1) |
al@14601 | 47 [ x$theme == x ] && echo "Theme \"$1\" not exist!" >&2 && exit 1 |
al@14601 | 48 echo $theme |
al@14601 | 49 } |
al@14601 | 50 i18n() |
al@14601 | 51 { |
al@14601 | 52 lang=$1 |
al@14601 | 53 curr=$(get_current) |
al@14601 | 54 strings=/usr/share/slim/themes/$curr/strings |
al@16779 | 55 [ ! -e $strings ] && strings=/usr/share/slim/strings |
al@14601 | 56 conf=/usr/share/slim/themes/$curr/slim.theme |
al@14601 | 57 for str in welcome_msg username_msg password_msg; do |
al@14601 | 58 # ll_CC.UTF-8@euro ; ll_CC.UTF-8 ; ll_CC ; ll ; en |
al@14601 | 59 for langtry in $lang ${lang%@*} ${lang%\.*} ${lang%_*} en; do |
al@14601 | 60 try="$(grep '^'${str:0:1}':'$langtry' ' $strings | cut -d' ' -f2)" |
al@14601 | 61 [ x"$try" != x ] && break |
al@14601 | 62 done |
al@14601 | 63 sed -i 's|^\('$str'\).*$|\1 '"$try"'|' $conf |
al@14601 | 64 echo "$str[$langtry]=$try" >&2 |
al@14601 | 65 done |
al@14601 | 66 } |
al@14601 | 67 |
al@14601 | 68 set_theme() |
al@14601 | 69 { |
al@14601 | 70 theme=$(find_theme "$1") |
al@14601 | 71 curr=$(get_current) |
al@14601 | 72 prev=$(get_prev) |
al@14601 | 73 if [ x$theme != x$curr ]; then |
al@14601 | 74 echo "Set theme $theme" >&2 |
al@14601 | 75 [ x$prev != x ] && curr=$curr:$prev |
al@14601 | 76 set_prev $curr |
al@14601 | 77 set_current $theme |
al@14601 | 78 else |
al@14601 | 79 echo "Already set" >&2 |
al@14601 | 80 fi |
al@14601 | 81 |
al@14601 | 82 i18n $LANG |
al@14601 | 83 exit 0 |
al@14601 | 84 } |
al@14601 | 85 |
al@14601 | 86 forget_theme() |
al@14601 | 87 { |
al@14601 | 88 theme=$(find_theme "$1") |
al@14601 | 89 curr=$(get_current) |
al@14601 | 90 prev=$(get_prev) |
al@14601 | 91 echo "Forget theme \"$theme\"" >&2 |
al@14601 | 92 if [ x$theme == x$curr ]; then |
al@14601 | 93 last=$(echo $prev | cut -d: -f1); [ x$last == x ] && last=base |
al@14601 | 94 rest=${prev#*:}; [ x$rest == x$prev ] && rest= |
al@14601 | 95 prev=$rest; set_prev $prev |
al@14601 | 96 echo "Back to \"$last\" theme" >&2 |
al@14601 | 97 set_current $last |
al@14601 | 98 fi |
al@14601 | 99 prev=$(echo $(echo $prev | tr ':' '\n' | sed "/$theme/d") | tr ' ' ':') |
al@14601 | 100 set_prev $prev |
al@14601 | 101 |
al@14601 | 102 exit 0 |
al@14601 | 103 } |
al@14601 | 104 |
al@14601 | 105 |
al@14601 | 106 # parse only first option |
al@14601 | 107 getopts ":lgs:f:VhtT:" opt |
al@14601 | 108 case $opt in |
al@14601 | 109 l) |
al@14601 | 110 list=$(find /usr/share/slim/themes/*/slim.theme | sort | awk -F/ '{ print $6 }') |
al@14601 | 111 echo $list | tr ' ' ','; exit 0 ;; |
al@14601 | 112 g) |
al@14601 | 113 get_current; exit 0 ;; |
al@14601 | 114 s) |
al@14601 | 115 set_theme "$OPTARG" ;; |
al@14601 | 116 f) |
al@14601 | 117 forget_theme "$OPTARG" ;; |
al@14601 | 118 V) |
al@14601 | 119 echo $VERSION; exit 0 ;; |
al@14601 | 120 h) |
al@14601 | 121 help; exit 0 ;; |
al@14601 | 122 t) |
al@14601 | 123 i18n $LANG; exit 0 ;; |
al@14601 | 124 T) |
al@14601 | 125 i18n $OPTARG; exit 0 ;; |
al@14601 | 126 *) |
al@14601 | 127 if [ x$OPTARG == xs -o x$OPTARG == xf -o x$OPTARG == xT ]; then |
al@14601 | 128 echo "Option \"$OPTARG\" requires an argument." |
al@14601 | 129 else |
al@14601 | 130 [ x$OPTARG != x ] && echo "Illegal option \"$OPTARG\"." |
al@14601 | 131 fi |
al@14601 | 132 echo "$ME -h for help."; exit 1 ;; |
al@14601 | 133 esac |
al@14601 | 134 |
al@14601 | 135 help |