Please try these, and let me know how they work. The script does nothing except report the space. Ignore the missing stuff like how many snapshots you have, how much space they're taking up and what the config file is. Those variables aren't set. My main concerns are the columns lining up in the df output and the fact that with zenity, I can't seem to control the window height. It might be too big on some screens, and the buttons might be off the screen. I'm also interested to know if it takes awhile to complete. In my tests, there's no delay like there is when running current versions of refractasnapshot.
If you want to try it with a progress bar, comment out the first df line in the check_space function and uncomment the second one. If you know how to use printf in awk better than I do, and you want to play with that, there are some of my failed attempts commented out.
And thanks in advance to anyone who tests this.
This one will use yad in preference to zenity if both are present:
- Code: Select all
#!/usr/bin/env bash
# if yad is installed, use in preference
if [[ -f /usr/bin/yad ]]; then
DIALOG="yad"
INFO="image=gtk-dialog-info"
QUESTION="image=gtk-dialog-question"
WARNING="image=gtk-dialog-warning"
ERROR="image=gtk-dialog-error"
#buttons
BUTTON0="button"
BUTTON1="button"
BUTTON0NUM=":0"
BUTTON1NUM=":1"
#cancel button always returns 1 as $?
#ok button always returns 0 as $?
#ok is default (highlighted)
#buttons in yad dialog window may show reversed from zenity window, e.g.
#yad: ok -- cancel (0 -- 1)
#zenity: cancel -- ok (1 -- 0)
elif [[ -f /usr/bin/zenity ]]; then
# use zenity
DIALOG="zenity"
INFO="info"
QUESTION="question"
WARNING="warning"
ERROR="error"
#buttons
BUTTON0="ok-label"
BUTTON1="cancel-label"
BUTTON0NUM=""
BUTTON1NUM=""
else
xterm -fa monaco -fs 12 -hold -e echo "
Neither Yad nor Zenity is installed. You can't run the GUI version of
Refracta Installer without one of those. Instead, you can run
'refractainstaller' from a terminal or console for the CLI version.
"
fi
# Check disk space on mounted filesystems.
check_space () {
disk_space=$(df -h -x tmpfs -x devtmpfs -x iso9660 | awk '{ print " " $2 "\t" $3 "\t" $4 "\t" $5 " \t" $6 "\t\t\t" $1 }')
#disk_space=$(df -h -x tmpfs -x devtmpfs -x iso9660 | awk '{ print " " $2 "\t" $3 "\t" $4 "\t" $5 " \t" $6 "\t\t\t" $1 }' | tee >($DIALOG --title="Checking disk space..." --progress --pulsate --auto-close --width 300) ;)
#disk_space=$(df -h -x tmpfs -x devtmpfs | awk '{ print $2 "\t" $3 "\t" $4 "\t" $5 "\t" $6 "\t\t\t"}{ printf (%-32s, $1) }')
#disk_space=$(df -h -x tmpfs -x devtmpfs | awk '{ print $2 "\t" $3 "\t" $4 "\t" $5 "\t" }{ printf "%-18s", $6 }{ printf "%-28s", $1 "\n" }')
#disk_space=$(df -h -x tmpfs -x devtmpfs | awk '{ printf "%-.32s", $1 }{ print "\t" $2 "\t" $3 "\t" $4 "\t" $5 "\t" $6 }')
#disk_space=$(df -h -x tmpfs -x devtmpfs | awk '{ printf "%-40s", $1 "\t" }{ print "\t" $2 "\t" $3 "\t" $4 "\t" $5 "\t" $6 }')
}
# Put information in a zenity or yad window to show current settings and disk space
report_space () {
$DIALOG --$QUESTION --title="Disk Space and Settings Report" --${BUTTON0}="Create Snapshot"${BUTTON0NUM} \
--${BUTTON1}="Exit"${BUTTON1NUM} --height=550 --width=920 \
--text "Please CLOSE any running applications NOW.
You will need plenty of free space. It is recommended that free space (Avail) in the partition that holds the work directory (probably \"/\") should be two times the total installed system size (Used).
You can deduct the space taken up by previous snapshots and any saved copies of the system from the Used amount.
* You have $snapshot_count snapshots taking up $snapshot_size of disk space.
$saved_copy
$save_message
* The snapshot directory is currently set to $snapshot_dir
$tmp_warning
You can change these and other settings by editing
$configfile.
Current disk usage:
(For complete listing, exit and run 'df -h')
$disk_space
"
if [ $? -ne 0 ]; then
exit 0
fi
}
check_space
report_space
echo "Done! "
This one was changed so that it will only use zenity:
- Code: Select all
#!/usr/bin/env bash
# if yad is installed, use in preference
#if [[ -f /usr/bin/yad ]]; then
DIALOG="yad"
INFO="image=gtk-dialog-info"
QUESTION="image=gtk-dialog-question"
WARNING="image=gtk-dialog-warning"
ERROR="image=gtk-dialog-error"
#buttons
BUTTON0="button"
BUTTON1="button"
BUTTON0NUM=":0"
BUTTON1NUM=":1"
#cancel button always returns 1 as $?
#ok button always returns 0 as $?
#ok is default (highlighted)
#buttons in yad dialog window may show reversed from zenity window, e.g.
#yad: ok -- cancel (0 -- 1)
#zenity: cancel -- ok (1 -- 0)
#el
if [[ -f /usr/bin/zenity ]]; then
# use zenity
DIALOG="zenity"
INFO="info"
QUESTION="question"
WARNING="warning"
ERROR="error"
#buttons
BUTTON0="ok-label"
BUTTON1="cancel-label"
BUTTON0NUM=""
BUTTON1NUM=""
else
xterm -fa monaco -fs 12 -hold -e echo "
Neither Yad nor Zenity is installed. You can't run the GUI version of
Refracta Installer without one of those. Instead, you can run
'refractainstaller' from a terminal or console for the CLI version.
"
fi
# Check disk space on mounted filesystems.
check_space () {
disk_space=$(df -h -x tmpfs -x devtmpfs -x iso9660 | awk '{ print " " $2 "\t" $3 "\t" $4 "\t" $5 " \t" $6 "\t\t\t" $1 }')
#disk_space=$(df -h -x tmpfs -x devtmpfs -x iso9660 | awk '{ print " " $2 "\t" $3 "\t" $4 "\t" $5 " \t" $6 "\t\t\t" $1 }' | tee >($DIALOG --title="Checking disk space..." --progress --pulsate --auto-close --width 300) ;)
#disk_space=$(df -h -x tmpfs -x devtmpfs | awk '{ print $2 "\t" $3 "\t" $4 "\t" $5 "\t" $6 "\t\t\t"}{ printf (%-32s, $1) }')
#disk_space=$(df -h -x tmpfs -x devtmpfs | awk '{ print $2 "\t" $3 "\t" $4 "\t" $5 "\t" }{ printf "%-18s", $6 }{ printf "%-28s", $1 "\n" }')
#disk_space=$(df -h -x tmpfs -x devtmpfs | awk '{ printf "%-.32s", $1 }{ print "\t" $2 "\t" $3 "\t" $4 "\t" $5 "\t" $6 }')
#disk_space=$(df -h -x tmpfs -x devtmpfs | awk '{ printf "%-40s", $1 "\t" }{ print "\t" $2 "\t" $3 "\t" $4 "\t" $5 "\t" $6 }')
}
# Put information in a zenity or yad window to show current settings and disk space
report_space () {
$DIALOG --$QUESTION --title="Disk Space and Settings Report" --${BUTTON0}="Create Snapshot"${BUTTON0NUM} \
--${BUTTON1}="Exit"${BUTTON1NUM} --height=550 --width=920 \
--text "Please CLOSE any running applications NOW.
You will need plenty of free space. It is recommended that free space (Avail) in the partition that holds the work directory (probably \"/\") should be two times the total installed system size (Used).
You can deduct the space taken up by previous snapshots and any saved copies of the system from the Used amount.
* You have $snapshot_count snapshots taking up $snapshot_size of disk space.
$saved_copy
$save_message
* The snapshot directory is currently set to $snapshot_dir
$tmp_warning
You can change these and other settings by editing
$configfile.
Current disk usage:
(For complete listing, exit and run 'df -h')
$disk_space
"
if [ $? -ne 0 ]; then
exit 0
fi
}
check_space
report_space
echo "Done! "