diff options
author | Dave Hodgins <davidwhodgins@mageia.org> | 2013-09-06 15:23:27 -0400 |
---|---|---|
committer | Dave Hodgins <davidwhodgins@mageia.org> | 2013-09-06 15:23:27 -0400 |
commit | dd7c17b63afb8402d5224930d4c8e1e84f1e780f (patch) | |
tree | aedd03b9db7840e13d2c179fde7032575b96e9c8 | |
download | copyiso2usb-dd7c17b63afb8402d5224930d4c8e1e84f1e780f.tar copyiso2usb-dd7c17b63afb8402d5224930d4c8e1e84f1e780f.tar.gz copyiso2usb-dd7c17b63afb8402d5224930d4c8e1e84f1e780f.tar.bz2 copyiso2usb-dd7c17b63afb8402d5224930d4c8e1e84f1e780f.tar.xz copyiso2usb-dd7c17b63afb8402d5224930d4c8e1e84f1e780f.zip |
Initial import of files used for copyiso2usb
-rw-r--r-- | copyiso2usb.pot | 96 | ||||
l--------- | usr/bin/copyiso2usb | 1 | ||||
-rwxr-xr-x | usr/sbin/copyiso2usb | 323 | ||||
-rw-r--r-- | usr/share/applications/copyiso2usb.desktop | 89 | ||||
-rw-r--r-- | usr/share/icons/copyiso2usb.png | bin | 0 -> 1666 bytes | |||
-rw-r--r-- | usr/share/man/man1/copyiso2usb.1 | 17 |
6 files changed, 526 insertions, 0 deletions
diff --git a/copyiso2usb.pot b/copyiso2usb.pot new file mode 100644 index 0000000..60b54cc --- /dev/null +++ b/copyiso2usb.pot @@ -0,0 +1,96 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-09-03 02:32-0400\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <LL@li.org>\n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: /usr/sbin/copyiso2usb:35 +msgid "Copy iso image to usb drive" +msgstr "" + +#: /usr/sbin/copyiso2usb:36 +msgid "Select iso image to be copied to a usb drive" +msgstr "" + +#: /usr/sbin/copyiso2usb:37 +#, sh-format +msgid "" +"No iso images found.${Newline}${Newline}If an iso has been recently " +"downloaded, please run /etc/cron.daily/mlocate.cron${Newline}so that this " +"script can find them using the locate command." +msgstr "" + +#: /usr/sbin/copyiso2usb:38 +#, sh-format +msgid "" +"No usb drives found.${Newline}${Newline}Please insert a usb drive, and then " +"rerun this script." +msgstr "" + +#: /usr/sbin/copyiso2usb:39 +msgid "Select usb drive to copy the iso image to" +msgstr "" + +#: /usr/sbin/copyiso2usb:40 +msgid "Copy cancelled. Exiting." +msgstr "" + +#: /usr/sbin/copyiso2usb:41 +msgid "" +"Running /etc/cron.daily/mlocate.cron. Please wait for 'rc=0' before " +"continuing." +msgstr "" + +#: /usr/sbin/copyiso2usb:42 +msgid "Copying iso to usb drive. Please wait for 'rc=0' before continuing." +msgstr "" + +#: /usr/sbin/copyiso2usb:120 +#, sh-format +msgid "$Command command not found. Installing $Package" +msgstr "" + +#: /usr/sbin/copyiso2usb:125 +#, sh-format +msgid "urpmi failed. Return code was $result. Exiting." +msgstr "" + +#: /usr/sbin/copyiso2usb:159 +#, sh-format +msgid "Must be root to run $ThisScript" +msgstr "" + +#: /usr/sbin/copyiso2usb:187 +#, sh-format +msgid "" +"mlocate.db is ${dbageseconds} seconds old (it's used to locate iso files), " +"would you like it updated?" +msgstr "" + +#: /usr/sbin/copyiso2usb:304 +#, sh-format +msgid "" +"ISO size is $IsoSize bytes. Selected USB stick only has room for $ofsize " +"bytes. Copy cancelled. Exiting." +msgstr "" + +#: /usr/sbin/copyiso2usb:309 +#, sh-format +msgid "" +"About to run${Newline}${ddcmd}${Newline}Please select yes to confirm, or no " +"to cancel.${Newline}NOTE: When it runs, please wait for 'rc=0' before " +"continuing." +msgstr "" diff --git a/usr/bin/copyiso2usb b/usr/bin/copyiso2usb new file mode 120000 index 0000000..ed9d1b0 --- /dev/null +++ b/usr/bin/copyiso2usb @@ -0,0 +1 @@ +/usr/bin/consolehelper
\ No newline at end of file diff --git a/usr/sbin/copyiso2usb b/usr/sbin/copyiso2usb new file mode 100755 index 0000000..916397e --- /dev/null +++ b/usr/sbin/copyiso2usb @@ -0,0 +1,323 @@ +#!/bin/bash +######################################################################################## +# /usr/sbin/copyiso2usb +######################################################################################## +# Usage: copyiso2usb [isofile] +# Installs needed packages if missing - dcfldd cdialog udisks mlocate +# Runs locate command if needed mmlocate.db doesn't exist, or is more than 24 hours +# old, or requested. +# Uses the locate command to find iso images, presented in a selection dialog, unless +# a file name is passed as the only argument. +# Lists usb drives in a selection dialog +# Checks that the iso will fit on the selected drive +# Confirms that the command should be run +# Copies the iso image to the usb drive. +# +# Note for maintainers 'xgettext -d copyiso2usb -L Shell /usr/sbin/copyiso2usb' used +# to create copyiso2usb.po (which was manually renamed to copyiso2usb.pot) +# +# If installing manually, also suggest installing Xdialog and runnning +# 'ln -s /usr/bin/consolehelper /usr/sbin/copyiso2usb' +######################################################################################## +# Author: David W. Hodgins - Mageia Qa team +# 2013-06-02 Initial writing +# 2013-06-04 Added iso as arg, fix for no partition table on usb stick, Thanks barjac. +# 2013-08-22 Converted to use gettext for translations +######################################################################################## +set -u # Show usage of unset variables as an error, to help catch typos. +# Obtain translations for all static messages (message with vars translated when needed) +. /usr/bin/gettext.sh +TEXTDOMAIN=copyiso2usb +export TEXTDOMAIN +TEXTDOMAINDIR=/usr/share/locale/ +export TEXTDOMAINDIR +Newline="\n" +TitleString=$(gettext "Copy iso image to usb drive") +SelectISO=$(gettext "Select iso image to be copied to a usb drive") +NoISOFound=$(eval_gettext "No iso images found.\${Newline}\${Newline}If an iso has been recently downloaded, please run /etc/cron.daily/mlocate.cron\${Newline}so that this script can find them using the locate command.") +NoUSBDrives=$(gettext "No usb drives found.\${Newline}\${Newline}Please insert a usb drive, and then rerun this script.") +SelectUSBDrive=$(gettext "Select usb drive to copy the iso image to") +CopyCancelled=$(gettext "Copy cancelled. Exiting.") +Waitmlocate=$(gettext "Running /etc/cron.daily/mlocate.cron. Please wait for 'rc=0' before continuing.") +WaitCopy=$(gettext "Copying iso to usb drive. Please wait for 'rc=0' before continuing.") +FileNameTemp=$(mktemp -p /tmp "${0##*/}".XXXXXX) + +# Set dialog command to use +dialogcmd="/usr/bin/Xdialog" +displaytest=${DISPLAY-"unset"} +if [ ! -e /usr/bin/Xdialog ] || [ ! -x /usr/bin/Xdialog ] || [ "unset" = "$displaytest" ] ; then + dialogcmd="/usr/bin/dialog" +fi + +ThisScript="$0" +if [[ ! ${ThisScript:0:1} = '/' ]] ; then + ThisScript="$(pwd)/$0" +fi + +# Function to get window size +GetDisplaySize() { + IFS=$':, ' + read label MaxLines MaxColumns<<<"$($dialogcmd --print-maxsize --output-fd 1 2>&1)" + unset IFS + MenuHeight=$(( MaxLines - 5 )) +} + +GetDisplaySize + +# Function to list all usb drives +listusbdrives () { + for block in /sys/devices/pci*/*/usb*/*/*/host*/target*/*/block/sd*; do + device=${block##*/} # strip last slash and everything before it. + printf '%s\n' "$device" + done +} + +menuitem=0 +MenuText="" +DisplayMenu() { + GetDisplaySize + $dialogcmd --backtitle "$TitleString" --title "copyiso2usb" --menu "$DisplayText" "$MaxLines" "$MaxColumns" "$MenuHeight" $MenuText 2>$FileNameTemp +} + +DisplayInfo() { + GetDisplaySize + $dialogcmd --backtitle "$TitleString" --title "copyiso2usb" --msgbox "$DisplayText" "$MaxLines" "$MaxColumns" +} + +RunCommandX() { + GetDisplaySize + printf '%s\n\n' "$DisplayText" >$FileNameTemp + ( printf '%s\n' "$@" ; eval "$@" ; result=$? ; printf '%s\n' "rc=$result" ) >>$FileNameTemp & + $dialogcmd --backtitle "$TitleString" \ + --title "copyiso2usb" \ + --tailbox "$FileNameTemp" "$MaxLines" "$MaxColumns" + rm -f "$FileNameTemp" +} + +RunCommand() { + if [[ "$dialogcmd" = "/usr/bin/dialog" ]] ; then + printf '%s\n\n' "$DisplayText" + eval "$@" + result=$? + printf '%s\n' "rc=$result" + else + RunCommandX "$@" + fi +} + +ShowMsgExit() { + DisplayText="$@" + DisplayInfo + exit 0 +} + +# Function to install missing packages +InstallPackageIfFileMissing() { +# Install command, if it isn't already available + if [ ! -x "$1" ] ; then + Command="$1" + Package="$2" + CmdNotFoundInstalling=$(eval_gettext "\$Command command not found. Installing \$Package") + DisplayText="$CmdNotFoundInstalling" + RunCommand "urpmi --auto $2" + result=$? + if (($result)) ; then + FailedExiting=$(eval_gettext "urpmi failed. Return code was \$result. Exiting.") + ShowMsgExit "$FailedExiting" + exit 1 + fi + fi +} + +# Function to convert size to human readable format +declare -a SpaceUnits=( B KB MB GB TB PB ) +declare -i SpaceUnitsIndex +declare -i SpaceInt +setspaceunits () { + SpaceUnitsIndex=0 + (( Size *= 100 )) # add two decimal places + while [ "$Size" -ge 102400 ] ; do + let Size="$Size"/1024 + (( SpaceUnitsIndex++ )) + done + SpaceString="$Size" + StringLength=${#SpaceString} + let Intlength="$StringLength - 2" + StringLeft=${SpaceString:0:$Intlength} + StringRight=${SpaceString:$Intlength} + SpaceString="$StringLeft.$StringRight${SpaceUnits[$SpaceUnitsIndex]}" + if [ "$Size" -gt 100 ] ; then + SpaceString="$SpaceString"s + else + SpaceString="$SpaceString " + fi + printf '%s' "$SpaceString" +} + +# Exit if not root. +if [[ "$(id -u)" != "0" ]] ; then + MustBeRoot=$(eval_gettext "Must be root to run \$ThisScript") + ShowMsgExit "$MustBeRoot" + exit 0 +fi + +InstallPackageIfFileMissing /usr/bin/dcfldd dcfldd +InstallPackageIfFileMissing /usr/bin/dialog cdialog +InstallPackageIfFileMissing /usr/bin/udisks udisks +InstallPackageIfFileMissing /etc/cron.daily/mlocate.cron mlocate + +if="" +if [[ $# -eq 1 && -r "$1" ]] ; then + if="$1" +fi + +runmlocate="no" +if [ -z "$if" ] ; then + if [ ! -s /var/lib/mlocate/mlocate.db ] ; then + runmlocate="yes" + else + dbdatetext=$(stat /var/lib/mlocate/mlocate.db|grep Modify) + dbdate="${dbdatetext#* }" # strip upto and including first space + dbdatesecondssince1970=$(date -u -d "$dbdate" "+%s") + currentsecondscince1970=$(date -u "+%s") + dbageseconds=$(( $currentsecondscince1970 - $dbdatesecondssince1970 )) + if (("$dbageseconds" > "86400")) ; then # 86400 seconds is one day + runmlocate="yes" + else + mlocateAsk=$(eval_gettext "mlocate.db is \${dbageseconds} seconds old (it's used to locate iso files), would you like it updated?") + $dialogcmd --backtitle "$TitleString" \ + --title "copyiso2usb" \ + --yesno "$mlocateAsk" "$MaxLines" "$MaxColumns" + Selected=$? + if (( ! $Selected)) ; then + runmlocate="yes" + fi + fi + fi +fi + + +if [[ "$runmlocate" == "yes" ]] ; then + DisplayText="${Waitmlocate}" + RunCommand "/etc/cron.daily/mlocate.cron" +fi + +IFS=$'\n' +isolist=($(locate -eiq .iso|grep -i iso$)) +unset IFS +if [ "${#isolist[@]}" == 0 ] ; then + ShowMsgExit "$NoISOFound" + exit 2 +fi + +for i in "${isolist[@]}" ; do + isolistshow="${i// /_}" # Show spaces in file names as underscores + MenuText="$MenuText $menuitem ${isolistshow}" + (( menuitem++ )) +done + +if [[ $# -eq 1 && -r "$1" ]] ; then + if="$1" +else + DisplayText="$SelectISO" + DisplayMenu + Selected=$(<$FileNameTemp) + rm -f "$FileNameTemp" + if [[ "${Selected}" == "" ]] ; then + exit 3 # Cancel selected + fi + if="${isolist[$Selected]}" +fi + +shopt -s nullglob +usbdrives=($(listusbdrives)) + +if [ "${#usbdrives[@]}" == 0 ] ; then + ShowMsgExit "$NoUSBDrives" + exit 4 +fi + +menuitem=0 +MenuText="" + +for dev in "${usbdrives[@]}" ; do + IFS=$'\n' + udisksinfo=($(udisks --show-info /dev/$dev |grep -e size -e label -e vendor -e model -e serial)) + unset IFS + Size=${udisksinfo[0]##*: } + read -rd '' Size <<< "$Size" + usbsize[$menuitem]="$Size" + SizeString=$(setspaceunits) + Label=${udisksinfo[2]##*: } + Vendor=${udisksinfo[3]##*: } + Model=${udisksinfo[4]##*: } + Serial=${udisksinfo[5]##*: } + if [[ "${Label}" == "" ]] ; then + udisksinfo=($(udisks --show-info /dev/${dev}1 |grep -e label)) + Label=${udisksinfo[0]##*:} + fi + Mountpoint="" + read mntdev Mountpoint rest<<<"$(grep ^/dev/$dev /proc/mounts)" + read -rd '' SizeString <<< "$SizeString" # Remove leading/trailing spaces + SizeString="${SizeString// /_}" # Translate any embedded spaces to underscores + Label="" + read -rd '' Label <<< "$Label" + if [[ "${Label}" == "" ]] ; then + if [ -e "/dev/${dev}1" ] ; then + IFS=$'\n' + udisksinfo=($(udisks --show-info /dev/${dev}1 |grep -m 1 label)) + unset IFS + Label=${udisksinfo[0]##*:} + fi + fi + read -rd '' Label <<< "$Label" + Label="${Label// /_}" + read -rd '' Vendor <<< "$Vendor" + Vendor="${Vendor// /_}" + read -rd '' Model <<< "$Model" + Model="${Model// /_}" + read -rd '' Serial <<< "$Serial" + Serial="${Serial// /_}" + read -rd '' Mountpoint <<< "$Mountpoint" + Mountpoint="${Mountpoint// /_}" + if [[ ! "${Mountpoint}" == "" ]] ; then + Mountpoint="---MOUNTED_at_${Mountpoint}" + fi + MenuText="$MenuText $menuitem ${dev}.${SizeString}.${Label}.${Vendor}.${Model}.${Serial}${Mountpoint}" + (( menuitem++ )) +done +DisplayText="$SelectUSBDrive" +DisplayMenu +Selected=$(<$FileNameTemp) +rm -f "$FileNameTemp" + +if [[ "${Selected}" == "" ]] ; then + exit 5 # Cancel selected +fi + +of="${usbdrives[$Selected]}" +ofsize="${usbsize[$Selected]}" +ddcmd="dcfldd sizeprobe=if statusinterval=5 if='""$if""' of=/dev/$of bs=1M" + +read label IsoSize rest<<<"$(stat $if|grep Size)" +if (( $IsoSize > $ofsize )) ; then + TooBig=$(eval_gettext "ISO size is \$IsoSize bytes. Selected USB stick only has room for \$ofsize bytes. Copy cancelled. Exiting.") + ShowMsgExit "$TooBig" + exit 7 +fi + +ConfirmRun=$(eval_gettext "About to run\${Newline}\${ddcmd}\${Newline}Please select yes to confirm, or no to cancel.\${Newline}NOTE: When it runs, please wait for 'rc=0' before continuing.") +$dialogcmd --backtitle "$TitleString" \ + --title "copyiso2usb" \ + --yesno "$ConfirmRun" "$MaxLines" "$MaxColumns" +Selected=$? + +if (($Selected)) ; then + ShowMsgExit "$CopyCancelled" + exit 7 +fi + +DisplayText="$WaitCopy" +RunCommand "${ddcmd} 2>&1" +exit 0 + diff --git a/usr/share/applications/copyiso2usb.desktop b/usr/share/applications/copyiso2usb.desktop new file mode 100644 index 0000000..7a4b5be --- /dev/null +++ b/usr/share/applications/copyiso2usb.desktop @@ -0,0 +1,89 @@ +[Desktop Entry] +Name=Copy iso image to a usb drive +Name[ar]=Copy iso image to a usb drive +Name[ast]=Copy iso image to a usb drive +Name[bg]=Copy iso image to a usb drive +Name[br]=Copy iso image to a usb drive +Name[ca]=Copy iso image to a usb drive +Name[cs]=Copy iso image to a usb drive +Name[cy]=Copy iso image to a usb drive +Name[da]=Copy iso image to a usb drive +Name[de]=Copy iso image to a usb drive +Name[el]=Copy iso image to a usb drive +Name[eo]=Copy iso image to a usb drive +Name[es]=Copy iso image to a usb drive +Name[et]=Copy iso image to a usb drive +Name[eu]=Copy iso image to a usb drive +Name[fi]=Copy iso image to a usb drive +Name[fr]=Copy iso image to a usb drive +Name[gl]=Copy iso image to a usb drive +Name[he]=Copy iso image to a usb drive +Name[hu]=Copy iso image to a usb drive +Name[id]=Copy iso image to a usb drive +Name[is]=Copy iso image to a usb drive +Name[it]=Copy iso image to a usb drive +Name[ja]=Copy iso image to a usb drive +Name[ky]=Copy iso image to a usb drive +Name[ltg]=Copy iso image to a usb drive +Name[ms]=Copy iso image to a usb drive +Name[nb]=Copy iso image to a usb drive +Name[nl]=Copy iso image to a usb drive +Name[nn]=Copy iso image to a usb drive +Name[pl]=Copy iso image to a usb drive +Name[pt]=Copy iso image to a usb drive +Name[pt_BR]=Copy iso image to a usb drive +Name[ro]=Copy iso image to a usb drive +Name[ru]=Copy iso image to a usb drive +Name[sl]=Copy iso image to a usb drive +Name[sv]=Copy iso image to a usb drive +Name[tr]=Copy iso image to a usb drive +Name[uk]=Copy iso image to a usb drive +Name[uz]=Copy iso image to a usb drive +Name[uz@cyrillic]=Copy iso image to a usb drive +Name[zh_CN]=Copy iso image to a usb drive +Name[zh_TW]=Copy iso image to a usb drive +Icon=copyiso2usb +Exec=/usr/bin/copyiso2usb +Comment=A tool to copy an iso image to a usb drive. +Comment[ar]=A tool to copy an iso image to a usb drive. +Comment[ast]=A tool to copy an iso image to a usb drive. +Comment[br]=A tool to copy an iso image to a usb drive. +Comment[cs]=A tool to copy an iso image to a usb drive. +Comment[cy]=A tool to copy an iso image to a usb drive. +Comment[da]=A tool to copy an iso image to a usb drive. +Comment[de]=A tool to copy an iso image to a usb drive. +Comment[el]=A tool to copy an iso image to a usb drive. +Comment[eo]=A tool to copy an iso image to a usb drive. +Comment[es]=A tool to copy an iso image to a usb drive. +Comment[et]=A tool to copy an iso image to a usb drive. +Comment[eu]=A tool to copy an iso image to a usb drive. +Comment[fi]=A tool to copy an iso image to a usb drive. +Comment[fr]=A tool to copy an iso image to a usb drive. +Comment[gl]=A tool to copy an iso image to a usb drive. +Comment[he]=A tool to copy an iso image to a usb drive. +Comment[hu]=A tool to copy an iso image to a usb drive. +Comment[id]=A tool to copy an iso image to a usb drive. +Comment[is]=A tool to copy an iso image to a usb drive. +Comment[it]=A tool to copy an iso image to a usb drive. +Comment[ja]=A tool to copy an iso image to a usb drive. +Comment[ky]=A tool to copy an iso image to a usb drive. +Comment[mk]=A tool to copy an iso image to a usb drive. +Comment[ms]=A tool to copy an iso image to a usb drive. +Comment[nb]=A tool to copy an iso image to a usb drive. +Comment[nl]=A tool to copy an iso image to a usb drive. +Comment[nn]=A tool to copy an iso image to a usb drive. +Comment[pl]=A tool to copy an iso image to a usb drive. +Comment[pt]=A tool to copy an iso image to a usb drive. +Comment[pt_BR]=A tool to copy an iso image to a usb drive. +Comment[ro]=A tool to copy an iso image to a usb drive. +Comment[ru]=A tool to copy an iso image to a usb drive. +Comment[sl]=A tool to copy an iso image to a usb drive. +Comment[sv]=A tool to copy an iso image to a usb drive. +Comment[tr]=A tool to copy an iso image to a usb drive. +Comment[uk]=A tool to copy an iso image to a usb drive. +Comment[zh_CN]=A tool to copy an iso image to a usb drive. +Comment[zh_TW]=A tool to copy an iso image to a usb drive. +Terminal=false +Type=Application +Categories=System; +StartupNotify=false diff --git a/usr/share/icons/copyiso2usb.png b/usr/share/icons/copyiso2usb.png Binary files differnew file mode 100644 index 0000000..6eb0a58 --- /dev/null +++ b/usr/share/icons/copyiso2usb.png diff --git a/usr/share/man/man1/copyiso2usb.1 b/usr/share/man/man1/copyiso2usb.1 new file mode 100644 index 0000000..afd5f5c --- /dev/null +++ b/usr/share/man/man1/copyiso2usb.1 @@ -0,0 +1,17 @@ +.TH COPYISO2USB 1 "September 2013" "Mageia utilities" "User Commands" +.SH NAME +copyiso2usb \- copy an iso file to a usb drive +.SH SYNOPSIS +.B copyiso2usb +.RI "<file>" +.SH DESCRIPTION +.\" Add any additional description here +.PP +If no file is specified, the option to update the locate database +is given, and if requested, the database is updated after which +a list of available iso files is presented for selection. + +The list of available usb drives is presented for selection. Once +selected, and after confirmation, the specified file or selected +iso file is copied to the usb drive. + |