Creta a script with GUi to made bootable usb

Need help with C, C++, perl, python, etc?

Creta a script with GUi to made bootable usb

Postby Scorpion » 2018-12-11 22:02

To made bootable usb I have a good method. How can I add a GUI and make a little program?
Code: Select all
#GUI message select usb stick (it must not allow to select hard disk maybe can be added an option to allow hard disk but is not really necessary)
#Format it to FAT32 and name it
??????
#Create directory to mount 
mkdir -option-to-do-nothing-if-already-exist /media/iso #or check if exist ok if not create it
#GUI message select iso
#Mount it
mount -o loop /path/to/debian.iso /media/iso
#Copy files (you get errors about cannot copy symbolic? link). It would be nice have a progress bar.
cp -a /media/iso/. /media/user/usb-stick
#Use syslinux (if not present install it)
syslinux -s /dev/sdx1
#rename necessary file/folder
cd  /media/user/usb-stick mv isolinux syslinux
cd sylinux mv isolinux.cfg syslinux.cfg
#GUi message you can now remove the media (after that the cmd is finished)
umount /media/user/usb-stick
User avatar
Scorpion
 
Posts: 123
Joined: 2018-10-17 11:38

Re: Creta a script with GUi to made bootable usb

Postby GarryRicketson » 2018-12-12 00:06

I use a program called dialog to make the graphical control element, if I feel I really need one. https://packages.debian.org/stretch/dialog


The manual is pretty good, but there also are plenty of tutorials , if one just does a little search effort.
Code: Select all
man dialog

DIALOG(1) General Commands Manual DIALOG(1)

NAME
dialog - display dialog boxes from shell scripts

SYNOPSIS
dialog --clear
dialog --create-rc file
dialog --print-maxsize
dialog common-options box-options

DESCRIPTION
Dialog is a program that will let you present a variety of questions or
display messages using dialog boxes from a shell script. These types
of dialog boxes are implemented (though not all are necessarily
compiled into dialog):

buildlist, calendar, checklist, dselect, editbox, form,
fselect, gauge, infobox, inputbox, inputmenu, menu,
mixedform, mixedgauge, msgbox (message), passwordbox,
passwordform, pause, prgbox, programbox, progressbox,
radiolist, rangebox, tailbox, tailboxbg, textbox, timebox,
treeview, and yesno (yes/no).

You can put more than one dialog box into a script:---snip---

============ edited =============
Here is some of the first things I did using "dialog", a few years ago:
Image
=========
Image
====
There are many other ways to create a GUI for your shell scripts, it seems like a waste of time though, everything that a GUI does, can be done from the CLI, I never could see much point in spending much time on trying to make a GUI for such simple things like mounting a usb drive, it only takes a couple of seconds to type in the commands to do that, Why spend hours ,and even months of studying to do that ?
Last edited by GarryRicketson on 2018-12-12 01:54, edited 3 times in total.
User avatar
GarryRicketson
 
Posts: 5877
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: Creta a script with GUi to made bootable usb

Postby xepan » 2018-12-12 00:22

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.
xepan
 
Posts: 89
Joined: 2018-11-28 06:38

Re: Creta a script with GUi to made bootable usb

Postby Scorpion » 2018-12-16 19:46

Thank you both, it would be nice to have a GUi to select the iso and the usb. Can I use nautilus?
User avatar
Scorpion
 
Posts: 123
Joined: 2018-10-17 11:38


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests

fashionable