File: loopback.sh

package info (click to toggle)
bashburn 3.0.1-2~deb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,140 kB
  • sloc: sh: 2,584; sed: 64; makefile: 19
file content (116 lines) | stat: -rwxr-xr-x 2,847 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

# Directory names
typeset -r bb_lb_dir=/tmp/bb-loopback
typeset -r bb_im_copy_dir="/tmp/imagecopy"

#
# This file has functions for mounting an image file in a loopback
# device and edit its contents. After editing, a new image file
# is created containing the edited material.
#

# Remove temporary directories
loopback_cleanup()
{
    sudo umount "$bb_lb_dir"
    rm -rf "$bb_im_copy_dir"/*
}

loopback()
{
    typeset -r mntcmd="mount -t iso9660 -o loop $1 $bb_lb_dir"
    typeset answer
    # Bad filename?
    if [[ ! -r "$1" ]]
    then
	echo " \"$1\" $bb_lb_noread"
	return 100	# FIXME: HOLD ON THAR BULLWINKLE
    fi

     # Create necessary directories if possible
    if [[ ! -e "$bb_lb_dir" ]]
    then
	echo "$bb_lb_no_lb_dir"
	mkdir -p "$bb_lb_dir" || { echo "$bb_lb_dir_cf"; return 2; }
	echo "$bb_lb_dir_c"
    fi


    if [[ ! -e "$bb_im_copy_dir" ]]
    then
	echo "$bb_lb_no_im_dir"
	mkdir -p "$bb_im_copy_dir" || { echo "$bb_lb_dir_cf"; return 3; }
	echo "$bb_lb_dir_c"
    fi

    if [[ ! -e "${BBBURNDIR}" ]]
    then
	echo "$bb_lb_no_temp_dir"
	mkdir -p ${BBBURNDIR} || { echo "$bb_lb_dir_cf"; return 4; }
	echo "$bb_lb_dir_c"
    fi

    # Mount the CD image in a loopback device
    if [[ "$USER" != root ]]
    then
	echo "$bb_lb_sudo1"
	echo "$bb_lb_sudo2"
	echo "$bb_lb_sudo3"
	echo "$bb_lb_sudo4"
	echo "$bb_lb_sudo5"
	echo "$bb_lb_sudo6"
	sudo $mntcmd || { echo "$bb_lb_mount_fail"; return 5; }
	echo "$bb_lb_mount"
    else
	$mntcmd || { echo "$bb_lb_mount_fail"; 	return 6; }
    fi
    echo "$bb_lb_mount"

    # Copy contents from the mounted image to another directory and set
    # new permissions so its contents can be manipulated.
    echo "$bb_lb_cp_cont"
    cp -R "$bb_lb_dir"/* "$bb_im_copy_dir"
    chmod -R +w "$bb_im_copy_dir"

    # Change to new directory and start a shell session there
    cd "$bb_im_copy_dir"
    echo "$bb_lb_in_file"
    ${SHELL:-/bin/bash}

    # When user exits shell session, change to temporary file directory and
    # create new image file out of what user manipulated (If anything was).
    echo "$bb_lb_change1"
    echo "$bb_lb_change2"
    #echo -n "|> "
    #read answer
    read -e -p "|>" answer
    if [[ "$answer" == y ]]
    then
	# We want to make sure no data is deleted by mistake
	if [[ "$(ls -A ${BBBURNDIR})" ]];
	then
	    echo "$bb_lb_change3 \"${BBBURNDIR}\","
	    echo "$bb_lb_change4"
	    echo -n "$bb_lb_change5"
	    read -p "|>" answer
	    if [[ "$answer" == y ]]
	    then
		cd "${BBBURNDIR}"
		rm -rf "${BBBURNDIR}"/*
		echo "$bb_lb_change6"
		${BB_ISOCMD} -r -f -v -J -hide-joliet-trans-tbl \
			-o BashBurn.iso ${bb_im_copy_dir} \
		&& echo "$bb_lb_change7 \"${BBBURNDIR}\""
	    else
		echo "$bb_lb_change8"
		cleanup
	    fi
	fi 
    else
	echo "$bb_lb_change9"
    fi

    # Finally clean up our mess
    loopback_cleanup
    return 0
}