slitaz-tools view tazbox/tazbox @ rev 1037

tazbox: lxpolkit support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Oct 23 10:41:01 2021 +0000 (2021-10-23)
parents 09a408773b37
children
line source
1 #!/bin/sh
2 #
3 # SliTaz tiny GUI boxes for the desktop (su, logout, locale, etc)
4 # and as usual, please: KISS
5 #
6 # Copyright (C) 2011-2015 SliTaz GNU/Linux - GNU GPL v3
7 # - Christophe Lincoln <pankso@slitaz.org>
8 # - Aleksej Bobylev <al.bobylev@gmail.com>
9 #
11 . /lib/libtaz.sh
12 export TEXTDOMAIN='tazbox' # i18n
15 # Get SliTaz settings
17 . /etc/slitaz/slitaz.conf
20 # download dir (may be in a config file)
22 DOWNLOADS="$HOME/Downloads"
25 # some constants to be used inside functions
27 tmp='/tmp/keymap.list'
28 db='/usr/share/i18n/locales'
29 zi='/usr/share/zoneinfo/'
30 ztab="${zi}zone-mini.tab"
31 csv='/tmp/freegeoip.csv'
32 prncf=~/.config/slitaz/printer
35 #
36 # Functions
37 #
39 usage() {
40 newline; _ 'SliTaz tiny GUI boxes for the desktop'
42 newline; boldify $(_ 'Usage:')
43 echo " $(basename $0) [$(_n 'command')]"
45 newline; boldify $(_ 'Commands:')
46 optlist "\
47 usage $(_ 'Display this short help usage')
48 su $(_ 'Execute a command as super-user')
49 logout $(_ 'Desktop logout box with actions')
50 out $(_ 'Pipe a command output into a GTK window')
51 out-dl $(_ 'Pipe wget output into a GTK window')
52 locale $(_ 'Configure system language (root)')
53 keymap $(_ 'Configure system keymap (root)')
54 tz $(_ 'Configure system timezone (root)')
55 setup $(_ 'System initial setup (locale, keymap & timezone)')
56 new-file $(_ 'Create a new file or folder on the desktop')
57 all-apps $(_ 'Display icons of all installed applications')
58 notify $(_ 'Notify user with a desktop centered box')
59 tazapps $(_ 'Configure SliTaz default applications')
60 vnc $(_ 'Launch a framebuffer VNC viewer')
61 ssh $(_ 'Open a remote terminal')
62 print $(_ 'Print PDF or PS files on a network printer')"
63 newline
64 }
67 # try to find icon in .desktop files
69 find_icon() {
70 local_desktop=$(find $HOME/.local/share/applications \
71 -name ${1##*/}.desktop 2&>/dev/null | head -n1)
72 system_desktop=$(find /usr/share/applications \
73 -name ${1##*/}.desktop 2&>/dev/null | head -n1)
74 desktop="${local_desktop:-$system_desktop}"
75 [ "$desktop" ] && sed '/\[Desktop\ Entry\]/,/^\[/!d' $desktop | \
76 sed '/^Icon=/!d' | head -n1 | cut -d= -f2
77 }
80 # su frontend GUIs
82 su_main() {
83 CMD1="${1%% *}"; CMD2="$(echo "${1#* }" | sed 's|&|&amp;|g')"
84 : ${icon=$(find_icon $CMD1)}
85 icon="${icon:-dialog-password}"
87 yad --title="$(_n 'SliTaz admin password')" --window-icon=$icon \
88 --width=520 --on-top --center \
89 --image=$icon --image-on-top \
90 --text="$(_n 'Please enter root password (default root) to execute:')\n
91 <span foreground=\"red\"><tt><b>$CMD1</b> $CMD2</tt></span>\n" \
92 --form \
93 --field="$(_n 'Password:'):H" $PASSWD \
94 --field="$(_n 'Autosave password'):CHK" $CHECKED
95 }
98 su_error() {
99 icon='dialog-error'
100 yad --title="$(_n 'Error')" --window-icon=$icon \
101 --width=320 --on-top --center \
102 --image=$icon --image-on-top \
103 --text="\n<b>$(_n 'Error: wrong password!')</b>\n" \
104 --button="gtk-close:1"
105 }
108 # user may press cancel on download.
110 cancel_dl() {
111 if [ "$?" -eq 1 ]; then
112 _ "CANCEL"
113 rm -f $DOWNLOADS/$(basename $url)
114 fi
115 }
118 # output a command in a GTK window
120 output_command() {
121 : ${title=$(_n 'TazBox Output')}
122 : ${icon=dialog-information}
124 yad --title="$title" --window-icon="$icon" \
125 --geometry='600x220+0-24' --fore='#ffffff' --back='#000000' \
126 --text-info --fontname=monospace --wrap $opts \
127 --button='gtk-close:1'
128 }
131 # logout GUI function
133 logout_main() {
134 icon='/usr/share/pixmaps/slitaz-icon.png'
135 yad --title="$(_n 'SliTaz Logout')" --window-icon="$icon" \
136 --on-top --center --height='130' \
137 --image="$icon" --image-on-top \
138 --text="<b>$(_n 'SliTaz Logout - Please choose an action:')</b>" \
139 --always-print-result \
140 --button "$(_n 'Close X session')!system-log-out:4" \
141 --button "$(_n 'Reboot system')!system-reboot:3" \
142 --button "$(_n 'Shutdown system')!system-shutdown:2"
143 }
146 # logout functions with auto-confirmation
148 logout_confirm() {
149 timeout=5
150 case $1 in
151 exit) action="$(_n 'Closing the X session...')"; icon='system-log-out';;
152 reboot) action="$(_n 'Rebooting the system...')"; icon='system-reboot';;
153 halt) action="$(_n 'Shutting down the system...')"; icon='system-shutdown';;
154 *) exit;;
155 esac
156 warning="$(_ 'Selected action will be executed automatically in %s seconds.' "$timeout")"
157 yad --title="$(_n 'SliTaz Logout')" --window-icon="$icon" \
158 --on-top --center --width='300' --image="$icon" --image-on-top \
159 --text="<b>$action</b>\n\n$warning" \
160 --timeout $timeout --timeout-indicator=bottom \
161 --button "gtk-cancel:252" --button "gtk-ok:0"
162 [ "$?" -ne 252 ] || exit 0
163 }
166 # make logout menu in the right edge of LXPanel
168 mkmenu() {
169 # (re)make the menu button with the user log name
170 dd="$HOME/.local/share/desktop-directories"; mkdir -p "$dd"
171 echo -e "[Desktop Entry]\nType=Directory\nName=$(whoami)" > "$dd/user.directory"
173 # check the panel config file existence, copy from default config if needed
174 panels=$(find $HOME/.config/lxpanel -type f -name panel 2>/dev/null)
175 if [ -z "$panels" ]; then
176 mkdir -p "$HOME/.config/lxpanel"
177 cp -a /etc/skel/.config/lxpanel/* "$HOME/.config/lxpanel"
178 fi
180 for panel in $panels; do
181 conf=$(tr '\n' '`' < $panel | sed 's|Plugin|\n&|g') # each plugin on its own line
182 if fgrep -q 'user.directory' "$panel"; then
183 # if menu already exists - shrink it to '@@@'
184 newconf=$(echo "$conf" | sed 's|.*user\.directory.*$|@@@|')
185 else
186 # otherwise do nothing
187 newconf="$conf"
188 fi
189 menu=$(cat <<EOT
190 Plugin {
191 type = menu
192 Config {
193 name=user.directory
194 image=avatar-default
195 tintcolor=#33230D
196 item {
197 image=system-log-out-panel
198 name=$(_ 'Close X session')
199 action=tazbox logout exit
200 }
201 item {
202 image=system-reboot-panel
203 name=$(_ 'Reboot system')
204 action=tazbox logout reboot
205 }
206 item {
207 image=system-shutdown-panel
208 name=$(_ 'Shutdown system')
209 action=tazbox logout halt
210 }
211 }
212 }
214 EOT
215 )
216 # rebuild the menu: change '@@@' to the menu content
217 echo "$newconf" | \
218 awk -vmenu="$menu" '{if ($1=="@@@") {printf ("%s\n\n", menu)} else {print}}' | \
219 tr '`' '\n' > $panel
220 done
221 }
224 # generate keymap list
226 gen_kmap_list() {
227 echo > $tmp
228 cd /usr/share/kbd/keymaps/i386
229 # we first need a list to sort and then use \n for Yad list.
230 for i in $(find -type f | sed '/include/d; s|./||'); do
231 echo "$(basename $i .map.gz)|$(dirname $i)" >> $tmp
232 done
233 }
236 # Initial Config functions
238 setup_main() {
239 icon='preferences-desktop-locale'
240 gen_kmap_list
241 locale=$(ls -1 $db 2> /dev/null | grep ^[a-z][a-z]_[A-Z][A-Z] | tr "\n" "!")
242 keymap=$(cat $tmp | sort | tr "\n" "!")
243 timezone=$(find $zi -type f | sed s,$zi,,g | grep -v -F '.tab' | tr "\n" "!")
244 yad --title="$(_n 'SliTaz Initial Setup')" --window-icon=$icon \
245 --width='500' \
246 --image="$icon" --image-on-top \
247 --text="<big>$(_n 'Here you can set your preferences \n for <b>locale, keymap and timezone</b>.')</big>" \
248 --form \
249 --field "$(_n 'Locale'):CB" $locale \
250 --field "$(_n 'Keymap'):CB" $keymap \
251 --field "$(_n 'Timezone'):CB" $timezone
252 }
255 setup() {
256 choices=$(setup_main)
257 locale=$( echo $choices | cut -d'|' -f1)
258 keymap=$( echo $choices | cut -d'|' -f2)
259 timezone=$(echo $choices | cut -d'|' -f3)
260 [ -n "$locale" ] && tazlocale init $locale
261 [ -n "$keymap" ] && tazkeymap init $keymap
262 [ -n "$timezone" ] && echo $timezone > /etc/TZ
263 }
266 #
267 # Locale functions
268 #
270 locale_main() {
271 icon='preferences-desktop-locale'
272 for locale in $(ls -1 $db 2> /dev/null | grep '[a-z]_[A-Z]'); do
273 desc=$(fgrep -m1 title $db/$locale | cut -d'"' -f2)
274 ll_CC=${locale%%@*}
275 echo -e "${ll_CC##*_}\n$locale\n$desc"
276 done | \
277 yad --title="$(_n 'SliTaz locale')" --window-icon="$icon" \
278 --width='600' --height='380' --sticky --on-top --center \
279 --image="$icon" --image-on-top \
280 --text="<b>$(_n 'Language configuration')</b> \
281 \n\n$(_ 'Tip: manage locales list by installing/removing locale packages.')" \
282 --list --column="$(_n 'Flag'):IMG" --column $(_n 'Name') \
283 --column $(_n 'Description') \
284 --print-column='2' --separator='' \
285 --button="$(_n 'Manage')!document-properties:2" \
286 --button="gtk-cancel:1" --button="gtk-ok:0"
287 }
290 locale() {
291 locale=$(locale_main)
292 # Deal with --button values
293 case $? in
294 2) tazbox manage_i18n main ;;
295 1) exit 0 ;;
296 *) continue ;;
297 esac
298 # System language configuration.
299 if [ "$locale" ]; then
300 tazlocale $locale
301 tazbox notify "$(_ 'Locale was set to %s' "$locale")" \
302 preferences-desktop-locale 3
303 fi
304 }
307 # Keymap functions
309 keymap_main() {
310 icon='preferences-desktop-keyboard'
311 gen_kmap_list
312 for i in $(sort $tmp); do
313 echo "$i" | tr '|' '\n'
314 done | \
315 yad --title="$(_ 'SliTaz keymap')" --window-icon=$icon \
316 --width=500 --height=380 --sticky --on-top --center \
317 --image=$icon --image-on-top \
318 --text="<b>$(_n 'Keyboard configuration')</b>" \
319 --list --column $(_n 'Keymap') --column $(_n 'Type') \
320 --print-column=1 --separator=''
321 rm -f $tmp
322 }
325 keymap() {
326 keymap=$(keymap_main)
327 # Deal with --button values
328 [ "$?" -eq 1 ] && exit 0
329 # System keymap configuration
330 [ -n "$keymap" ] && tazkeymap $keymap
331 }
334 # Free GeoIP service
335 # Response: IP,CountryCode,CountryName, ...
337 geoip() {
338 # freegeoip.net can be in the blocked hosts list. Return only correct answer or nothing
339 [ ! -e $csv ] && wget -q -T3 -O - http://freegeoip.net/csv/ 2&>/dev/null | \
340 grep '[0-9.]*,.*,.*,.*,.*,.*,.*,.*,[0-9.]*,[0-9.]*' > $csv
341 [ -e $csv ] && cut -d, -f2 $csv
342 }
345 #
346 # TZ functions
347 #
350 # list of all existing available locations for country
352 tz_list() {
353 find $zi | \
354 grep -E "$(awk -F$'\t' -vv="$1" '{if ($1 == v || $2 ~ v) print $2}' $ztab | tr ' ' '|')" | \
355 grep -v -E "posix|right" | \
356 sed 's|.*/||g' | sort
357 }
360 # ask for confirmation only if we have what to choose
362 tz_suggest() {
363 CountryCode=$(geoip)
364 if [ -n "$CountryCode" ]; then
365 if [ -n "$(tz_list $CountryCode)" ]; then
366 CountryName=$(cut -d, -f3 $csv)
367 yad --title="$(_ 'SliTaz TZ')" --window-icon="$icon" \
368 --on-top --center \
369 --image="$CountryCode" --image-on-top \
370 --text="$(_ 'Suggested location:') <b>$CountryName</b>\n
371 $(_ 'Are you agreed?')" \
372 --button='gtk-yes:0' --button='gtk-no:1'
373 [ "$?" -eq 0 ] && echo $CountryCode
374 fi
375 fi
376 }
379 tz_select() {
380 case x$1 in
381 x)
382 # first pass - country
383 tmpcc=$(mktemp)
385 for tzfile in $(find $zi -type f -regex '.*info/[ABCEIMP].*'); do
386 grep -m1 $(basename $tzfile) $ztab
387 done | cut -d$'\t' -f1 | sort -u > $tmpcc
389 while read CC; do
390 cat << EOT
391 $CC
392 $CC
393 $(grep -m1 "$CC " ${zi}iso3166.tab | cut -d$'\t' -f2 | sed 's|\&|&amp;|g')
394 EOT
395 done < $tmpcc | \
396 yad --title="$(_ 'SliTaz TZ')" --window-icon="$icon" \
397 --width='500' --height='380' --on-top --center \
398 --image="$icon" --image-on-top \
399 --text="<b>$(_ 'TimeZone Configuration')</b> \
400 \n$(_ 'Select country and press "Forward" or manually select timezone file.') \
401 \n\n$(_ 'Tip: manage timezones list by installing/removing locale packages.')" \
402 --list \
403 --column="$(_n 'Flag'):IMG" --column=$(_n 'Code') --column=$(_n 'Country') \
404 --button="$(_n 'Manage')!document-properties:4" \
405 --button="$(_n 'Manual')!gtk-index:2" \
406 --button="gtk-go-forward:0" \
407 --button="gtk-cancel:1" --always-print-result \
408 --print-column='2' --separator=''
409 ;;
410 xindex)
411 # manual selection of file with timezone info
412 yad --title="$(_ 'SliTaz TZ')" --window-icon="$icon" \
413 --width='500' --on-top --center \
414 --image="$icon" --image-on-top \
415 --text="<b>$(_ 'TimeZone Configuration')</b>\n$(_ 'Select time zone')" \
416 --form --field=":FL" ${zi}UTC --separator='' | \
417 sed "s|$zi||"
418 ;;
419 *)
420 # second pass - city/place
421 list=$(tz_list $1)
422 icon="$1"
423 if [ $(echo "$list" | wc -l) != 1 ]; then
424 echo "$list" | \
425 yad --title="$(_ 'SliTaz TZ')" --window-icon="$icon" \
426 --width='500' --height='380' --on-top --center \
427 --image="$icon" --image-on-top \
428 --text="<b>$(_ 'TimeZone Configuration')</b>\n$(_ 'Select location')" \
429 --list --column $(_n 'Location/City') --separator=''
430 else
431 echo $list
432 fi
433 ;;
434 esac
435 }
438 tz() {
439 icon='preferences-system-time'
440 arg=$(tz_suggest)
442 timezone=$(tz_select $arg)
443 case $? in
444 1) exit 0 ;;
445 0)
446 [ -n "$timezone" ] && timezone=$(tz_select "$timezone")
447 [ -z "$timezone" ] && exit 0
448 timezone=$(find $zi -name $timezone | grep -v -E "posix|right" | \
449 sed "s|$zi||")
450 ;;
451 2) timezone=$(tz_select "index") ;;
452 4) tazbox manage_i18n main;;
453 esac
455 [ -z "$timezone" ] && exit 0
456 echo $timezone > /etc/TZ
457 export TZ=$timezone
458 tazbox notify "$(_ 'TimeZone was set to %s' "$timezone")" $icon 3
459 rm -f $tmpcc
460 }
463 #
464 # Manage i18n packages
465 #
468 # if installed
470 if_installed() {
471 [ -d "$INSTALLED/$1" ]
472 }
475 # get package's description, install flag and sizes
477 desc_etc() {
478 if grep -q "^$1"$'\t' "$PKGS_DB/installed.info"; then
479 echo 'TRUE' >> $PKGS_LIST; echo $1 >> $ORIG_LIST
480 else
481 echo 'FALSE' >> $PKGS_LIST
482 fi
483 awk -F$'\t' -vp="$1" '
484 ($1==p){
485 split($7, s, " ");
486 printf "%s\n%s\n%s\n%s\n", $1, $4, s[1], s[2];
487 }' "$PKGS_DB/packages.info" >> $PKGS_LIST
488 }
491 # remove temp
493 rm_temp() {
494 rm -f $PKGS_LIST $ORIG_LIST $ANSWER $NEW_LIST $LIST1 $LIST2
495 }
498 # install/remove locale packages
500 manage_i18n() {
501 PKGS_LIST=$(mktemp)
502 ORIG_LIST=$(mktemp)
503 ANSWER=$(mktemp)
504 NEW_LIST=$(mktemp)
505 LIST1=$(mktemp)
506 LIST2=$(mktemp)
507 PINFO="$PKGS_DB/packages.info"
509 if [ ! -e "$PINFO" ]; then
510 icon='dialog-warning'
511 yad --title="$(_n 'Manage locale packages')" --window-icon="$icon" \
512 --width='400' --on-top --center \
513 --image="$icon" --image-on-top \
514 --text="$(_n 'Please, recharge packages database.')" \
515 --button="$(_n 'Recharge list')!view-refresh:2" \
516 --button="gtk-cancel:1"
518 case "$?" in
519 1) rm_temp; return;;
520 2) tazbox recharge;;
521 esac
522 fi
524 tazbox notify "$(_ 'Please wait')" appointment-soon &
526 for i in $(awk -F$'\t' '$1~/^locale-[a-z_A-Z]+$/{print $1}' $PINFO); do
527 desc_etc $i
528 done
530 if [ "$1" != 'main' ]; then
531 for i in $(awk -F$'\t' '$1~/^locale-[a-z_A-Z]+-extra$/{print $1}' $PINFO); do
532 desc_etc $i
533 done
535 if if_installed libQtCore; then
536 for i in $(awk -F$'\t' '$1~/^qt-locale/{print $1}' $PINFO); do
537 desc_etc $i
538 done
539 fi
541 if if_installed razorqt; then
542 for i in $(awk -F$'\t' '$1~/^razorqt-locale/{print $1}' $PINFO); do
543 desc_etc $i
544 done
545 fi
547 if if_installed firefox; then
548 for i in $(awk -F$'\t' '$1~/^firefox-langpack/{print $1}' $PINFO); do
549 desc_etc $i
550 done
551 fi
553 if if_installed thunderbird; then
554 for i in $(awk -F$'\t' '$1~/^thunderbird-langpack/{print $1}' $PINFO); do
555 desc_etc $i
556 done
557 fi
559 if if_installed squirrelmail; then
560 for i in $(awk -F$'\t' '$1~/^squirrelmail-[a-z][a-z][_-]/{print $1}' $PINFO); do
561 desc_etc $i
562 done
563 fi
565 if if_installed aspell; then
566 for i in $(awk -F$'\t' '$1~/^aspell-[a-z][a-z]_?[A-Z]?[A-Z]?$/{print $1}' $PINFO); do
567 desc_etc $i
568 done
569 fi
571 OTHER_LOCALE="gnome-commander|-i18n gnome-vfs|-i18n gpa|-langpack \
572 gucharmap|-i18n lxterminal|-locales lyx|-locales rox-filer|-locales \
573 ufraw|-locales qupzilla|-locales"
574 for i in $OTHER_LOCALE; do
575 if if_installed ${i%%|*}; then desc_etc ${i/|/}; fi
576 done
577 fi
579 icon='preferences-desktop-locale'
580 {
581 yad --title="$(_n 'Manage locale packages')" --window-icon="$icon" \
582 --width='600' --height='400' --on-top --center \
583 --image="$icon" --image-on-top \
584 --text="$(_n 'Check only locale packages you need and press "Install/Remove".')" \
585 --list --multiple --ellipsize='END' --expand-column='3' \
586 --column="$(_n 'Inst.'):CHK" --column="$(_n 'Package Name'):TEXT" \
587 --column="$(_n 'Description'):TEXT" --column="$(_n 'Size'):TEXT" \
588 --column="$(_n 'Installed'):TEXT" \
589 --button="$(_n 'Recharge list')!view-refresh:4" \
590 --button="$(_n 'Install/Remove')!gtk-execute:2" \
591 --button="gtk-cancel:1" \
592 --print-all
593 } < $PKGS_LIST > $ANSWER
595 case "$?" in
596 1) rm_temp; exit 0;;
597 4) tazbox recharge; rm_temp; tazbox manage_i18n; exit 0;;
598 esac
600 grep -e 'TRUE' $ANSWER | cut -d'|' -f2 > $NEW_LIST
602 # check difference between ORIG_LIST and NEW_LIST
603 sort -o $LIST1 $ORIG_LIST
604 sort -o $LIST2 $NEW_LIST
605 DIFF=$(diff $LIST1 $LIST2 | sed '/---/d;/+++/d;/@@/d')
606 if [ -z "$DIFF" ]; then rm_temp; exit 0; fi
608 # output log to gtk window
609 title="$(_n 'TazPkg log')"; icon='system-software-update'; opts='--tail'
610 {
611 for pkg in $(echo "$DIFF" | grep -e '^-' | sed 's|^-||g'); do
612 _ 'REMOVE: %s' "$pkg"
613 yes | tazpkg -r $pkg --output='raw'
614 done
615 for pkg in $(echo "$DIFF" | grep -e '^+' | sed 's|^+||g'); do
616 _ 'INSTALL: %s' "$pkg"
617 tazpkg -gi $pkg --output='raw'
618 done
619 echo -e "\n\n$(_n 'Done!')\n"
620 } | output_command
621 rm_temp
622 }
626 # New file functions
628 newfile_main() {
629 icon='document-new'
630 yad --title="$(_n 'New file')" --window-icon="$icon" \
631 --width='460' --height='160' --on-top --center \
632 --image="$icon" --image-on-top \
633 --icon="$icon" \
634 --text="<b>$(_n 'Create a new file or folder on your desktop')</b>" \
635 --entry --entry-label="$(_n 'File name')" \
636 --ricon='edit-clear' \
637 --always-print-result \
638 --button="$(_n 'SHell script')!application-x-shellscript:4" \
639 --button="$(_n 'Folder')!folder:3" \
640 --button="$(_n 'File')!empty:2" \
641 --button='gtk-cancel:1'
642 }
645 newfile() {
646 file=$(newfile_main)
647 ret=$?
648 [ -z "$file" ] && exit 0
649 case $ret in
650 4)
651 cat > "$HOME/Desktop/$file" << EOT
652 #!/bin/sh
653 #
655 EOT
656 chmod +x "$HOME/Desktop/$file" ;;
657 3) mkdir -p "$HOME/Desktop/$file" ;;
658 2) touch "$HOME/Desktop/$file" ;;
659 1) exit 0 ;;
660 esac
661 }
664 # All applications
666 all_apps() {
667 icon='user-bookmarks'
668 yad --title="$(_n 'All Applications')" --window-icon="$icon" \
669 --width='400' --height='400' \
670 --icons --compact \
671 --read-dir='/usr/share/applications' \
672 --button='gtk-close:0'
673 }
676 # Ask root permissions for system settings
678 ask_root() {
679 if [ "$(id -u)" -ne 0 ]; then
680 exec tazbox su $0 $@
681 exit 0
682 fi
683 }
686 # VNC gui
688 vnc_main() {
689 icon='video-display'
690 yad --title="$(_n 'Framebuffer VNC viewer')" --window-icon="$icon" \
691 --width='250' --height='160' --on-top --center \
692 --image="$icon" --image-on-top --icon="$icon" \
693 --form \
694 --text="<b>$(_n 'Remote display connection')</b>" "localhost 5900" \
695 --field="$(_n 'VNC Server')" \
696 --field="$(_n 'Via a SSH tunnel'):CHK" \
697 --always-print-result \
698 --button="$(_n 'On this console'):1" \
699 --button="$(_n 'In a new console'):0"
700 }
703 # SSH gui
705 ssh_main() {
706 icon='xterm'
707 yad --title="$(_n 'Remote connection')" --window-icon="$icon" \
708 --width='250' --height='180' --on-top --center \
709 --image="$icon" --image-on-top --icon="$icon" \
710 --form \
711 --text="<b>$(_n 'Remote terminal connection')</b>" "user@host:port" \
712 --field="$(_n 'Server')" \
713 --field="$(_n 'Password'):H" \
714 --field="$(_n 'SSH Keys'):MFL" \
715 --field="$(_n 'SSH Proxy')" \
716 --field="$(_n 'Telnet protocol (instead of SSH)'):CHK" \
717 --always-print-result
718 }
721 # Network printer gui
723 printer0_main() {
724 icon='printer'
725 yad --title="$(_n 'Printer server')" --window-icon="$icon" \
726 --width='250' --height='180' --on-top --center \
727 --image="$icon" --image-on-top --icon="$icon" \
728 --form \
729 --text="<b>$(_n 'Network printer server')</b>" \
730 --field="$(_n 'Printer IP'):CB" 0.0.0.0!$(ifconfig | sed '/inet6\? addr/!d;s|[^:]*: *||;s| .*||;s|^127|^&|' | xargs | sed 's| |!|g') \
731 "9100" --field="$(_n 'Port')" \
732 --field="$(_n 'Device'):CB" $(ls /dev/*lp? | xargs | sed 's| |!|g') \
733 --always-print-result
734 }
737 printer1_main() {
738 icon='printer'
739 yad --title="$(_n 'Remote printer')" --window-icon="$icon" \
740 --width='250' --height='180' --on-top --center \
741 --image="$icon" --image-on-top --icon="$icon" \
742 --form \
743 --text="<b>$(_n 'Remote PDF or PS printer')</b>" "192.168.0.254" \
744 --field="$(_n 'Printer IP')" "9100" \
745 --field="$(_n 'Port')" \
746 $([ "$(ls /dev/*lp? 2> /dev/null)" ] && echo --button "$(_ 'Server'):2") \
747 --button "gtk-cancel:1" --button "gtk-ok:0" \
748 --always-print-result
749 }
752 # Parse printer configuration file
754 conf_printer()
755 {
756 awk 'BEGIN { state = -1 }
757 {
758 if (state < 0) {
759 if (/@PJL INFO VARIABLES/) state=0
760 }
761 else {
762 if (state == 0) {
763 printf "%s " $0
764 sub(/.*\[/,"")
765 state=$0 + 0
766 }
767 else {
768 printf "%s " $1
769 state--
770 }
771 if (state == 0) print ""
772 }
773 }' < $prncf
774 }
776 var_printer()
777 {
778 while read key name; do
779 conf_printer | grep "^ *$key=" | grep -v '\[1 ' | \
780 if [ "$1" ]; then
781 #[ "$key=$1" = "COPIES=1" ] ||
782 echo "@PJL SET $key=$1"
783 else
784 awk -vn=$name '{
785 sub(/.*=/,"")
786 if (/ RANGE\]/) {
787 sub(/ \[.*\] /,"!")
788 sub(/ /,"..")
789 print "--field=" n ":NUM " $0 "!1!0"
790 }
791 else if (/ ENUMERATED\]/) {
792 def=$0
793 sub(/ .*/,"",def)
794 sub(/.*\] /,"")
795 gsub(/ /,"!")
796 pos=index($0,def)
797 print "--field=" n ":CB " substr($0,0,pos-1) "^" substr($0,pos)
798 }
799 }'
800 fi
801 shift
802 done <<EOT
803 COPIES $(_n 'Number')
804 RESOLUTION $(_n 'Resolution')
805 ORIENTATION $(_n 'Orientation')
806 PAPER $(_n 'Paper')
807 LPAPERSOURCE $(_n 'Source')
808 DUPLEX $(_n 'Twosided')
809 BINDING $(_n 'Binding')
810 ECONOMODE $(_n 'Eco-Mode')
811 DENSITY $(_n 'Density')
812 MANUALFEED $(_n 'Manual-Feed')
813 EOT
814 }
817 # File print gui
819 printer2_main() {
820 icon='printer'
821 support=
822 filter=
823 grep -q PDF $prncf && support="PDF" && filter="*.pdf *.PDF "
824 if grep -q POSTSCRIPT $prncf ; then
825 [ "$support" ] && support="$support or PostScript" ||
826 support="PostScript"
827 filter="${filter}*.ps *.eps *.PS *.EPS"
828 fi
829 yad --title="$(_n 'Print %s files' "$support")" --window-icon="$icon" \
830 --width='250' --height='180' --on-top --center \
831 --image="$icon" --image-on-top --icon="$icon" \
832 --form \
833 --text="<b>$(_n 'Print %s files' "$support")</b>" "" \
834 --field="$(_n 'Files'):MFL" \
835 --file-filter="$(_ 'All printable files')|$filter" \
836 --file-filter="$(_ 'All files')|*" \
837 $(var_printer) \
838 --button "$(_ 'Printer'):2" \
839 --button "gtk-cancel:1" --button "gtk-ok:0" \
840 --always-print-result
841 }
843 printer_server() {
844 while true; do
845 nc -l -p $2 $1 < $3 > $3
846 done
847 }
849 printer_query() {
850 echo -e "\033%-12345X@PJL"
851 echo "@PJL INFO CONFIG"
852 echo "@PJL INFO VARIABLES"
853 echo -e "\033%-12345X"
854 sleep 5
855 }
857 printer() {
858 local tmpprncf=$prncf
859 while true; do
860 if [ ! -s "$tmpprncf" ]; then
861 while true; do
862 ip="$(printer1_main)"
863 case "$?" in
864 0) break ;;
865 1) return ;;
866 esac
867 ip="$(printer0_main)"
868 [ $? = 0 ] && $0 prnsvr ${ip//|/ }
869 done
870 echo -e "${ip//|/ }\n" > $prncf
871 printer_query | nc ${ip//|/ } | sed 's|\r||;s|'$'^\f''|\n|g' >> $prncf
872 fi
873 if ! grep -q PDF$ $prncf && ! grep -q POSTSCRIPT$ $prncf; then
874 yad --title="$(_n 'Print')" --window-icon="$icon" \
875 --width='280' --height='80' --on-top --center \
876 --image="$icon" --image-on-top --icon="$icon" \
877 --text="Your printer doesn't support PDF or POSTSCRIPT" \
878 --button="$(_n 'Remove'):0" \
879 --button="$(_n 'Quit'):1"
880 [ $? -eq 0 ] && rm -f $prncf
881 return
882 fi
883 tmpprncf=
884 result="$(printer2_main)"
885 case "$?" in
886 0) break ;;
887 1) return ;;
888 esac
889 done
890 for file in $(echo ${result%%|*} | sed 's|!| |g'); do
891 case $(sed 'y/pdfsaobe/PDFSAOBE/;q' "$file") in
892 %PDF*) LG="PDF" ;;
893 %!PS-ADOBE*) LG="POSTSCRIPT" ;;
894 esac
895 if grep -q $LG$ $prncf; then
896 {
897 echo -e "\033%-12345X@PJL"
898 var_printer $(echo ${result#*|} | sed 's/|/ /g')
899 echo "@PJL ENTER LANGUAGE = $LG"
900 cat $file
901 echo -e "\033%-12345X"
902 sleep 5
903 } | nc $(sed 1q $prncf)
904 else
905 yad --title="$(_n 'Print')" --window-icon="$icon" \
906 --width='280' --height='80' --on-top --center \
907 --image="$icon" --image-on-top --icon="$icon" \
908 --text="Your printer can't print the $LG file $file"
909 fi
910 done
911 }
914 video() {
915 icon='video-x-generic'
917 # Get switchs
918 tazwebargs="--notoolbar"
919 while true ; do
920 case "$1" in
921 --fullscreen) tazwebargs="$tazwebargs --kiosk"
922 dpmstimeout=$(xset q | grep timeout | cut -d' ' -f5) ;;
923 --loop) loop="loop" ;;
924 *) break
925 esac
926 shift
927 done
929 # Get filename
930 [ "$1" ] && file="$PWD/$(basename "$1")"
931 [ "${1:0:1}" = "/" ] && file="$1"
932 [ -s "$file" ] || file="$(yad --file --width='600' --height='500' --add-preview \
933 --window-icon $icon --title "$(_ 'Select the video file')" --center \
934 --file-filter="$(_ 'All video files')|*.mp4 *.m4v *.webm *.ogg *.ogv *.flv *.avi *.3gp" \
935 --file-filter="$(_ 'All files')|*")"
936 [ -s "$file" ] || return
938 # Extra parameters
939 text=
940 attr='autoplay="true"'
941 for i in jpg jpeg ; do
942 [ -s "${file%.*}.$i" ] &&
943 attr="poster=\"file://${file%.*}.$i\"" && break
944 done
945 IFS=$'\n'
946 for i in ${file%.*}_${LANG%%[._]*}.vtt ${file%.*}.vtt ; do
947 [ -s $i ] && text="
948 <track kind=\"captions\" src=\"file://$i\" srclang=\"${LANG%%[._]*}\" default>"
949 done
951 # Build the html5 page
952 tmp=/tmp/video-player-$$.html
953 cat > $tmp <<EOT
954 <html>
955 <head>
956 <meta charset="UTF-8">
957 <title>$(basename "$file")</title>
958 <style>
959 body{background:#000;margin:0}
960 a{color:#29F}
961 div{color:#FFF;position:absolute;bottom:2em;left:0;right:0;text-align:center}
962 </style>
963 </head>
964 <body>
965 <video width="100%" height="100%" src="file://$file" controls $attr$loop>$text
966 <div>$(_ 'Unsupported video file format.')<br>
967 $(IFS=$'\n'; _ 'Retry with %s, %s, %s, %s, %s or %s.' \
968 $(printf '<a href="http://127.0.0.1:82/user/pkgs.cgi?info=%s">%s</a>\n' \
969 vlc VLC gnome-mplayer 'GNOME MPlayer' mplayer MPlayer gxine gxine xine-ui xine ffplay ffplay))
970 </div>
971 </video>
972 </body>
973 </html>
974 EOT
975 unset IFS
976 [ -n "$dpmstimeout" ] && xset dpms 0 0 0 s 0 0
977 tazweb $tazwebargs file://$tmp || browser file://$tmp
978 [ -n "$dpmstimeout" ] && xset dpms $dpmstimeout $dpmstimeout $dpmstimeout s $dpmstimeout $dpmstimeout
979 rm -f $tmp
980 }
983 newvt()
984 {
985 ask_root newvt $@ || return
986 openvt -sw $@
987 deallocvt
988 }
991 vnc() {
992 server=$(vnc_main)
993 status=$?
994 # Deal with --button values
995 [ "$server" ] || return
996 case "$server" in
997 *TRUE\|) fbvnc=sshfbvnc ;;
998 *) fbvnc=fbvnc ;;
999 esac
1000 case "$status" in
1001 1) $fbvnc ${server%%|*} ;;
1002 0) newvt $fbvnc ${server%%|*} ;;
1003 esac
1007 ssh() {
1008 IFS='|'; set -- $(ssh_main) ; unset IFS
1009 export TERM=sakura; [ "$(which $TERM)" ] && XTERM=$TERM || XTERM=xterm
1010 [ -n "$2" ] && export DROPBEAR_PASSWORD="$2"
1011 s=${1#*@}; k="${3:+-i ${3//!/ -i }}"
1012 case "$4$5" in
1013 TRUE) $XTERM -e "telnet ${s/:/ }" ;;
1014 *RUE) dbclient $k -B $s $4 ;;
1015 *) export DBPROXY="$4"; sshx $k $1 ;;
1016 esac
1021 # Commands
1024 case "$1" in
1025 su)
1026 shift
1027 # Don't show dialog if we are root
1028 [ "$(id -u)" -eq 0 ] && exec "$@"
1030 # lxpolkit support
1031 [ -f "/var/run/ConsoleKit/pid" ] &&
1032 exec pkexec env XAUTHORITY=$XAUTHORITY DISPLAY=$DISPLAY "$@"
1034 SU_CMD="$@"
1035 SUBOX_CONF="$HOME/.config/slitaz/subox.conf"
1037 # Check if a password has been saved before launching main dialog
1038 if [ -s "$SUBOX_CONF" ]; then
1039 PASSWD="$(cat $SUBOX_CONF)"
1040 CHECKED='TRUE'
1041 fi
1043 # Display the main dialog (ask for password)
1044 main="$(su_main "$SU_CMD")"
1046 # Deal with --button values and exit if cancelled to avoid erasing
1047 # saved password.
1048 [ "$?" -eq 1 ] && exit 0
1050 # Save or erase Autosaved password
1051 if [ $(echo "$main" | cut -d"|" -f2) = 'TRUE' ]; then
1052 echo "$main" | cut -d"|" -f1 > $SUBOX_CONF
1053 chmod 0600 $SUBOX_CONF
1054 else
1055 cat /dev/null > $SUBOX_CONF
1056 fi
1058 # Try to login & execute. If password is wrong execute error dialog
1059 SU_CMD_QUOTED="$(echo "$SU_CMD" | sed 's|&|\\&|g')"
1060 echo $main | cut -d"|" -f1 | su -c "$SU_CMD_QUOTED &" || su_error
1061 ;;
1063 logout)
1064 # Logout window with actions
1065 if [ -n "$2" ]; then
1066 answer="$2"
1067 logout_confirm $answer
1068 else
1069 logout_main; answer=$?
1070 fi
1072 # Deal with --button values
1073 # DE and WM started with a custom -session script should export
1074 # XDG_CURRENT_DESKTOP
1075 case $answer in
1076 4|exit)
1077 case $XDG_CURRENT_DESKTOP in
1078 LXDE)
1079 [ -n "$_LXSESSION_PID" ] && kill $_LXSESSION_PID
1080 [ "$DESKTOP_SESSION" = 'compiz' ] && killall compiz
1081 openbox --exit ;;
1082 openbox) openbox --exit ;;
1083 compiz) killall compiz ;;
1084 *)
1085 # Try to kill other WM that dont set XDG var.
1086 jwm -exit 2>/dev/null ;;
1087 esac ;;
1088 3|reboot)
1089 reboot || reboot -f ;;
1090 2|halt)
1091 poweroff ;;
1092 esac
1093 ;;
1095 out)
1096 # Pipe a command into a GTK window
1097 sed 's|\[.m||g; s|\[[0-9][0-9]*G| |g' | output_command
1098 ;;
1100 out-dl)
1101 # A tiny GTK window for Busybox wget output
1102 url="$2"; opts='--tail --button=gtk-cancel:1'
1103 icon='folder-download'; title="$(_ 'Downloading...')"
1104 [ -d $DOWNLOADS ] || mkdir -p $DOWNLOADS
1105 busybox wget -c -P $DOWNLOADS $url 2>&1 | output_command
1106 cancel_dl
1107 ;;
1109 locale)
1110 ask_root $@ && locale
1111 ;;
1113 keymap)
1114 ask_root $@ && keymap
1115 ;;
1117 tz)
1118 ask_root $@ && tz
1119 ;;
1121 manage_i18n)
1122 ask_root $@ && manage_i18n $2
1123 ;;
1125 recharge)
1126 ask_root $@; opts='--on-top'; output=raw tazpkg recharge | output_command
1127 ;;
1129 setup)
1130 ask_root $@ && setup
1131 ;;
1133 new-file)
1134 newfile
1135 ;;
1137 all-apps)
1138 all_apps
1139 ;;
1141 notify|-n)
1142 # On screen notification box.
1143 icon="$3"
1144 time="$4"
1145 [ -z "$icon" ] && icon='dialog-information'
1146 [ -z "$time" ] && time='4'
1147 yad --width='520' --height='80' --timeout="$time" --timeout-indicator='right' \
1148 --on-top --center --no-buttons --borders='12' --undecorated \
1149 --skip-taskbar --image="$icon" --image-on-top --text="<b>$2</b>"
1150 ;;
1152 tazapps)
1153 # Default applications configuration script. System wide config file
1154 # is /etc/slitaz/applications.conf and each user can have personal
1155 # settings. System wide for root and personal config for user.
1156 export CONFIG="$HOME/.config/slitaz/applications.conf"
1157 if [ "$(id -u)" -eq 0 ]; then
1158 [ ! -f $CONFIG ] || mv -f $CONFIG /etc/slitaz/applications.conf
1159 export CONFIG='/etc/slitaz/applications.conf'
1160 fi
1162 for a in FILE_MANAGERS BROWSERS EDITORS TERMINALS WINDOW_MANAGERS; do
1163 eval $(expr $a=$(echo $(LC_ALL=C tazx get-applist ${a%%S} \
1164 only-installed yad) | sed 's/ /!/g ; s/!!//g; s/ //g'))
1165 done
1167 # Missing file was created by slitaz_apps_conf function from tazx
1168 . $CONFIG
1170 icon='preferences-desktop-default-applications'
1171 eval $(yad --title="$(_n 'SliTaz default applications')" \
1172 --window-icon="$icon" --image="$icon" --image-on-top \
1173 --text="<b>$(_n 'SliTaz default applications configuration')</b>" \
1174 --form \
1175 --field="$(_n 'File manager:'):CBE" "$FILE_MANAGERS" \
1176 --field="$(_n 'Web browser:'):CBE" "$BROWSERS" \
1177 --field="$(_n 'Text editor:'):CBE" "$EDITORS" \
1178 --field="$(_n 'Terminal:'):CBE" "$TERMINALS" \
1179 --field="$(_n 'Window manager:'):CBE" "$WINDOW_MANAGERS" | \
1180 awk -F'|' '{printf "FILE_MANAGER=\"%s\"\nBROWSER=\"%s\"\nEDITOR=\"%s\"\
1181 TERMINAL=\"%s\"\nWINDOW_MANAGER=\"%s\"\n", $1, $2, $3, $4, $5}')
1183 sed '/FILE_MANAGER=/s|"\([^"]*\)"|"'$FILE_MANAGER'"|; \
1184 /BROWSER=/s|"\([^"]*\)"|"'$BROWSER'"|; \
1185 /EDITOR=/s|"\([^"]*\)"|"'$EDITOR'"|; \
1186 /TERMINAL=/s|"\([^"]*\)"|"'$TERMINAL'"|; \
1187 /WINDOW_MANAGER=/s|"\([^"]*\)"|"'$WINDOW_MANAGER'"|' \
1188 -i $CONFIG
1189 ;;
1191 gpl)
1192 yad --title='GNU General Public License' --window-icon='text-x-copying' \
1193 --geometry='650x500' \
1194 --image='/usr/share/pixmaps/gpl3.png' --image-on-top \
1195 --center \
1196 --text-info \
1197 --fontname='monospace' \
1198 --button 'OK' < /usr/share/licenses/gpl.txt
1199 ;;
1201 print)
1202 printer
1203 ;;
1204 prnsvr)
1205 shift
1206 printer_server $@ &
1207 ;;
1208 ssh)
1209 ssh
1210 ;;
1212 vnc)
1213 vnc
1214 ;;
1216 video)
1217 shift
1218 video "$@"
1219 ;;
1221 newvt)
1222 $@
1223 ;;
1225 mkmenu) $@ ;;
1227 *)
1228 usage
1229 ;;
1230 esac
1232 exit 0