Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

script for migrating from UW-IMAP to Dovecot [PATCHED]

#!/bin/bash

# A script for migrating from UW-IMAP to Dovecot
#
# By Andrew Ziem
# Copyright (c) 2007 Springs Rescue Mission.  All rights reserved.
#
#
# Moves UW-IMAP mboxes from two locations to ~/mail so that Dovecot
# can easily convert mboxes to Maildirs.  Mailboxes with whitespace
# should be handled properly, and IMAP subscriptions should be preserved.
#
#


# Edit the below variables

#HOME_USERS=/home
HOME_USERS=/home/users

#MAIL_SPOOL=/var/mail
MAIL_SPOOL=/var/spool/mail



# to this function pass the user name
function move_mailboxlist
{
	if [ ! -d "$HOME_USERS/$1" ];
	then
		echo "Error: $HOME_USERS/$1 does not exist"
		return 0
	fi

	# make ~/mail
	cd "$HOME_USERS/$1"
	mkdir mail
	chown "$1" mail

	# find each mbox and move it to ~/mail
	if [ ! -f ".mailboxlist" ];
	then
		echo "Warning: .mailboxlist does not exist for $1"
		return 0
	fi
	
	# cat .mailboxlist | while read line; do mv "${line}" ./mail/; done
	cat .mailboxlist | tr '\n' '\0' | xargs -0 mv -t ./mail/

	# preserve subscriptions (to prevent manual resubscriptions)
	mkdir Maildir
	chown "$1" Maildir
	cp -a .mailboxlist Maildir/subscriptions
}

# move inbox from $MAIL_SPOOL to ~/mail/inbox
function move_inbox
{
	if [ ! -f "${MAIL_SPOOL}/$1" ];
	then
		echo "Error: ${MAIL_SPOOL}/$1 does not exist"
		return 0
	fi
	cp "${MAIL_SPOOL}/$1" "${HOME_USERS}/$1/mail/inbox"
	chown "$1" "${HOME_USERS}/$1/mail/inbox"
}

if [ $# -eq 0 ];
then
	echo "First, did you edit the directory names in the script?"
	echo "Then, if you want to do a dry run, prefix mv and cp with echo."
	echo "Then, invoke $0 by passing one or more user names."
	exit
fi

for user in $@
do
	echo "*** Processing user $user"
	move_mailboxlist $user
	move_inbox $user
done

acts_as_taggable_on_steroids migration

Run this when installing this plugin.

class AddTaggable < ActiveRecord::Migration
  def self.up
    create_table :tags, :force => true do |t|
      t.column :name, :string
    end

    create_table :taggings, :force => true do |t|
      t.column :tag_id, :integer
      t.column :taggable_id, :integer
      t.column :taggable_type, :string
      t.column :created_at, :datetime
    end

  end

  def self.down
    drop_table "tags"
    drop_table "taggings"
  end
end

zfs migration script

First rev, works but could use improvement

#!/bin/bash
if [ $# -ne 2 ]
then
    echo "Usage: $0 host_to_send_to zpool_name_on_destination"
    exit
fi
SERVER=$1
ZPOOL=$2
echo
echo "*********************************************************************************"
echo "*                                                                               *"
echo "* Please note, this wrapper only creates migration scripts for filesystems with *"
echo "* existing snapshots. If you want to migrate a snapshot-less filesystem, just   *"
echo "* run 'zfs snapshot zpool/filesystem@migrate' to create a snapshot which will   *"
echo "* allow this script to transfer it to the destination zpool.                    *"
echo "*                                                                               *"
echo "*********************************************************************************"
echo
if [ -f ./tmp/${SERVER}.screens ]
then
echo
echo "******************************************************************************"
echo "*"
echo "* Sorry, tmp/${SERVER}.screens exists, please run 'rm tmp/*' and try again..."
echo "*"
echo "******************************************************************************"
echo
exit
else
if [ ! -d tmp ]
then
mkdir tmp
fi
fi
for z in `zfs list | grep @ | awk '{print $1}' `;
do
FSNAME=`echo $z | awk -F@ '{print $1}' | awk -F/ '{print $NF}'`
if [ -f tmp/${FSNAME}.migrate ] 
then
echo "zfs backup -i $PREV $z | ssh root@$SERVER zfs restore $ZPOOL/${FSNAME}" >> tmp/${FSNAME}.migrate
PREV=$z
else
echo "Processing snapshots for ${FSNAME}."
echo "zfs backup $z | ssh root@$SERVER zfs restore $ZPOOL/${FSNAME}" > tmp/${FSNAME}.migrate
echo "screen -m -d bash tmp/${FSNAME}.migrate" >> tmp/${SERVER}.screens
PREV=$z
fi
done
echo
echo "**************************************************************************"
echo "*"
echo "* Ok, all finished - You can either run them individually, or simply type"
echo "*"
echo "* bash tmp/${SERVER}.screens"
echo "*"
echo "* at a prompt to run them concurrently in disconnected screen sessions."
echo "*"
echo "**************************************************************************"
echo