Every time I have a new shell account I end up customizing it. Making alterations to my vimrc, screenrc or whatever. It can be a huge pain when you have lots of slightly varying configs on different machines. I wrote this little script to grab my files and create a self extracting shell script so I can easily setup my environment on multiple machines.
The usage is pretty straightforward. Define your remote path, and the filename along with your user that has scp access. Then define the files you want to include. To create the archive just run the moveout script. Once the self extracting script is uploaded you can just download it and execute it.
Example Restore:
wget example.com/movein && bash movein
moveout script
#!/bin/bash
# Nick Anderson
# This script eases “moving” into a new account.
# You define files that are staple configs like your vimrc,
# .bashrc, .screenrc etc … The files are added to a self
# extracting shell script and uploaded via scp to a remote
# server. Once the self extracting shell script is available
# you can wget it and execute it.
TMPDIR=$(mktemp -d -t moveout.XXXX)
PAYLOADDIR=$TMPDIR/payload
BUILDER=$TMPDIR/build
DECOMPRESSOR=$TMPDIR/decompress
# Create directories
mkdir $TMPDIR/payload
function addFile() {
cp -R $1 $PAYLOADDIR
}
#################################################
# Remote path (uses scp)
#################################################
export REMOTEPATHSPEC=”example.com:public_html/”
export REMOTEFILE=”movein”
export REMOTESSHUSER=”remoteuser”
#################################################
# Include these files in movin #
#################################################
addFile ~/.vim
addFile ~/.bashrc
addFile ~/.bash_logout
addFile ~/.screenrc
addFile ~/.profile
#################################################
cd $TMPDIR
# Generate selfextraction builder
cat » $TMPDIR/build «EOF #!/bin/bash cd payload tar cf ../payload.tar . cd .. if [ -e “payload.tar” ]; then gzip payload.tar if [ -e “payload.tar.gz” ]; then cat decompress payload.tar.gz > movein
else
echo “payload.tar.gz does not exist”
exit 1
fi
else
echo “payload.tar does not exist”
exit 1
fi
echo “movein created”
exit 0
EOF
chmod +x $TMPDIR/build
# Generate decompression script
cat » $TMPDIR/decompress «EOF #!/bin/bash cd ~ ARCHIVE=$(awk ‘/^__ARCHIVE__/ { print NR + 1; exit 0; }’ $0) # Pipe tarfile into tar tail -n+$ARCHIVE $0 | tar xzv -C ~ exit 0 __ARCHIVE__ EOF chmod +x $TMPDIR/decompress cd $TMPDIR ./build scp $TMPDIR/movein $REMOTESSHUSER@$REMOTEPATHSPEC/$REMOTEFILE rm -rf $TMPDIR [/bash] Note: Be careful to not expose any sensitive information if your put your self extracting script on a publicly available address.