#!/bin/bash
a=sfslinux@gmail.com 
v="180417"
#need: sfsusr ntf mnt_sfs sfs_event_rem 
value() { egrep -o "(^| )$1=[^ ]+" /proc/cmdline | cut -d= -f2; } #sfs
wget="sudo wget -c"
if [ "`value dir`" ];then #frugal
    [ -d /mnt/home ] && pra="/mnt/home/`value dir`/optional"
    [ -d "$pra" ] || pra= && pra1=true
fi
loader="mnt_sfs"
start="$@"
[ ! -f /etc/rc.d/PUPSTATE ] && losetup="sudo losetup -a" || losetup="losetup-FULL -a"
        inst="`$losetup |awk -F"(" '! /.squashfs\)/ {print $2}'|awk -F")" '{print $1}'` `awk -F= '!/.[ps]fs/ && !/\/changes=/ {print $1}' /sys/fs/aufs/si_*/br[0-9]*`"
#echo $inst;exit
#sudo="`which sudo`"
which sudo && sudo=sudo
[ "$sudo" ] && sudou="sudo -u `sfsusr`"
maxdepth=2
rep="/etc/sfs-get"
pth="/mnt/sd* /mnt/home/ "$HOME"/" ;[ -d "/media" ] && pth="/media/ /live/image/"

AF(){
if [  -f /etc/pacman.conf ] ;then
    krn1="_"
    for krn in `awk -F"overlay=" '{print $2}' /proc/cmdline |awk '{print $1}'|sed 's/,/ /g'` ;do
	krn="`basename $krn`" ; krn1="$krn1|$krn"
    done
    if [ -f /tmp/permanent_pfs_load.log ] ;then
        echo af
        inst="`$losetup |awk -F"(" '! /.squashfs\)/ {print $2}'|awk -F")" '{print $1}'|grep -v -f /tmp/permanent_pfs_load.log|egrep -v ''$krn1''`"
    else
	echo porteus=1 ;porteus=1 
	inst0="$inst"
	krn1="`cd /mnt && ls -1ad .*.[ps]fs|sed 's/^.//'`"
	krn2="`echo -n "$krn1" |tr "\n" "|"`"
	[ "$krn2" ] && inst="`echo "$inst"| egrep ''$krn2''`" || inst=
    fi
    
else
    echo puppyrus
    inst="`$losetup |awk -F"(" '! /.squashfs\)/ {print $2}'|awk -F")" '{print $1}'|grep -v -f /tmp/permanent_pfs_load.log`"
fi
#echo "inst=$inst $krn1" ;exit
}
[ "$1" != "-a" ] && AF

WG() {
if [ -f $1/$2 ] ;then 
    ntf -i "$1/$2 существует" &    
    $sudo $loader $1/$2  && $sudou sfsstart "$2"
    exit
fi

! `which sudo ` ping -c 1 -W 1 8.8.8.8 >/dev/null 2>&1 && (ntf -e "Нет подключения" "к интернет" &) && exit 
    dsk="`echo "$1" | grep $pth`"
    dsk="$dsk`echo "$1" | grep /live/image`"
    [ "$dsk" ] || echo pth=$pth
    tmp="`mktemp`"

if [ "`which yad`" ];then
    sudo wget-progress3 "$1" "$2" "$3" && $sudo $loader $1/$2
else echo "$wget -N -O $1/$2 $3  && $sudo $loader $1/$2 && sleep 3 && rm $tmp" >$tmp
    urxvt -e $sudo bash $tmp 
fi
    $sudou sfsstart "$2" 
}

TSTXXXXXX() {
	    status=$?
    	    if [ ${status} -eq 0 ]; then
    		ntf -i "$1" "успешно $2" &
	     $sudo pfsramfree &
    	    else 
    		[ "$m1" ] || m1="В некоторых системах невозможно подключение модуля, находящегося на RAM-диске. Перенесите его на физический носитель (жесткий диск) и подключите."
    		ntf -a "ОШИБКА!" "$m1" && exit 
	    fi
}

