Skip to content

Instantly share code, notes, and snippets.

@jodoherty
Last active December 18, 2015 17:59
Show Gist options
  • Save jodoherty/ad8b4aba9bb8bf2ee29d to your computer and use it in GitHub Desktop.
Save jodoherty/ad8b4aba9bb8bf2ee29d to your computer and use it in GitHub Desktop.
burnr xorriso wrapper script
#!/bin/sh
#
# burnr 0.2.0
#
# Copyright (c) 2015 James O'Doherty <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Requires xorriso
#
usage() {
cat <<EOF >&2
Usage: $0
[ --help|-h|-? ] Display help
[ --out|-o "..." ] Set output device or file
[ --dry ] Dry run (show commands and exit)
[ --force|-f ] Force blanking on rewritable discs
[ --name|-n "..." ] Set volume name for disc
path Input device, directory, or file
EOF
}
if ! which xorriso > /dev/null 2>&1 || ! [ -x "$(which xorriso)" ]
then
echo "$0 requires the xorriso package to be installed:" >&2
if which yum > /dev/null 2>&1
then
echo " # yum install xorriso" >&2
fi
if which apt-get > /dev/null 2>&1
then
if which sudo > /dev/null 2>&1
then
echo " $ sudo apt-get install xorriso" >&2
else
echo " # apt-get install xorriso" >&2
fi
fi
exit 1
fi
dryrun=false
force=false
input=
intype=
options=
output=
postcmd=
verbose=false
volid=`date +%Y_%m_%d`
while [ $# -gt 0 ]; do
case $1 in
--force|-f)
force=true
;;
--name|-n)
volid="$2"
shift
;;
-o)
if [ "$output" != "" ]; then
echo Please specify only one output device or file
exit 1
fi
output="$2"
shift
;;
--dry)
verbose=true
dryrun=true
;;
-?|-h|--help)
usage
exit 1
;;
*)
if [ "$input" != "" ]; then
echo Please specify only one input directory or ISO file
exit 1
fi
input="$1"
;;
esac
shift
done
if [ "$output" == "" ]; then
output=/dev/dvd
fi
if [ "$input" == "" ]; then
echo Please specify an input directory or ISO file
exit 1
fi
case "$input" in
/dev/*)
intype=dev
;;
*.[iI][sS][oO])
if ! [ -f "$input" ]; then
echo Error: Expected ISO file, but $input doesn"'"t exist
exit 1
fi
intype=iso
;;
*)
if ! [ -d "$input" ]; then
echo Error: Expected directory
exit 1
fi
intype=dir
;;
esac
case "$output" in
/dev/*)
umount "$output" > /dev/null 2>&1
options="-close on $options"
postcmd="$postcmd -eject"
if $force
then
precmd="$precmd -blank as_needed"
fi
;;
*)
if [ "$intype" == "iso" ]
then
echo "Error: Burning an iso to a non-device target" >&2
usage
exit 1
fi
;;
esac
dry=
if $dryrun; then
dry=echo
fi
case $intype in
dev)
umount "$input" > /dev/null 2>&1
if ! which readom > /dev/null 2>&1 || ! [ -x "$(which readom)" ]
then
echo "$0 requires readom to be installed to read discs" >&2
if which yum > /dev/null 2>&1
then
echo " # yum install wodim" >&2
fi
if which apt-get > /dev/null 2>&1
then
if which sudo > /dev/null 2>&1
then
echo " $ sudo apt-get install wodim" >&2
else
echo " # apt-get install wodim" >&2
fi
fi
exit 1
fi
case "$output" in
*.[Ii][Ss][Oo])
$dry readom "dev=$input" "f=$output"
;;
*)
echo "Error: expected output file path" >&2
exit 1
;;
esac
;;
iso)
case "$output" in
/dev/*)
$dry xorriso -abort_on FATAL $options -as cdrecord -v \
"dev=$output" blank=as_needed "$input" \
-eject
;;
*)
echo "Error: expected output drive device path" >&2
exit 1
;;
esac
;;
dir)
case "$output" in
/dev/*|*.[Ii][Ss][Oo])
$dry xorriso -abort_on FATAL -volid "$volid" $options \
-joliet on -in_charset utf-8 \
-outdev "$output" \
$precmd \
-map "$input" / \
-find / -type file -exec chmod a+r,a-wx -- \
-find / -type dir -exec chmod a+rx,a-w -- \
-commit -toc \
$postcmd
;;
*)
echo "Error: output not a drive or ISO file path" >&2
exit 1
;;
esac
;;
*)
echo Unknown input type >&2
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment