source: /cluster/svnroot/bccd-ng/branches/skylar/bccd-3.3.4/bin/extract_squashfs @ 6130

Last change on this file since 6130 was 6130, checked in by skylar, 18 months ago

new path to squashfs re #1015

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