HLP() {
export MAIN_DIALOG='
<window title="Справка. '`basename $0`' v.'$v'" resizable="false"  icon-name="application-pfs">
<vbox>
 <vbox scrollable="true" hscrollbar-policy="2" width="500" height="350">
  <text use-markup="true"><label>
"
<b><big>sfs-get - менеджер <i>модулей.[ps]fs</i></big></b>

<b>Модуль</b> - программа со всем необходимым ей для работы (библиотеки и т.п.) находящаяся в модуле с сжимающей файловой системой <i>squashfs</i>

Содержимое модуля доступно только для чтения. Его можно просматривать, подключать и отключать. Отключать получится только модули, файлы которых не заняты системой.

Модуль подключается в определенный слой <b>AUFS</b> (вспомогательной файловой системы, образующей каскадно-объединённое монтирование для файловых систем Linux)

<b>AUFS</b> позволяет собрать итоговую файловую систему как слоеный пирог. Верхний слой 000 перекрывает слои с большими номерами.

<b>sfs-get</b> ищет программу в системе. 
    -Если находит - запускает. При наличие ключа <i>-s</i> запуск от имени <i>root</i>
    -Если не находит - ищет модуль на подключенных носителях <i>(maxdepth='$maxdepth')</i> и в репозиториях <i>'$rep'</i>
При нахождении предлагает загрузить , подключить и запустить.
    Например, можно делать ярлык для программы, которой нет в базовом модуле: <i>sfs-get doublecmd</i>

WWW репозиторий - модули, размещенные на ftp или http.
URL репозиторий - ссылки на файлообменники. Каждый может сделать свой.
"</label>
  </text>
 </vbox>
 <hbox>
     <text><label>Подробности (wiki):</label></text>
    <button>
     <input file stock="gtk-help"></input>
     <action>defaultbrowser http://wiki.puppyrus.org/setups/aufs</action>
     <label>AUFS</label>
    </button>
    <button>
     <input file stock="gtk-help"></input>
     <action>defaultbrowser http://wiki.puppyrus.org/soft/sfs-get</action>
     <label>SFS-get</label>
    </button>
    
     <text><label> ; </label></text>
    <button>
     <input file stock="gtk-quit"></input>
     <label>Выход</label>
     </button>
 </hbox>
</vbox>
</window>
'
ret="`gtkdialog --program=MAIN_DIALOG --center`"
}
#HLP;exit

DLG1() {
(sfs-get -p & ) && exit
exit
}

