#!/bin/bash
### .sfs downloader ###
### stu90 ###
### root password for user fido ###
[ "`whoami`" != "root" ] && exec sudo -A ${0} ${@}
TESTSERVER="174.132.189.156"
SERVER="
www.smokey01.com/Oldyeller/pet_packages-upup/"
## test server ##
ping -4 -c 1 "$TESTSERVER"
if [[ "$?" == "1" ]]; then
yaf-splash -placement center -bg yellow -fontsize large -timeout 10 -text "Either your Internet connection is not working, or the primary repository is down. Aborting SFS Downloader" &
exit 1
fi
## default download location ##
if [[ -f /etc/rc.d/PUPSTATE ]]; then
PUPPYSFS="/mnt/home/`grep 'PUPSFS' /etc/rc.d/PUPSTATE | cut -d '/' -f 2`"
fi
## action for first run with out save file ##
if [[ ! -d "$PUPPYSFS" ]]; then
## get available partitions ##
AVPART="`probepart -m | grep -v -E 'none|iso9660|swap' | cut -f 1 -d '|' | cut -f 3 -d '/' | tr '\n' '!' | sed '$s/.$//'`"
## mount partition info and gui ##
TEXT1=" This is a first boot of Puppy and you have not yet saved a session. \n You want to download the .sfs package, and this needs to be downloaded \n to the same partition in which you will be creating the session save-file.
\n Here is a list of suitable partitions. Whichever one you choose, at \n shutdown you will be asked to save the session and be sure to choose the \n same partition - please select a partition to mount from the box below: "
MNTPART=$(yad --title="$TITLE $VER" --text="$TEXT1" --form --field="mount partition:CB" "$AVPART" \
--button="gtk-quit:1" --button="gtk-ok:0")
result=$?
if [[ "$MNTPART" = "" ]]; then
echo "Exiting" && exit
fi
case $result in
0)
GETMNT=`echo $MNTPART | cut -d '|' -f 1`
## mount selected partition ##
if [[ ! -d /mnt/"$GETMNT" ]];then
mkdir -p /mnt/"$GETMNT"
mount /dev/"$GETMNT" /mnt/"$GETMNT"
fi
if [ $? -ne 0 ];then
xmessage -bg red -center "ERROR: Could not mount /dev/"$GETMNT", aborting"
exit 1
else
## set mounted partition as download location ##
PUPPYSFS="/mnt/"$GETMNT""
fi
;;
1)
echo "cancel pressed exiting"
exit
;;
esac
fi
## .sfs selection gui ##
## gui info ##
TITLE="Ov-Precise Get .sfs"
VER="0.2"
TEXT=" Please choose the .sfs packages that you would like to download from the drop down box below."
## get available .sfs on server ##
AVSFS="` curl -s $SERVER | awk -F '\"' '/href=\".*\.sfs/ {print $8}' | sort -f -u | tr '\n' '!' | sed '$s/.$//' `"
LISTSFS=$(yad --title="$TITLE $VER" --text --justify=center --text="$TEXT" --form \
--field="Available sfs":CB "$AVSFS" \
--field="Download to":DIR "$PUPPYSFS" \
--button="gtk-quit:1" --button="gtk-ok:0")
result=$?
[[ $result = 1 ]] && echo "Exiting" && exit
case $result in
0)
GETSFS=`echo $LISTSFS | cut -d '|' -f 1`
GETLOC=`echo $LISTSFS | cut -d '|' -f 2`
## move to .sfs download location ##
cd "$GETLOC"
## check if .sfs exists in download location ##
if [ -f "$GETLOC/$GETSFS" ]; then
yaf-splash -placement center -bg yellow -close never -fontsize large -timeout 10 -text "$GETSFS already exists - aborting connection" &
exit 1
else
## download .sfs - could do with some error check here ##
yaf-splash -placement center -bg yellow -close never -fontsize large -text "Please wait, downloading .sfs..." &
YPID=$!
TERMSET="urxvt -fg green -bg black -geometry 65x10+0+0 +sb -e "
$TERMSET wget -c "$SERVER/$GETSFS"
kill $YPID
fi
## load .sfs ##
if [ "$GETLOC" == "/mnt/home/$PUPPYSFS" ];then
yaf-splash -placement center -bg green -fontsize large -timeout 10 -text "$SFSGET download complete - load .sfs now..." &
sfs_load "${GETSFS}" &
echo "exit" && exit 0
else
yaf-splash -placement center -bg green -fontsize large -timeout 10 -text "$SFSGET download complete - load .sfs now..." &
sfs_load "${GETSFS}" &
echo "exit" && exit 0
fi
;;
1)
echo "cancel pressed exiting"
exit
;;
esac