| 1 | 3c3,8 |
|---|
| 2 | < try_bind_umount() { |
|---|
| 3 | --- |
|---|
| 4 | > temp_dirs= |
|---|
| 5 | > mount_points= |
|---|
| 6 | > |
|---|
| 7 | > # Unmount all directories mounted by cross-shell and delete all temporary |
|---|
| 8 | > # directories created by cross-shell |
|---|
| 9 | > unmount_all() { |
|---|
| 10 | 5c10,25 |
|---|
| 11 | < while $ROOT_CMD umount $_shared_mounts_MOUNTPOINT 2>/dev/null; do :; done |
|---|
| 12 | --- |
|---|
| 13 | > |
|---|
| 14 | > for _mount_point in $mount_points; do |
|---|
| 15 | > |
|---|
| 16 | > # If the mount point is still mounted |
|---|
| 17 | > if fgrep -q "$_mount_point" < /etc/mtab; then |
|---|
| 18 | > |
|---|
| 19 | > # Unmount it |
|---|
| 20 | > $ROOT_CMD umount "$_mount_point" |
|---|
| 21 | > fi |
|---|
| 22 | > done |
|---|
| 23 | > |
|---|
| 24 | > for _temp_dir in $temp_dirs; do |
|---|
| 25 | > |
|---|
| 26 | > # Remove the temp dir and any empty parent dirs |
|---|
| 27 | > $ROOT_CMD rmdir -p "$_temp_dir" 2> /dev/null || : |
|---|
| 28 | > done |
|---|
| 29 | 10c30,39 |
|---|
| 30 | < fgrep -q $2 < /etc/mtab || $ROOT_CMD mount --bind $1 $2 |
|---|
| 31 | --- |
|---|
| 32 | > _old_path=$1 |
|---|
| 33 | > _new_path=$2 |
|---|
| 34 | > |
|---|
| 35 | > if ! fgrep -q $_new_path < /etc/mtab; then |
|---|
| 36 | > $ROOT_CMD mount --bind $_old_path $_new_path |
|---|
| 37 | > fi |
|---|
| 38 | > |
|---|
| 39 | > mount_points="$mount_points $_new_path" |
|---|
| 40 | > trap unmount_all 0 INT QUIT KILL TERM |
|---|
| 41 | > } |
|---|
| 42 | 12,13c41,62 |
|---|
| 43 | < _shared_mounts_MOUNTPOINT=$2 |
|---|
| 44 | < trap try_bind_umount 0 INT QUIT KILL TERM |
|---|
| 45 | --- |
|---|
| 46 | > try_mount_repo() { |
|---|
| 47 | > _chroot_path=$1 |
|---|
| 48 | > _local_rep=$2 |
|---|
| 49 | > |
|---|
| 50 | > # Strip any meaningless trailing dots and slashes from the chroot path |
|---|
| 51 | > _trimmed_chroot_path=$(echo "$_chroot_path" | sed 's|/\.\?$||') |
|---|
| 52 | > |
|---|
| 53 | > # If the local repo directory isn't already mounted |
|---|
| 54 | > if ! fgrep -q "$_trimmed_chroot_path$_local_rep" < /etc/mtab; then |
|---|
| 55 | > |
|---|
| 56 | > # Make a mount dir within chroot and mount the local repo dir to it |
|---|
| 57 | > $ROOT_CMD mkdir -p "$_trimmed_chroot_path$_local_rep" |
|---|
| 58 | > $ROOT_CMD mount --bind "$_local_rep" "$_trimmed_chroot_path$_local_rep" |
|---|
| 59 | > |
|---|
| 60 | > # Add local repo to list of mount points and list of temp dirs |
|---|
| 61 | > mount_points="$mount_points $_trimmed_chroot_path$_local_rep" |
|---|
| 62 | > temp_dirs="$temp_dirs $_trimmed_chroot_path$_local_rep" |
|---|
| 63 | > |
|---|
| 64 | > # Call unmount_repos to clean up the local repos when the script is |
|---|
| 65 | > # exited or interrupted |
|---|
| 66 | > trap unmount_all 0 INT QUIT KILL TERM |
|---|
| 67 | > fi |
|---|