Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow Multiple Concurrent Mirrors

This is a change I've been meaning to make for a while now.

Now you can build a few mirrors at the same time.
In general, though, I've used this opportunity to tighten everything.

There's more error checking than there was, it refuses certain things.

I've tried to make it "backward compatible" in that if you only ever
have one at a time, it will work as it previously did.

It does that by picking the only one if there's only one.
It also tries to clean up more than it used to.

Specifically, if you clean up the last mirror, it should be as though
you never had any.
  • Loading branch information...
commit 04b3ce806e269461725c9ca605aa6e29e48b3b79 1 parent 4fec072
@psycotica0 authored
Showing with 107 additions and 49 deletions.
  1. +48 −13 breakdown_mirror
  2. +35 −34 build_mirror
  3. +24 −2 enter_mirror
View
61 breakdown_mirror
@@ -1,27 +1,62 @@
#!/bin/sh
-CACHE_LOCATION="/mnt/cache"
-UNION_LOCATION="/mnt/union"
+DATA_LOCATION="/mnt/easy_mirror"
+MIRROR_NAME="$1"
+
+if [ '!' -d "$DATA_LOCATION" ]; then
+ echo "There are no active mirrors" >&2
+ exit 1
+fi
+
+# Need to be root to chroot
+if [ "$(whoami)" != "root" ]; then
+ echo "You're going to want to be root" >&2
+ exit 2
+fi
+
+if [ -z "$MIRROR_NAME" ]; then
+ if [ "$(ls "$DATA_LOCATION" | wc -l)" = 1 ]; then
+ # Pick the only open mirror
+ MIRROR_NAME="$(ls "$DATA_LOCATION")"
+ else
+ echo "Mirror name must be given" >&2
+ exit 1
+ fi
+fi
+
+UNION_LOCATION="$DATA_LOCATION/$MIRROR_NAME/union"
+CACHE_LOCATION="$DATA_LOCATION/$MIRROR_NAME/cache"
+
+if [ '!' -d "$UNION_LOCATION" ]; then
+ echo "'$DATA_LOCATION/$MIRROR_NAME' doesn't appear to be a mirror" >&2
+ exit 4
+fi
processes="$(lsof -t "$UNION_LOCATION")"
if [ -n "$processes" ]; then
echo "Some processes are still using the mirror, kill anyway?"
read answer
- if [ "$answer" = "y" -o "$answer" = "yes" ]; then
+ if [ "$answer" = "Y" -o "$answer" = "y" -o "$answer" = "yes" ]; then
echo "$processes" | xargs kill
else
- exit
+ echo "Aborting breakdown"
+ exit 3
fi
fi
# This is inelegant, but I don't care
-umount -l "$UNION_LOCATION"/tmp
-umount -l "$UNION_LOCATION"/proc
-umount -l "$UNION_LOCATION"/sys
-umount -l "$UNION_LOCATION"/dev/shm
-umount -l "$UNION_LOCATION"/dev/pts
-umount -l "$UNION_LOCATION"/dev
-umount -l "$UNION_LOCATION"/
-
-umount -l "$CACHE_LOCATION"
+for dir in tmp proc sys dev/shm dev/pts dev .; do
+ umount "$UNION_LOCATION/$dir"
+done
+
+rmdir "$UNION_LOCATION"
+
+umount "$CACHE_LOCATION"
+rmdir "$CACHE_LOCATION"
+
+rmdir "$DATA_LOCATION/$MIRROR_NAME"
+
+if [ "$(ls "$DATA_LOCATION" | wc -l)" = 0 ]; then
+ rmdir "$DATA_LOCATION"
+fi
View
69 build_mirror
@@ -2,13 +2,19 @@
IMAGE_FILE="$1"
IMAGE_SIZE="1600M"
-CACHE_LOCATION="/mnt/cache"
-UNION_LOCATION="/mnt/union"
+DATA_LOCATION="/mnt/easy_mirror"
+MIRROR_NAME="$2"
if [ -z "$IMAGE_FILE" ]; then
echo "Please pass the path where you want your image file" >&2
fi
+if [ -z "$MIRROR_NAME" ]; then
+ MIRROR_NAME="$(basename "${IMAGE_FILE%.*}")"
+fi
+
+MIRROR_LOCATION="$DATA_LOCATION/$MIRROR_NAME"
+
# Need to be root for some mount operations
if [ "$(whoami)" != "root" ]; then
echo "You're going to want to be root" >&2
@@ -27,43 +33,38 @@ if [ ! -e "$IMAGE_FILE" ]; then
echo "Image Created"
fi
-if [ -z "$(mount | grep -w "$CACHE_LOCATION")" ]; then
- # Mounting Image
- mkdir -p "$CACHE_LOCATION"
- if ! mount -t ext2 -o loop "$IMAGE_FILE" "$CACHE_LOCATION"; then
- echo "Failed to Mount Image" >&2
- exit 1
- fi
- echo "Mounted Image"
+if [ -d "$MIRROR_LOCATION" ]; then
+ echo "Folder already exists at '$MIRROR_LOCATION'" >&2
+ echo "Remove that folder if you wish to continue, or choose another name for this mirror" >&2
+ exit 1
fi
-if [ -z "$(mount | grep -w "$UNION_LOCATION")" ]; then
- # Create Union
- if ! mount -t aufs -o dirs="$CACHE_LOCATION:/=ro" none "$UNION_LOCATION"; then
- echo "Failed to Mount Union" >&2
- exit 1
- fi
- echo "Mounted Union"
-fi
+CACHE_LOCATION="$MIRROR_LOCATION/cache"
+UNION_LOCATION="$MIRROR_LOCATION/union"
-if [ -z "$(mount | grep -w "$UNION_LOCATION"/dev)" ]; then
- mount --bind /dev "$UNION_LOCATION"/dev 2> /dev/null
-fi
+mkdir -p "$MIRROR_LOCATION" "$CACHE_LOCATION" "$MIRROR_LOCATION/union"
-if [ -z "$(mount -t devpts | grep -w "$UNION_LOCATION"/dev/pts)" ]; then
- mount -t devpts devpts "$UNION_LOCATION"/dev/pts 2> /dev/null
-fi
-if [ -z "$(mount -t tmpfs | grep -w "$UNION_LOCATION"/dev/shm)" ]; then
- mount -t tmpfs shm "$UNION_LOCATION"/dev/shm 2> /dev/null
+if ! mount -t ext2 -o loop "$IMAGE_FILE" "$CACHE_LOCATION"; then
+ echo "Failed to Mount Image" >&2
+ exit 1
fi
+echo "Mounted Image"
-if [ -z "$(mount -t sysfs | grep -w "$UNION_LOCATION"/sys)" ]; then
- mount -t sysfs sysfs "$UNION_LOCATION"/sys 2> /dev/null
+# Create Union
+if ! mount -t aufs -o dirs="$CACHE_LOCATION:/=ro" none "$UNION_LOCATION"; then
+ echo "Failed to Mount Union" >&2
+ exit 1
fi
+echo "Mounted Union"
-if [ -z "$(mount -t proc | grep -w "$UNION_LOCATION"/proc)" ]; then
- mount -t proc proc "$UNION_LOCATION"/proc 2> /dev/null
-fi
-if [ -z "$(mount | grep -w "$UNION_LOCATION"/tmp)" ]; then
- mount --bind /tmp "$UNION_LOCATION"/tmp 2> /dev/null
-fi
+mount --bind /dev "$UNION_LOCATION"/dev 2> /dev/null
+
+mount -t devpts devpts "$UNION_LOCATION"/dev/pts 2> /dev/null
+
+mount -t tmpfs shm "$UNION_LOCATION"/dev/shm 2> /dev/null
+
+mount -t sysfs sysfs "$UNION_LOCATION"/sys 2> /dev/null
+
+mount -t proc proc "$UNION_LOCATION"/proc 2> /dev/null
+
+mount --bind /tmp "$UNION_LOCATION"/tmp 2> /dev/null
View
26 enter_mirror
@@ -1,5 +1,27 @@
#!/bin/sh
-UNION_LOCATION="/mnt/union"
+DATA_LOCATION="/mnt/easy_mirror"
+MIRROR_NAME="$1"
-chroot "$UNION_LOCATION" su -l "$SUDO_USER"
+if [ '!' -d "$DATA_LOCATION" ]; then
+ echo "There are no active mirrors" >&2
+ exit 1
+fi
+
+# Need to be root to chroot
+if [ "$(whoami)" != "root" ]; then
+ echo "You're going to want to be root" >&2
+ exit 2
+fi
+
+if [ -z "$MIRROR_NAME" ]; then
+ if [ "$(ls "$DATA_LOCATION" | wc -l)" = 1 ]; then
+ # Pick the only open mirror
+ MIRROR_NAME="$(ls "$DATA_LOCATION")"
+ else
+ echo "Mirror name must be given" >&2
+ exit 1
+ fi
+fi
+
+chroot "$DATA_LOCATION/$MIRROR_NAME/union" su -l "$SUDO_USER"
Please sign in to comment.
Something went wrong with that request. Please try again.