Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fin

  • Loading branch information...
commit 1e26b31a49232d862cf37ec70b96229a3f02523b 1 parent 5044284
@ideamonk authored
View
BIN  .DS_Store
Binary file not shown
View
117 README
@@ -0,0 +1,117 @@
+ __ _ _
+ /__\ __ _ _ __ ___ | |__ ___ | | __ _
+ / \/// _` | '_ ` _ \| '_ \ / _ \| |/ _` |
+ / _ \ (_| | | | | | | |_) | (_) | | (_| |
+ \/ \_/\__,_|_| |_| |_|_.__/ \___/|_|\__,_|
+
+based on QuickSander's [1] Cache2RAM script [2]
+improvised for data retainment done right on logout/restart/shutdown/schedule
+
+Author : Abhishek Mishra
+
+
+What is this?
+-------------
+A bunch of scripts to manage a RamDisk on your mac.
+
+
+Why use a RamDisk?
+------------------
+To cache the shit you want to fly fast across the fans :D or, have a look at
+these XBench results -
+
+ HDD -
+ =====
+ Sequential 114.94
+ Uncached Write 116.50 65.92 MB/sec [256K blocks]
+ Uncached Read 140.07 70.40 MB/sec [256K blocks]
+
+ Random 33.36
+ Uncached Write 103.96 33.28 MB/sec [256K blocks]
+ Uncached Read 117.44 21.79 MB/sec [256K blocks]
+
+ RamDisk -
+ =========
+ Sequential 973.74
+ Uncached Write 2530.99 1432.04 MB/sec [256K blocks]
+ Uncached Read 2907.41 1461.24 MB/sec [256K blocks]
+ Random 3551.18
+ Uncached Write 4954.97 1586.27 MB/sec [256K blocks]
+ Uncached Read 7848.65 1456.37 MB/sec [256K blocks]
+
+
+What do I use it for?
+---------------------
+Ever since I put those 2 4gig sticks, I've been caching these on RamDisk -
+ * eclipse workspace, projects
+ * eclipse plugins
+ * android sdk platforms, whichever I'm working on
+ * Chrome cache and Application Support/Google/Chrome folder
+ * Safari Cache
+ * Firefox Cache
+
+Just symlink whatever you wish into the RamDisk.
+
+
+How do I use this?
+------------------
+Do the following on a terminal -
+ cd ~/Applications
+ git clone https://ideamonk@github.com/ideamonk/Rambola.git
+ cd Rambola
+ ./enable.sh
+
+This shall push Rambola into your Login/Logout Hooks. Just logout and log back
+in to see a RamDisk mounted in Finder.
+
+
+How do I disable this?
+----------------------
+Say you have Rambola in ~/Applications/Rambola, do this on a terminal -
+
+ ~/Applications/Rambola/disable.sh
+
+
+How do I retain RamDisk data?
+-----------------------------
+By default Rambola keeps a synced backup into ~/Library/CachesSnapshotRamDisk.
+It syncs the RamDisk every time you logout/restart/shutdown and restores when
+you start your machine back. If worried about power-cuts, then by default,
+Rambola also syncs the backup every 45 minutes in background.
+
+
+How do I disable the 45 minute syncs running in background?
+-----------------------------------------------------------
+Get into Rambola's folder, open helper.sh under src and change -
+ TIMELY_BACKUP=yes , into,
+
+ TIMELY_BACKUP=no
+
+
+How do I change the time period for automatic background syncs?
+---------------------------------------------------------------
+Get into Rambola's folder, open helper.sh under src and change the number
+in this line -
+let SAFETY_BACKUP_INTERVAL=45 # backup interval in minutes
+
+
+Does it support multiple users?
+-------------------------------
+Once enabled, it should work for every user. Though I haven't tested it out.
+
+
+Why was this created?
+---------------------
+Uh, I assumed QuickSander's sweet app Cache2RAM [2] to be too sweet to retain
+things on logout/restart/shutdown. Alas! I lost a bunch of good things I cached
+and had to modify to bend it to my own needs.
+
+
+Why is it named Rambola?
+------------------------
+Uh, I dunno, maybe 'cause ramona bambola is a bit too hot on tv.
+
+Have fun.
+
+[1] http://hints.macworld.com/users.php?mode=profile&uid=1054078
+[2] http://hints.macworld.com/article.php?story=2011010204203424
View
8 disable.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+# removes loginwindow hooks for Rambola
+
+APP_NAME=Rambola
+APP_DEST=`pwd`
+
+sudo defaults delete com.apple.loginwindow LoginHook
+sudo defaults delete com.apple.loginwindow LogoutHook
View
20 enable.sh
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+# Rambola installer (unlike Cache2RAM this is based on Login window hooks)
+
+APP_NAME=Rambola
+APP_DEST=`pwd`
+
+function setup()
+{
+ echo "Adding ${APP_NAME} to LoginHook (needs root)..."
+ sudo defaults write com.apple.loginwindow LoginHook $APP_DEST/src/rambola.sh
+ sudo defaults write com.apple.loginwindow LogoutHook $APP_DEST/src/logout.sh
+}
+
+echo "This will install and setup ${APP_NAME} at ${APP_DEST}"
+echo
+read -p "Continue (y/n) :"
+
+if [ "$REPLY" == "y" ]; then
+ setup
+fi
View
0  setup.sh
No changes.
View
109 src/helper.sh
@@ -0,0 +1,109 @@
+# Rambola helper - configurations, helper functions
+
+# Auto-filled variables
+USER_NAME=$1
+SELF=Rambola:$(basename $0)
+
+# Constants
+AS_USER="sudo -u ${USER_NAME} "
+RSYNC="/usr/local/bin/rsync -aNHAXx --delete --fileflags --protect-decmpfs "
+SLEEP_DELAY=60 # re-check count every one minute
+let SAFETY_BACKUP_INTERVAL=45 # backup interval in minutes
+
+# Settings
+RAMDISK_SIZE=1024 # Size in Mega Bytes.
+RAMDISK_NAME="RamDisk"
+SNAPSHOT_LOCATION="/Users/${USER_NAME}/Library/CachesSnapshot${RAMDISK_NAME}/"
+TIMELY_BACKUP=yes
+
+# Variables
+COUNT=0
+
+# Operational function declaration
+function log
+{
+ echo "${SELF}: $1"
+}
+
+function quit
+{
+ log "Quiting: $1"
+ exit 0
+}
+
+function lock_ramdisk
+{
+ $AS_USER exec 5>"/Volumes/${RAMDISK_NAME}/.lock.${USER_NAME}"
+}
+
+function unlock_ramdisk
+{
+ $AS_USER exec 5>&-
+ $AS_USER rm "/Volumes/${RAMDISK_NAME}/.lock.${USER_NAME}"
+}
+
+function create_ramdisk
+{
+ # Check if ramdisk is not already created and mounted.
+ if [ ! -d "/Volumes/${RAMDISK_NAME}" ]; then
+ log "Creating Ram disk (\"${RAMDISK_NAME}\") with a size of: ${RAMDISK_SIZE}MB."
+ let RAMDISK_BLOCKSIZE=2048*${RAMDISK_SIZE} # Size in blocks.
+
+ BLOCK_DEVICE=$($AS_USER hdiutil attach -nomount ram://${RAMDISK_BLOCKSIZE})
+ $AS_USER diskutil eraseVolume HFS+ "$RAMDISK_NAME" $BLOCK_DEVICE
+
+ # Update so every user can write to it while pertaining its own
+ # user permissions.
+ $AS_USER mount -u -o owners "/Volumes/${RAMDISK_NAME}"
+ $AS_USER chmod g+w "/Volumes/${RAMDISK_NAME}"
+
+ else
+ log "Ram disk (\"${RAMDISK_NAME}\") already created."
+ fi
+
+}
+
+function restore_contents_from_snapshot
+{
+ # Check if snapshot path exists
+ if [ ! -d ${SNAPSHOT_LOCATION} ]; then
+ log "Snapshot location missing: \"${SNAPSHOT_LOCATION}\" not found."
+ log "Creating snapshot path"
+ $AS_USER mkdir -p ${SNAPSHOT_LOCATION}
+ fi
+
+ DEST="/Volumes/${RAMDISK_NAME}/"
+ log "Restoring snapshot from \"${SNAPSHOT_LOCATION}\" to \"${DEST}\"."
+ $AS_USER $RSYNC "${SNAPSHOT_LOCATION}" "${DEST}"
+}
+
+function store_contents_on_snapshot
+{
+ SOURCE="/Volumes/${RAMDISK_NAME}/"
+ if [ ! -d "$SOURCE" ]; then
+ quit "Directory: \"$SOURCE\" does not exist."
+ fi
+
+ log "Storing snapshot from \"${SOURCE}\" to \"${SNAPSHOT_LOCATION}\"."
+ $AS_USER $RSYNC "${SOURCE}" "${SNAPSHOT_LOCATION}"
+}
+
+
+function store_periodically
+{
+ let COUNT=COUNT+1
+ if [[ $COUNT -gt $SAFETY_BACKUP_INTERVAL ]]; then
+ log "Starting power failure preventive backup."
+ store_contents_on_snapshot
+ let COUNT=0
+ fi
+}
+
+
+function shutdown_rambola
+{
+ log "Shutdown request received."
+ store_contents_on_snapshot
+ unlock_ramdisk
+ quit "Shutdown request finished."
+}
View
8 src/logout.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+# Rambola LogoutHook script, backs up ramdisk on logout/restart/shutdown
+
+APP_HOME=$(dirname $0)
+source $APP_HOME/helper.sh $1
+SELF=Rambola:$(/usr/bin/basename $0)
+
+shutdown_rambola
View
147 src/rambola.sh
@@ -1,147 +1,18 @@
#!/usr/bin/env bash
-:<<'_'
- __ _ _
- /__\ __ _ _ __ ___ | |__ ___ | | __ _
- / \/// _` | '_ ` _ \| '_ \ / _ \| |/ _` |
- / _ \ (_| | | | | | | |_) | (_) | | (_| |
- \/ \_/\__,_|_| |_| |_|_.__/ \___/|_|\__,_|
-
-My very own improvised RamDisk Manager.
-Heavily based on QuickSander's [1] Cache2RAM script [2]
-
-Author : Abhishek Mishra
-
-[1] http://hints.macworld.com/users.php?mode=profile&uid=1054078
-[2] http://hints.macworld.com/article.php?story=2011010204203424
-_
-
-# Auto-filled variables
-USER_NAME=$(/usr/bin/who am i | /usr/bin/awk '{print $1}')
-SELF=$(/usr/bin/basename $0)
-USER_ID=$(id | sed 's/uid=\([0-9]*\).*/\1/')
-OUR_PID=$(ps -ef | grep ${SELF} | grep -v 'grep' | awk -v uid="$USER_ID" '$1==uid {print $2; exit;}') # Only first occurence from the current user.
-
-
-# Constants
-RSYNC="/usr/local/bin/rsync -aNHAXx --fileflags --protect-decmpfs "
-SLEEP_DELAY=1
-let SAFETY_BACKUP_INTERVAL=(60*60*2)/SLEEP_DELAY # Create backup in case of power failure every 2 hours.
-
-# Settings
-RAMDISK_SIZE=1024 # Size in Mega Bytes.
-RAMDISK_NAME="RamDisk"
-SNAPSHOT_LOCATION="/Users/${USER_NAME}/Library/CachesSnapshot${RAMDISK_NAME}/"
-
-# Variables
-COUNT=
-
-# Operational function declaration
-function log
-{
- echo "${SELF}: $1"
-}
-
-function quit
-{
- log "Quiting: $1"
- exit 0
-}
-
-function lock_ramdisk
-{
- exec 5>"/Volumes/${RAMDISK_NAME}/.lock.${USER_NAME}"
-}
-
-function unlock_ramdisk
-{
- exec 5>&-
- rm "/Volumes/${RAMDISK_NAME}/.lock.${USER_NAME}"
-}
-
-function create_ramdisk
-{
- # Check if ramdisk is not already created and mounted.
- if [ ! -d "/Volumes/${RAMDISK_NAME}" ]; then
- log "Creating Ram disk (\"${RAMDISK_NAME}\") with a size of: ${RAMDISK_SIZE}MB."
- let RAMDISK_BLOCKSIZE=2048*${RAMDISK_SIZE} # Size in blocks.
-
- BLOCK_DEVICE=$(hdiutil attach -nomount ram://${RAMDISK_BLOCKSIZE})
- diskutil eraseVolume HFS+ "$RAMDISK_NAME" $BLOCK_DEVICE
-
- # Update so every user can write to it while pertaining its own
- # user permissions.
- mount -u -o owners "/Volumes/${RAMDISK_NAME}"
- chmod g+w "/Volumes/${RAMDISK_NAME}"
-
- else
- log "Ram disk (\"${RAMDISK_NAME}\") already created."
- fi
-
-}
-
-function restore_contents_from_snapshot
-{
- # Check if snapshot exists
- if [ -d ${SNAPSHOT_LOCATION} ]; then
- DEST="/Volumes/${RAMDISK_NAME}/${USER_NAME}/"
-
- log "Restoring snapshot from \"${SNAPSHOT_LOCATION}\" to \"${DEST}\"."
- $RSYNC "${SNAPSHOT_LOCATION}" "${DEST}"
- else
- log "No restore required: \"${SNAPSHOT_LOCATION}\" not found."
- fi
-}
-
-function store_contents_on_snapshot
-{
- SOURCE="/Volumes/${RAMDISK_NAME}/${USER_NAME}/"
- if [ ! -d "$SOURCE" ]; then
- quit "Directory: \"$SOURCE\" does not exist."
- fi
-
- log "Storing snapshot from \"${SOURCE}\" to \"${SNAPSHOT_LOCATION}\"."
- $RSYNC "${SOURCE}" "${SNAPSHOT_LOCATION}"
-}
-
-
-function store_periodically
-{
- let COUNT=COUNT+1
- if [ "0$COUNT" -gt $SAFETY_BACKUP_INTERVAL ]; then
- log "Starting power failure preventive backup."
- store_contents_on_snapshot
- let COUNT=0
- fi
-}
-
-
-function shutdown
-{
- log "Shutdown request received."
- store_contents_on_snapshot
- unlock_ramdisk
- quit "Shutdown request finished."
-}
-
-
-# Shutdown: Register terminate signals.
-trap shutdown TERM
-
+# Rambola LoginHook script, sets up ramdisk, spawns timely if configured
+APP_HOME=$(dirname $0)
+source $APP_HOME/helper.sh $1
+SELF=Rambola:$(/usr/bin/basename $0)
# Startup
create_ramdisk
lock_ramdisk
restore_contents_from_snapshot
-# Renice ourself to a low priority
-log "Lowering priority from $OUR_PID to 19."
-/usr/bin/renice 19 ${OUR_PID}
+if [ "$TIMELY_BACKUP" == "yes" ]; then
+ log "Spawning timely.sh for extra safety"
+ $APP_HOME/timely.sh $1 &
+fi
-# Main loop
-while [ 1 ]; do
- sleep ${SLEEP_DELAY}
-
- # Store to snapshot every hour for extra safety (power failure, etc.)
- #store_periodically
-done
+log "Rambola LoginHook finished."
View
0  src/rambolactl.sh
No changes.
View
21 src/timely.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+# Rambola timely backup, syncs cache snapshots on time
+
+APP_HOME=$(dirname $0)
+source $APP_HOME/helper.sh $1
+SELF=Rambola:$(basename $0)
+
+OUR_PID=$(ps -ef | grep ${SELF} | grep -v 'grep' | awk -v uid="$USER_ID" '$1==uid {print $2; exit;}') # Only first occurence from the current user.
+USER_ID=$(id | sed 's/uid=\([0-9]*\).*/\1/')
+
+# Renice ourself to a low priority
+log "Lowering priority from $OUR_PID to 19."
+/usr/bin/renice 19 ${OUR_PID}
+
+# Main loop
+while [ 1 ]; do
+ sleep ${SLEEP_DELAY}
+
+ # Store to snapshot every hour for extra safety (power failure, etc.)
+ store_periodically
+done
Please sign in to comment.
Something went wrong with that request. Please try again.