To waste a bit of time i gave it a try how i would start (and more than a start it isn't).
Don't use it !
It's only purpose is to give you some ideas.
I got no clue about syslinux and such stuff, i got no way to test if it really works.
It completely lacks the gui stuff you ask for too. fsmithred/refractat uses the program "yad" for an easy gui (it seems).
Might contain some hints for you too:
https://github.com/fsmithred
(somewhere there you will find perfect solutions for such a problem, selecting devices with yad, etc, but i forgot which script it is).
Code: Select all
#!/usr/bin/bash
# TESTS #########################################
# test for syslinux:
if ! command syslinux; then
printf "install syslinux, then run again"
exit 1
fi
##############################################
# VARIABLES #####################################
mp=/media/iso #mountpoint
musb=/media/user/usb-stick # media user usb-stick
usb=
iso=
# get usb stick device
read -p "enter usb device name, full path: " usb
if ! [[ -b "$usb" ]]; then
printf "not a valid usb stick\n"
exit 1
fi
# get iso path
read -p "enter iso to write, full path" iso
if ! [[ -f "$iso" ]]; then
printf "iso doesn't exist\n"
exit 1
fi
##############################################
### MAIN WORK ################################
# format stick
mkdosfs -F 32 -I "$usb" || printf "failure to format %d\n" "$usb"; exit
1
# make mountpoint
if ! [[ -d "$mp" ]]; then
mkdir "$mp" || printf "failed to create %s\n" "$mp"; exit 1
fi
# mount it, copy
if mount -o loop "$mp"; then
cp -a "$mp"/* "$musb" || exit 1
fi
# syslinux
syslinux -s "$usb" || printf "failure syslinux\n"; exit 1
# move stuff
mv "$musb"/isolinux "$musb"/syslinux || exit 1
mv "$musb"/syslinux/isolinux.cfg "$musb"/syslinux/syslinux.cfg || exit 1
# umount
umount "$musb" || printf "failure umount\n"; exit 1
##############################################
The code itself seems to be correct as far
http://shellcheck.net is concerned (it complains bout using read without -r).
But that only means that formally it is (more or less) correct, not that it does what you want to do.
If it was me:
If you hardcode the variables at the top, instead of asking the user for input, the whole script will be much easier. user input is ... well ... it can go south.
If you ask me why sometimes i use if-else, and sometimes i use || : i can't really tell you.
Looks to me as if i would prefer || to test if a command failed and quickly exit.
Important thing is: never do cd or mkdir or such without checking if the command succeeded (and if it doesn't, exit and don't go on).
Also || printf "yada yada" is superfluous, most commands will give you the error message, command || exit 1; is sufficient.
using a die() function would sure make the whole thing look less noobish:
http://mywiki.wooledge.org/BashFAQ/101
In general usage of functions could enhance the whole thing, sure make it less verbose.
Short: Have at it, if you like pick up some of my ideas and fiddle with them, if in doubt ask, make sure to use
http://shellcheck.net
(for example: it will tell you to not cd without || ; iirc).
good luck.