Permalink
Browse files

Added Creation Callbacks

So, if certain scripts exist, they will be run with the mirror is built.

This is something I've wanted for quite a while.
There are a series of things I always did as soon as I built a mirror so
I could tell it apart and use it and stuff.

Now this is all in scripts, so it'll just be done for me.
Happy.
  • Loading branch information...
1 parent 4cc6c2e commit ec92c36052ebe2c8c62f327e6d21526cf7421f42 @psycotica0 committed Nov 13, 2012
Showing with 40 additions and 3 deletions.
  1. +24 −3 README
  2. +16 −0 build_mirror
View
27 README
@@ -24,6 +24,27 @@ If you have more than one mounted at a time, then you'll need to specify.
sudo breakdown_mirror test
-Tip:
-I tend to change .bashrc when I make a new image to put CHROOT in the PS1.
-That way I can tell when I'm in and when I'm not.
+Callbacks:
+I've got a system in place for scripts that you want to be run every time
+a new mirror is setup.
+
+The scripts are searched for in ~/.local/share/easy_mirror/
+The '~' in this case is relative to the user who's running the scripts (Not root, even when under sudo)
+Similarly, the scripts are run by that user, not root.
+
+There are currently two:
+new_image.sh
+ This one is run every time a new cache file was created.
+ It is not run if you're just remounting an existing cache.
+new_mirror.sh
+ This one is run every time a new mirror is built, whether or not the image file is new.
+
+Both of these scripts are run with the name of the mirror as the first argument.
+If either of these scripts don't exist, or aren't executable, then they just won't be run.
+
+I use new_image.sh for adding
+export PS1="$MIRROR_NAME-$PS1"
+to ~/.bashrc, so I can tell the mirrors apart from each other, and the root system.
+
+I use new_mirror.sh to make sure some state is removed so that the mirror is independent from the host.
+
View
@@ -5,6 +5,8 @@ IMAGE_SIZE="1600M"
DATA_LOCATION="/mnt/easy_mirror"
MIRROR_NAME="$2"
+NEW_IMAGE="0"
+
if [ -z "$IMAGE_FILE" ]; then
echo "Please pass the path where you want your image file" >&2
fi
@@ -31,6 +33,7 @@ if [ ! -e "$IMAGE_FILE" ]; then
mkfs.ext2 -M "$UNION_LOCATION" -F "$IMAGE_FILE"
echo "Image Created"
+ NEW_IMAGE="1"
fi
if [ -d "$MIRROR_LOCATION" ]; then
@@ -68,3 +71,16 @@ 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
+
+# Check for "callbacks"
+NEW_MIRROR_CALLBACK="/home/$SUDO_USER/.local/share/easy_mirror/new_mirror.sh"
+NEW_IMAGE_CALLBACK="/home/$SUDO_USER/.local/share/easy_mirror/new_image.sh"
+if [ "$NEW_IMAGE" = 1 -a -x "$NEW_IMAGE_CALLBACK" ]; then
+ echo "Running New Image Callback"
+ enter_mirror "$MIRROR_NAME" "$NEW_IMAGE_CALLBACK" "$MIRROR_NAME"
+fi
+
+if [ -x "$UNION_LOCATION/$NEW_MIRROR_CALLBACK" ]; then
+ echo "Running New Mirror Callback"
+ enter_mirror "$MIRROR_NAME" "$NEW_MIRROR_CALLBACK" "$MIRROR_NAME"
+fi

0 comments on commit ec92c36

Please sign in to comment.