Ticket #834: enter.2.patch

File enter.2.patch, 2.3 KB (added by EvanKroske, 23 months ago)

Final patch for the enter script. Cleans up mounted local repos if script is interrupted.

Line 
137a38,79
2> # A space-separated list of mounted repositories
3> mounted_repos=
4>
5> # Unmount all mounted repositories
6> unmount_repos() {
7>     
8>     for _mounted_repo in $mounted_repos; do
9>     
10>         # If current repo directory is actually mounted
11>         if fgrep -q "$_trimmed_chroot_path$_local_rep" < /etc/mtab; then
12>             sudo umount "$_mounted_repo"
13>         fi
14>         # Remove the repo directory and any empty parent directories
15>         sudo rmdir -p "$_mounted_repo" 2> /dev/null || :
16>     done
17>     exit
18> }
19>
20> # Mount a repository directory
21> mount_repo() {
22>     _chroot_path=$1
23>     _local_rep=$2
24>     
25>     # Strip any meaningless trailing dots and slashes from the chroot path
26>     _trimmed_chroot_path=$(echo $_chroot_path | sed 's|/\.\?$||')
27>     
28>     # If the local repo directory isn't already mounted
29>     if ! fgrep -q "$_trimmed_chroot_path$_local_rep" < /etc/mtab; then
30>         
31>         # Make a mount dir within chroot and mount the local repo dir to it
32>         sudo mkdir -p "$_trimmed_chroot_path$_local_rep"
33>         sudo mount --bind "$_local_rep" "$_trimmed_chroot_path$_local_rep"
34>         
35>         # Add local repo to list of mounted repos
36>         mounted_repos=`echo "$mounted_repos $_trimmed_chroot_path$_local_rep"`
37>         
38>         # Call unmount_repos to clean up the local repos when the script is
39>         # exited or interrupted
40>         trap unmount_repos TERM INT EXIT
41>     fi
42> }
43>
4460c102,121
45< exec sudo chroot "$CHROOT_PATH" su -l -c "$ENV_EXPORT exec \$SHELL $SU_CMD" build
46---
47> # Mount every local repository in the chroot's sources.list file that doesn't
48> # exist in the chroot file system.
49>
50> # All the local repositories mentioned in chroot's sources.list file
51> local_repos=$(egrep -o '(file:[^[:space:]]+)' < "$CHROOT_PATH/etc/apt/sources.list" | sed 's/file://')
52>
53> for local_repo in $local_repos; do
54>     # If the directory doesn't exist in the chroot file system
55>     if [ ! -e "$CHROOT_PATH$local_repo" ]; then
56>         
57>         # If the directory does exist in the exterior file system
58>         if [ -d "$local_repo" ]; then
59>             
60>             # Make a mount dir and mount the exterior repository dir to it
61>             mount_repo "$CHROOT_PATH" "$local_repo"
62>         fi
63>     fi
64> done
65>
66> sudo chroot "$CHROOT_PATH" su -l -c "$ENV_EXPORT exec \$SHELL $SU_CMD" build