DLG2() {
if [ -z "$f" ] ;then
fmsg2="Введите имя (часть имени) модуля"
	export ok_box='
<window title="SFS-get. Менеджер модулей .pfs .sfs v.'$v'" resizable="true"  icon-name="application-pfs">
 <vbox width-request="550">

 <frame Поиск и подключение модуля:>
    <hbox>
'

[ "$pra" ] && ok_box=$ok_box'
    <checkbox tooltip-text="Поиск модулей в '$pra'">
	<label>в</label>
	<default>"'$pra1'"</default>
        <variable>pra1</variable>
    </checkbox>

    <button tooltip-text="Подключение модулей из 
'$pra'.">
     <input file stock="gtk-index"></input>
     <action>dmenu-sfs-get-opt &</action>
     <action>EXIT:exit 0</action>
     <label>/optional,</label>
    </button>
'

ok_box=$ok_box'
    <checkbox tooltip-text="Поиск модулей на подключенных
носителях (hdd, flash).">
	<label>локально,</label>
	<default>"'$loc'"</default>
        <variable>loc</variable>
    </checkbox>
'
[ "`egrep -v '^#' /etc/sfs-get/www.list`" ] && ok_box=$ok_box'
    <checkbox tooltip-text="Поиск модулей в www
репозитории /etc/sfs-get/www.list
Требуется интернет.">
	<label>в WWW репозитории</label>
	<default>"'$www'"</default>
        <variable>www</variable>
    </checkbox>
<pixmap><height>32</height><width>32</width><input file stock="gtk-find"></input></pixmap>
</hbox>
'

ok_box=$ok_box'
<hbox>
<pixmap><height>32</height><width>32</width><input file icon="application-pfs"></input></pixmap>
<pixmap><height>32</height><width>32</width><input file icon="application-sfs"></input></pixmap>
   <entry activates_default="true" width-request="350" is-focus="true" tooltip-text="'$fmsg2'">
         <variable>f</variable>
	 <input>echo "'$fmsg'"</input>
   </entry>

   <button can-default="true" has-default="true">
    <input file icon="gtk-find"></input>
    <action>EXIT:ok</action>
   </button>
    </hbox>
'

[ "`egrep -v '^$|^#' $rep/www.list`" ] && \
ok_box=$ok_box'
    <hbox width-request="0" space-fill="true" space-expand="false">
 <frame WWW репозиторий:>
  <hbox width-request="0" space-fill="true" space-expand="false">
'

ok_box=$ok_box'
    <button tooltip-text="Просмотр всех модулей из 
официальных WWW репозиториев 
'$rep'/www.list
Требуется интернет.">
     <input file icon="gtk-index"></input>
     <action>dmenu-sfs-get-rep &</action>
     <action>EXIT:exit 0</action>
     <label>просмотр</label>
    </button>

    <button tooltip-text="Изменить список репозиториев
и обновить списки модулей">
     <input file icon="gtk-edit"></input>
     <action>sudo defaulttexteditor /etc/sfs-get/www.list && sudo rm /tmp/mod_update/repolist.txt &</action>
     <label>изменить</label>
    </button>

   </hbox>
 </frame>
'

[ "`egrep -v '^$|^#' $rep/sfs.list`" ] && \
ok_box=$ok_box'
    <button tooltip-text="Просмотр всех модулей
из пользовательского
репозитория /etc/sfs-get/sfs.list">
     <action>dmenu-sfs-get+ &</action>
     <action>EXIT:exit 0</action>
     <label>User модули:</label>
    </button>
'

[ "`egrep -v '^$|^#' $rep/links.list`" ] && \
ok_box=$ok_box'
 <frame URL репозиторий:>
   <hbox>
    <button tooltip-text="Просмотр всех модулей из
пользовательского URL репозитория 
'$rep'/links.list.">
     <input file icon="gtk-index"></input>
     <action>dmenu-sfs-get-rep2 &</action>
     <action>EXIT:exit 0</action>
     <label>просмотр</label>
    </button>

    <button tooltip-text="Обновление списка модулей
через интернет">
     <input file icon="gtk-refresh"></input>
     <action>sfs-get-rep2 -u &</action>
     <action>EXIT:exit 0</action>
     <label>обновить</label>
    </button>
   </hbox>
 </frame>
'

ok_box=$ok_box'
    </hbox>
 </frame>
'

cd /mnt && ok_box=$ok_box'
 <frame Отключение модуля (001-верхний слой AUFS):>
   <hbox height-request="150">

			<tree headers_visible="true" auto-sort="true" sort-column="1" selected-row="0" selection-mode="3">
 				<variable>dir</variable>
				<label>Модуль |Слой|Расположение</label>'

AAA(){
for i in $inst ;do
#i2="`basename "$i"`			`dirname "$i"`"
#i2="`basename "$i"` | `dirname "$i"`"
i21="`basename "$i"`"
#i2="$i21 | `aufs-n|awk '/'$i21'/ {print $1}'` `dirname "$i"`"
#i2="$i21 | `grep -F "$i21="  /sys/fs/aufs/si_*/br[0-9]* | sed 's/^.*br\([0-9]\+\):.*$/\1/'` `dirname "$i"`"
i20="$(printf %03d "`grep -F "$i21=" /sys/fs/aufs/si_*/br[0-9]* |sed 's/^.*br\([0-9]\+\):.*$/\1/'`")"
i2="$i21 |$i20|`dirname "$i"`"
ok_box=$ok_box'
				<item>'$i2'</item>
'
done
}

BBB(){
aun=0
while true; do 
#    i="`cat /sys/fs/aufs/si_*/br$aun 2>/dev/null |sed 's/.pfs=r.*/.pfs/'`" || break
    i="`cat /sys/fs/aufs/si_*/br$aun 2>/dev/null`" || break
    [ "`echo "$i" |egrep '=rw$'`" ] && aun=$(expr $aun + 1) && continue
    aun=$(expr $aun + 1)
    [ "`echo "$i" |egrep '^/mnt/live/memory/images/'`" ] && continue
    echo "$i"
i2="`basename "$i"` | `dirname "$i"`"
ok_box=$ok_box'
				<item>'$i2'</item>
'
done
}
AAA
##BBB

ok_box=$ok_box'
				<action>EXIT:dir</action>
			</tree>
    <button tooltip-text="Отключить выделенные 
(можно несколько одновременно).
Модуль не должен использываться,
иначе он не отключится.
Возможно отключение 
двойным щелчоком мыши.">
     <input file icon="disconnect"></input>
     <action>EXIT:dir</action>
    </button>

    </hbox>
    <hbox>
			        <checkbox tooltip-text="Постоянно подключенные - 
модули, автоподключенные
при старте системы">
				<label>'$pp' показывать постоянно подключенные</label>
'
echo pp=$pp
if [ "$pp" != "" ];then
ok_box=$ok_box'
				<action>sfs-get -p &</action>
'
else
ok_box=$ok_box'
				<action>sfs-get -a &</action>
'
fi

ok_box=$ok_box'
				<action>EXIT:exit 0</action>
				</checkbox>
    </hbox>
 </frame>
'

ok_box=$ok_box'
<hbox>
       <button help></button>
'

bak="$(find "/mnt/home/`value dir`" -maxdepth 3 -type f \( -name "*.pfs.old" \) |wc -l)"
[ "$bak" = 0 ] || ok_box=$ok_box'
    <button tooltip-text="В каталоге дистрибутива 
'$bak' резервных копий модулей. 
Просмотреть?">
     <input file icon="package_compressed"></input>
     <action>EXIT:bak</action>
        <label>'$bak' pfs.old</label>
    </button>
'

ok_box=$ok_box'
    <button tooltip-text="Обновить подключенные
модули системы">
     <input file stock="gtk-refresh"></input>
     <action>EXIT:ref</action>
        <label>Обновить</label>
    </button>

    <button tooltip-text="Подключить локальный модуль
(находящийся на Вашем компьютере)">
     <input file icon="connect"></input>
     <action>mnt_sfs &</action>
     <action>EXIT:abort</action>
        <label>Подключить</label>
    </button>

       <button tooltip-text="Выход">
        <input file stock="gtk-quit"></input>
       </button>
</hbox>
 </vbox>
</window>'

ret="`gtkdialog --program=ok_box --center`"
eval "$ret"
dir="`echo "$dir" |awk '{print $2"/"$1}'`"
###echo "$ret  ===$dir==" ;exit
#dir="/$dir"
#ntf -i "dir=$dir" &
echo "DLG2: $ret"; echo "EXIT=$EXIT";echo "$file www=$www loc=$loc dir=$dir"
#exit

case "$EXIT" in
"abort" )  exit    ;;
"dir" )
	    echo "dir=$dir"
