source: /cluster/svnroot/bccd-ng/tags/bccd-3.3.2-rc/bin/extract_squashfs @ 4726

Last change on this file since 4726 was 4726, checked in by skylar, 7 years ago

merging in changes for bccd-3.3.2-rc (#745, #774, #833, #837, #838, #840, #842, #843, #844, #846, #847, #848)

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1#!/bin/bash
2
3set -eo pipefail
4
5function usage() {
6    echo -e "$(basename $0) -i <path-to-bccd-iso>\n" >&2
7    echo "Extract the KNOPPIX/KNOPPIX squashfs to a directory" >&2
8    echo "See http://bccd.net/wiki/index.php/DevelopmentInstructions#Regenerating_KNOPPIX.2FKNOPPIX_squashfs for more details" >&2
9}
10
11function cleanup() {
12    local RC=$1
13    local ISO_MOUNT=$2
14    local SQUASHFS_MOUNT=$3
15    local ISO_DIR=$4
16    local SQUASHFS_DIR=$5
17
18    # Clear trap so we don't get in a loop
19    trap - INT TERM ERR EXIT
20
21    # Don't care about failure at this point
22    set +e
23
24    for DIR in ${ISO_MOUNT} ${SQUASHFS_MOUNT}; do
25        if mount | grep -q ${DIR} > /dev/null; then
26            /bin/umount ${DIR}
27            /bin/rmdir ${DIR}
28        fi
29    done
30
31    # Only delete squashfs on failure
32    if [[ ${RC} -ne 0 ]]; then
33        if [[ ${SQUASHFS_DIR} =~ ^/tmp ]] && [[ -d ${SQUASHFS_DIR} ]]; then
34            /bin/rm -fr ${SQUASHFS_DIR}
35        fi
36        if [[ ${ISO_DIR} =~ ^/tmp ]] && [[ -d ${ISO_DIR} ]]; then
37            bin/rm -fr ${ISO_DIR}
38        fi
39    fi
40
41    exit ${RC}
42}
43
44# Cleanup temp dirs on error or exit, using $? as exit
45trap 'cleanup $? ${ISO_MOUNT} ${SQUASHFS_MOUNT} ${ISO_DIR} ${SQUASHFS_DIR}' \
46    INT TERM ERR EXIT
47
48while getopts "hi:" option; do
49    case ${option} in
50        h)
51            usage
52            exit 1
53            ;;
54        i)
55            ISO_PATH=${OPTARG}
56            ;;
57    esac
58done
59
60if [[ $(whoami) != "root" ]]; then
61    echo "$(basename $0) must be run as root!" >&2
62    exit 2
63elif [[ -z ${ISO_PATH} ]]; then
64    echo "Supply all arguments!" >&2
65    usage
66    exit 1
67elif [[ ! -f ${ISO_PATH} ]] || [[ ! -r ${ISO_PATH} ]]; then
68    echo "${ISO_PATH} does not exist or is unreadable" >&2
69    exit 2
70fi
71
72ISO_MOUNT=$(/bin/mktemp -d -p /tmp bccd_mount.XXXXXX)
73SQUASHFS_MOUNT=$(/bin/mktemp -d -p /tmp squashfs_mount.XXXXXX)
74ISO_DIR=$(/bin/mktemp -d -p /tmp bccd.XXXXXX)
75SQUASHFS_DIR=$(/bin/mktemp -d -p /tmp squashfs.XXXXXX)
76SQUASHFS=${ISO_DIR}/KNOPPIX/KNOPPIX
77
78echo "Mounting ${ISO_PATH} to ${ISO_MOUNT}" >&2
79/bin/mount ${ISO_PATH} ${ISO_MOUNT} -o loop,ro
80
81echo "Copying ${ISO_MOUNT} to ${ISO_DIR}" >&2
82/bin/tar -C ${ISO_MOUNT} -cf - . | /bin/tar -C ${ISO_DIR} -xf -
83
84if [[ ! -f ${SQUASHFS} ]]; then
85    echo "${SQUASHFS} does not exist, not BCCD ISO?" >&2
86    exit 2
87fi
88
89echo "Mounting ${SQUASHFS} to ${SQUASHFS_MOUNT}" >&2
90/bin/mount ${SQUASHFS} ${SQUASHFS_MOUNT} -o loop,ro
91
92echo "Copying ${SQUASHFS_MOUNT} to ${SQUASHFS_DIR}" >&2
93/bin/tar -C ${SQUASHFS_MOUNT} -cf - . | /bin/tar -C ${SQUASHFS_DIR} -xf -
94
95echo "ISO: ${ISO_DIR}"
96echo "SQUASHFS: ${SQUASHFS_DIR}"
Note: See TracBrowser for help on using the repository browser.