File live-usb-gui of Package live-fat-stick

#!/bin/bash
# live-usb-gui : Simple GUI to create bootable usb stick from iso images
# Copyright (c) 2012 CyberOrg Info
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Authors:      Jigish Gohil <cyberorg@opensuse.org>
# This script creates bootable openSUSE, Fedora or Ubuntu(or clones) live usb stick on fat partition
#
if [[ $(id -u) != 0 ]]; then
        echo "run this command as root"
	exit 1
fi
PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin
ionice -c3 -p$$
if [ x"$WINDOWMANAGER" = x"/usr/bin/startkde" ]; then
	which kdialog &>/dev/null && popup=kdialog
else
	which zenity &>/dev/null && popup=zenity
fi
popup=${popup:-zenity}

which $popup &>/dev/null || echo "$popup not found, please install to use this tool"
which live-fat-stick &>/dev/null || echo "live-fat-stick script not found in PATH, please install it and make it executable"

export liveusbgui=/tmp/liveusbgui
touch /tmp/liveusbgui
clean_up () {
        if [[ -f $liveusbgui ]]; then
                rm $liveusbgui &>/dev/null
        fi
}

fileselecttitle="Select distribution iso file"
fileselectpath="/"
fileselectfilter="*iso"
usbselecttitle="Select the target USB device"
distributionlist="suse fedora mint ubuntu isohybrid"
distrotitle="Select the distribution of the iso"
usbdevicelist=$(for i in `echo $(for i in $(find /dev/disk/by-path/ |grep usb); do readlink -f $i;done)`
	do
        #	if [[ $(blkid -s TYPE -o value $i) == vfat ]];then
        		echo $i
        #        fi
done)
usbdevicelistkd=$(for device in $usbdevicelist; do
	printf "%s %s %s" ${device} ${device} off 
	printf "\n"
done)

distributionlistkd=$(for distro in $distributionlist; do
	printf "%s %s %s" $distro $distro off
	printf "\n"    
done)
check_variable () {
	if [ ! "$1" ]; then
		clean_up
		exit 1
	fi
}
if [[ $popup == zenity ]]; then
	sourceiso=$(zenity --file-selection --title="$fileselecttitle" --file-filter="$fileselectfilter")
	check_variable $sourceiso
	usbdevice=$(zenity --list --title="$usbselecttitle" --column="USB device" $usbdevicelist)
	check_variable $usbdevice
	distroname=$(zenity --list --title="distrotitle" --column="Distribution:" $distributionlist)
	check_variable $distroname
else
	sourceiso=$(kdialog --title "$fileselecttitle" --getopenfilename "$fileselectpath" "$fileselectfilter")
	check_variable $sourceiso
	usbdevice=$(kdialog --separate-output --title "$usbselecttitle" --checklist "USB device:" $usbdevicelistkd)
	check_variable $usbdevice
	distroname=$(kdialog --separate-output --title "$distrotitle" --checklist "Distribution:" $distributionlistkd)
	check_variable $distroname
fi

case $distroname in
	fedora)
	option="--fedora"
	;;
	suse)
	option="--suse"
	;;
	ubuntu)
	option="--ubuntu"
	;;
	mint)
	option="--ubuntu"
	;;
        isohybrid)
        option="isohybrid"
        ;;
esac

if [ ! "$option" ]; then
        clean_up
	exit 1
fi
questiontitle="Is the information below correct?"
questiontext="Distribution: $distroname \nISO image: $sourceiso \nUSB device: $usbdevice"
errortext="oops, something went wrong"
successtext="Your bootable usb device is now ready"
if [[ $popup == zenity ]]; then
	if ! zenity --question --title="$questiontitle" --text "$questiontext"; then
	        clean_up
	        exit 1
	fi
else
	if ! kdialog --title "$questiontitle" --warningcontinuecancel "$questiontext"; then
		clean_up
	        exit 1
	fi	
fi

if [[ $option == isohybrid ]]; then
	usbdev=$(echo $usbdevice | sed 's/[0-9]*//g')
	xterm -e "live-fat-stick --isohybrid $sourceiso $usbdev"
else
	xterm -e "live-fat-stick $option $sourceiso $usbdevice"
fi

if [ $? != 0 ]; then
	if [[ $popup == zenity ]]; then
		zenity --error --text="$errortext"
	else
		kdialog --error "$errortext"
	fi
else
	if [[ $popup == zenity ]]; then
		zenity --info --text="$successtext"	
	else
		kdialog --msgbox "$successtext"
	fi
fi
clean_up

openSUSE Build Service is sponsored by