for dir1 in $dir;do
	    dirb="`basename "$dir1"`"
    if [ "`mount|grep '+'"$dirb"''`" ];then
	    #if [ "`echo "$dir"|egrep -v '.[ps]fs$'`" ];then
###	     m1="`$sudo umountfile "$dir1"`" ; TST "$dirb" отмонтирован
	     wt "$sudo umountfile "$dir1"" 
    else
	     echo "p=$p pp=$pp porteus=$porteus"
	     [ "$pp" ] && [ -f /var/log/porteus-livedbg ] && porteus=1
	     echo "p=$p pp=$pp porteus=$porteus"
	     #if [ "$porteus" = "1" ] ;then
###	          m1="`$sudo pfsunload "$dir1"`" 
###	          m1="`$sudo wt "pfsunload "$dir1"" &`" 
	         $sudo wt  "pfsunload "$dir1"" #&
	         [ "$?" = "0" ] || $sudo klsof "`losetup |awk '/\'$dir1'/ {print $6}'`"
#ntf "m1 $m1" &
	     #else m1="`$sudo pfsunload "$dir"`"
	     #fi
###	     TST "`basename $dir1`" отключен
#	     `which sudo` pfsfix "$dir" stop && `which sudo` pfsramfree &
	     fixmenus &
	     `which sudo` sfs_event_rem "$dir1" & #& `which sudo` pfsramfree &
    fi
done
	    f=;DLG1
    ;;
"ok" ) [ "" = "$f" ] && exit  ;;
"Help" )  HLP;f=;DLG1 ;;
"bak" )  mod-old-rm ;f=;DLG1 ;;
"ref" )  sudo rm /tmp/mod_update/repolist.txt ;sudo mod-up ;f=;DLG1 ;;
*      ) exit ;;
esac

fi
}

