-
Notifications
You must be signed in to change notification settings - Fork 28
/
live-usb-gui
executable file
·192 lines (185 loc) · 6.16 KB
/
live-usb-gui
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/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 <[email protected]>
# 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}
scriptorun=${scriptorun:-live-fat-stick}
which $popup &>/dev/null || echo "$popup not found, please install to use this tool"
export liveusbgui=/tmp/liveusbgui
touch /tmp/liveusbgui
clean_up () {
if [[ -f $liveusbgui ]]; then
rm $liveusbgui &>/dev/null
fi
if [[ -f $statusfile ]]; then
rm $statusfile
fi
}
fileselecttitle="Select distribution iso file"
fileselectpath="/"
fileselectfilter="*iso"
usbselecttitle="Select the target USB device"
usbselecttext="Select the correct device, usually the one with a number at the end;\n\
usually device without a number at the end is for isohybrid."
nousbmedia="No USB media found. Please insert USB stick and try again."
distributionlist="suse suse-persistent fedora mint ubuntu ubuntu-persistent ipxe isohybrid"
distributionlisttext="isohybrid should work for most distribution iso images and EFI booting,\n\
persistent preserve changes in live system after reboots."
distrotitle="Select the distribution of the iso"
scriptstitle="Select script to run"
scriptstext="Select live-fat-stick for vfat/fat32 partition,\n\
live-grub-stick for vfat/fat32/ntfs/ext3/ext4\n\
and any other partition supported by grub2"
supportedscripts="live-grub-stick live-fat-stick"
for i in $(echo "$supportedscripts"); do
if which $i > /dev/null 2>&1; then
scriptlist="$scriptlist $i"
else
scriptlist="$scriptlist"
fi
done
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)
if [ -z "$usbdevicelist" ] ; then
if [[ $popup == zenity ]]; then
zenity --error --text="$nousbmedia"
else
kdialog --error "$nousbmedia"
fi
clean_up
exit 1
fi
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)
scriptlistkd=$(for script in $scriptlist; do
printf "%s %s %s" $script $script 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
distroname=$(zenity --list --title="$distrotitle" --text "$distributionlisttext" --column="Distribution:" $distributionlist)
check_variable $distroname
usbdevice=$(zenity --list --title="$usbselecttitle" --text "$usbselecttext" --column="USB device" $usbdevicelist)
check_variable $usbdevice
scriptorun=$(zenity --list --title="Select script to run" --text "$scriptstext" --column="Scripts:" $scriptlist)
check_variable $scriptorun
else
sourceiso=$(kdialog --title "$fileselecttitle" --getopenfilename "$fileselectpath" "$fileselectfilter")
check_variable $sourceiso
distroname=$(kdialog --separate-output --title "$distrotitle" --radiolist "$distributionlisttext" $distributionlistkd)
check_variable $distroname
usbdevice=$(kdialog --separate-output --title "$usbselecttitle" --radiolist "$usbselecttext" $usbdevicelistkd)
check_variable $usbdevice
scriptorun=$(kdialog --separate-output --title "$scriptstitle" --radiolist "$scriptstext" $scriptlistkd)
check_variable $scriptorun
fi
case $distroname in
fedora)
option="--fedora"
;;
suse)
option="--suse"
;;
ubuntu)
option="--ubuntu"
;;
suse-persistent)
option="--suse-persistent"
;;
ubuntu-persistent)
option="--ubuntu-persistent"
;;
mint)
option="--ubuntu"
;;
isohybrid)
option="isohybrid"
;;
ipxe)
option="--ipxe"
;;
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, try live-fat-stick or live-grub-stick from terminal"
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
statusfile=$(mktemp)
if [[ $option == isohybrid ]]; then
usbdev=$(echo $usbdevice | sed 's/[0-9]*//g')
xterm -e "($scriptorun --isohybrid $sourceiso $usbdev || echo 1 > $statusfile)"
else
xterm -e "($scriptorun $option $sourceiso $usbdevice || echo 1 > $statusfile)"
fi
if [[ $(cat $statusfile) == 1 ]]; 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