have different dists
[camarabuntu.git] / bin / extract-cd-contents.sh
blob78234b966afe5c3721fe096a9fd46cd0fa568136
1 #! /bin/bash
3 ISO=$1
4 DIR_NAME=$2
6 function help {
7 echo "USAGE: $0 <path of .iso> <path to dir to extract to>"
8 exit
11 case $1 in
12 "-h"|"--help")
13 help
14 esac
16 if [ ! "$ISO" -o ! "$DIR_NAME" ] ; then
17 help
20 function cleanup {
21 local status=$1
22 sudo umount "${TMP_DIR}"
23 rmdir "${TMP_DIR}"
24 exit $status
27 trap cleanup SIGINT SIGTERM
29 if [ ! -d "${DIR_NAME}" ] ; then
30 mkdir -p "${DIR_NAME}" || exit $?
31 else
32 rm -rf "${DIR_NAME}"
35 TMP_DIR=$(mktemp -t -d cd-image-XXXXXX)
36 [ "$TMP_DIR" ] || exit 1
38 echo "Mounting the CD image now, you may need to enter your root password "
39 sudo mount -o loop "${ISO}" "${TMP_DIR}" || exit $?
40 echo " ... Done"
42 echo -n "CD mounted, starting file copy "
43 cp -rT "${TMP_DIR}" "${DIR_NAME}" || cleanup $?
44 echo " ... Done"
46 echo -n "Updating permissions on cd image "
47 find "${DIR_NAME}" -exec chmod +w '{}' ';' # why not just 'chmod -R +w' ?
48 echo " ... Done"
50 echo "All Done"
52 cleanup