##repu
REPU() {
if [ -f $rep/sfs.list ] ;then
	echo "$rep/sfs.list -ok"
    else
	ntf -e "Список репозиториев" "$rep/sfs.list не обнаружен"  &
	f=;DLG1
fi

repf="`egrep -v '^#|^$' $rep/sfs.list`"
po2=`
cd $rep/list ; cat "$repf"| egrep -v '^#|^$' |
while read po1 ;do
  name1="$name"
  echo "$po1" |egrep '^'$f''
done`

#echo "po=$1  url=$2  fname=$3"   ;exit
po2="`echo $po2|head -1`"
}


funcbtnCreate() {
	echo '<button>
			<input file stock="gtk-'$2'"></input>
			<action>fileselect:ent'$1'</action>
		</button>'
}

#http://find.unixpin.com/ru/
#find /media -maxdepth 3 -type f \( -name "*.sfs" -o  -name "*.squashfs" \)       -print 
#find /media -maxdepth 3 -type f \( -name "firefox*.sfs" -o  -name "firefox*.squashfs" \)  -print 
#find /media -maxdepth 3 -type f \( -name "firefox*.s*fs" -o  -name "chrome*.s*fs" -o  -name "opera*.s*fs" \)  -print 

DLG() {
[ "$po" = "$fmsg" ] && (ntf -e "$fmsg" &) && DLG1
export DIALOG='
<window title="Операции с модулями v.'$v'" resizable="false"  icon-name="application-pfs">
<vbox width-request="550">

<frame Программа "'`echo $po| awk '{print $1}'`'" '$ust' установлена.>
'

finded=""

FINDLOC(){
#echo po=$po ;exit
wt -start "Поиск модулей 
$1" &
for i in $po ;do
    if [ "$loc" = true ] ;then
    #echo $i
    finded="$finded `$sudo find $pth -maxdepth $maxdepth -type f \( -iname "$i*.sfs" -o -iname "$i*.squashfs" -o -iname "$i*.pfs" \)  -print`"
    echo "$sudo find $pth -maxdepth $maxdepth -type f \( -iname "$i*.sfs" -o -iname "$i*.squashfs" -o -iname "$i*.pfs" \)  -print"
    #find $pth -maxdepth 3 -type f \( -name "$i*.sfs" -o  -name "$i*.squashfs" \)  -exec echo qq{} \;
    else finded="$finded `$sudo find $pra -type f \( -iname "$i*.sfs" -o -iname "$i*.squashfs" -o -iname "$i*.pfs" \)  -print`"
    fi
done
sleep 0.3 && `which sudo` wt -kill #2>/dev/null
}

if  [ "$loc" = true ] ;then
    FINDLOC "на монтированных разделах"
else
    [ "$pra1" = true ] && FINDLOC "в $pra"
fi
echo finded=$finded\end #;exit
#if [ "$finded" != " " ] ;then
#ntf -w "=$finded="
#if [ "$finded" != "" ] ;then
if [ "`echo "$finded" |egrep '[0-Z]'`" ] ;then
DIALOG=$DIALOG'
    <frame Подключить найденный локально модуль:>

  <hbox>
    <tree headers_visible="true" auto-sort="true" sort-column="0"  selected-row="0" exported-column="2" column-visible="true|true|false">
      <variable>COMBOBOX</variable>
      <label>Модуль | Расположение | fd</label>
      <height>100</height>
'
    for i in $finded ;do
    #i2="`basename "$i"`		`dirname "$i"`"
    i2="`basename "$i"` | `dirname "$i"` | "$i""
	DIALOG=$DIALOG'
          <item>'$i2'</item>
'
    done

DIALOG=$DIALOG'
	  <action type="exit">exit by add</action>
    </tree>

	<button tooltip-text="Подключить модуль.
Если модуль находится на съемном носителе -
подключайте с копированием на RAM диск">
	    <input file icon="connect"></input>
	    <action type="exit">exit by add</action>
	</button>

  </hbox>
    </frame>
'
else
#ntf -w "r7 =$repr="
[ "$repr" ] && m1= || m1="Модуль не найден"
#$loc && m1="Модуль не найден" || m1="Поиск модуля на Вашем компьютере не производился"
#$pra1 && m1="$loc111$pra1Модуль на Вашем компьютере не найден" || m1="Mодуль в /optional не найден. Локально поиск не производился"
DIALOG=$DIALOG'
  <hbox>
    <text width-request="400">
      <label>"'$m1'"
      </label>
    </text>
  </hbox>
'
fi

if [ "$url$urlr$urlr2" != "" ] ;then
ent=/home/"`sfsusr`"/
[ ! "`uname -a|grep puppyrus`" = "" ] || ent="$HOME"/
value() { egrep -o "(^| )$1=[^ ]+" /proc/cmdline | cut -d= -f2; } #sfs
[ -d /mnt/live ] && ent="/mnt/home/`value dir`/optional"
cd $ent

rephlp="Загрузить из интернет,
подключить и запустить модуль"

   if [ "$url" != "" ] ;then
DIALOG=$DIALOG'
<frame из пользовательского репозитория:>
  <hbox>
    <text width-request="400" use-markup="true">
      <label>"<b>'$fname' '$fdu'Mb</b>"
      </label>
    </text>
	<button tooltip-text="'$rephlp'">
	    <input file icon="gtk-save"></input>
	    <action type="exit">exit by wget</action>
	</button>
  </hbox>
</frame>
'
   fi

  if [ "$urlr" != "" ] ;then 
#r7="`echo $repr  |sed 's/ /\\\n/g'`"
#ntf -w "repr $r7"
DIALOG=$DIALOG'
<frame Скачать из WWW репозитория:>
    <hbox>

    <tree headers_visible="true" auto-sort="true" sort-column="0"  selected-row="0" exported-column="2" column-visible="true|true|false">
      <variable>r</variable>
      <label>Модуль | URL | fd</label>
      <height>100</height>
'
    for i in $repr ;do
#    ntf -w "repr $i"
    i2="`basename "$i"` | `dirname "$i"` | "$i""
	DIALOG=$DIALOG'
          <item>'$i2'</item>
'
    done
DIALOG=$DIALOG'
	  <action type="exit">exit by rep</action>
	  <action>EXIT</action>
    </tree>
	<button tooltip-text="'$rephlp'">
	    <input file icon="gtk-save"></input>
	    <action type="exit">exit by rep</action>
	</button>
    </hbox>
</frame>
'  
  fi

DIALOG=$DIALOG'
    <frame в каталог>
			<hbox>
				<entry fs-title="Выберите папку для сохранения" fs-action="folder">
					<variable>ent3</variable>
	 <input>echo '$ent'</input>
				</entry>
				'"$(funcbtnCreate 3 open)"'
			</hbox>
    </frame>
'

  if [ "$urlr2" != "" ] ;then
for r in `echo $repr2` ;do
DIALOG=$DIALOG'
<frame Скачать из URL репозитория:>
  <hbox>
    <text width-request="400" use-markup="true">
      <label>"<b>'$r'</b>"</label>
    </text>
	<button tooltip-text="'$rephlp'">
	    <input file icon="gtk-save"></input>
	    <action type="exit">exit by rep2</action>
	</button>
  </hbox>
</frame>
'
done
  fi

else
[ "$www" ] || DIALOG=$DIALOG'
  <hbox>
    <text width-request="400"><label>"Поиск в WWW репозитории не производился."</label>    </text>
  </hbox>
'
$lock || DIALOG=$DIALOG'
  <hbox>
    <text width-request="400"><label>"Модуль в выбранных репозиториях не найден. Возможно их нужно обновить"</label>    </text>
  </hbox>
'
fi

DIALOG=$DIALOG'
</frame>
    <hbox>
'

[ "$start" ] || start="$po"

[ "$ust" ] || DIALOG=$DIALOG'
        <button tooltip-text="Запустить '$i'
Консольные программы не запустятся .">
	    <label>Запустить</label>
	    <input file stock="gtk-media-play"></input>
	    <action type="exit">start</action>
        </button>
'

if [ "`egrep -v '^$|^#' $rep/www.list`" ] ;then
[ "$www" = "true" ] || \
DIALOG=$DIALOG'
        <button tooltip-text="Поиск модулей в www
репозитории /etc/sfs-get/www.list
Требуется интернет.">
	    <label>WWW реп.</label>
	    <input file icon="internet_connect_yes"></input>
	    <action type="exit">www1</action>
        </button>
'
fi 

DIALOG=$DIALOG'
        <button tooltip-text="Новый поиск модулей.">
	    <label>В начало</label>
	    <input file stock="gtk-goto-first"></input>
    	    <action>sfs-get -p &</action>
    	    <action>EXIT:exit 0</action>
        </button>
	<button help></button>
	<button cancel></button>
    </hbox>
</vbox>
</window>
'
ret="`gtkdialog --program=DIALOG --center`"
eval "$ret"
#COMBOBOX="`echo "$COMBOBOX" |awk '{print $3"/"$1}'`"
#ntf -w "ret=$ret $EXIT ent3=$ent3 combobox=$COMBOBOX r=$r" #;exit
[ "`echo $EXIT |egrep -i 'cancel|abort'`" ] && exit 1

CHKD(){
[ ! -d "$ent3" ] && ntf -a "Каталог $ent3," "выбранный Вами для сохранения модуля, не существует
Выберите другой" && DLG #exit 1
tf="`sudo mktemp  -p "$ent3"`" 
echo ---------tf=$tf
[ ! -f "$tf" ] && ntf -a "Каталог $ent3," "выбранный Вами для сохранения модуля, недоступен для записи
Выберите другой" && DLG || sudo rm "$tf"
}
[ "$ent3" ] && CHKD

case "$EXIT" in
start)
            $sudou "$i" &
            exit
            #$sudou sfsstart "$i" ; exit
    ;;
"www1" )
    	    sfs-get -w "$po" #& 
    	    exit
    ;;
"exit by add" )
    echo    loader=$loader sfs=$COMBOBOX
    $loader $COMBOBOX #&
    #$sudou sfsstart "`basename $COMBOBOX`"
    exit
    ;;
"exit by wget" )
    WG "$ent3" "$fname" "$url" #folder name url
    ;;
"exit by rep" )
    echo --------rep "$ent3" "$fnamer" "$urlr" $r
    #WG "$ent3" "$fnamer" "$urlr" #folder name url
    #echo --- "$ent3" "`basename $urlr`" "$urlr" #folder name url
    #WG "$ent3" "`basename $urlr`" "$urlr" #folder name url
    WG "$ent3" "`basename $r`" "$r" #folder name url
    ;;
"exit by rep2" )
    echo --------rep2 "$ent3" "$fnamer2" "$urlr2"
    #WG "$ent3" "$fnamer2" "$urlr2" #folder name url
    WG "$ent3" "`basename $urlr2`" "$urlr2" #folder name url
    ;;
"Help" ) 
    HLP;DLG;;
*       ) exit;;
esac
}

################################start
#разбор ключей 
for j in $@ ;do
[ "$j" = "--help" ] && echo "\
Использование: $0 [ПАРАМЕТР]... ШАБЛОН [ФАЙЛ]
Поиск (или загрузка) и запуск подключенного модуля имени исполняемого файла (или его части) 
Информация о репозиториях : /etc/sfs-get
    -s 		запуск модуля от имени root
    -w		искать модули в WWW репозитории
    -a 		показывать постоянно подключенные модули
" && exit
[ "$j" = "-s" ] && shift && sudou="sudo -u root"
[ "$j" = "-w" ] && shift && www="true"
[ "$j" = "-p" ] && shift
[ "$j" = "-a" ] && shift && pp=не #&& AF 
done
#echo "inst=$inst" ;exit

if [ "$1" = "" ] ;then
	f=;DLG2
else	f="$1"
fi
#po2="`sfs-get-repu "$f"`"
po="`echo "$po2"|awk -F";" '{print $1" "$7}'`" #; url=$2 ; fname=$3
url="`echo "$po2"|awk -F";" '{print $3}'`"
fname="`echo "$po2"|awk -F";" '{print $4}'`"
fdu="`echo "$po2"|awk -F";" '{print $8}'`"

[ "$po2" = "" ] && po="$f"
echo f=$f po=$po  url=$url  fname=$fname $f #;exit
for i in $po ;do
    if [ -n "`which $i`" ] ;then
        ust=
        #ntf -q "Установлен $i"
        shift
        #$sudou sfsstart "$i" ; exit
    else ust=не
    fi
done
#echo $fname $fdu ;exit
#echo "###rep=$repr f=$f" ;exit
if [ "$www" = "true" ];then
    repr="`sfs-get-rep "$f"`"
    urlr="`echo "$repr"|awk '{print $1}'`"
    fnamer="`basename "$urlr"`"
fi

repr2="`sfs-get-rep2 "$f"`"
urlr2="`echo "$repr2"|awk '{print $1}'`"
fnamer2="`basename "$urlr2"`"

DLG
