User:Apple/projects/Transplant

a.k.a. I like my Linux how I like my women... easy to set upflexible.

This is a script to backup and/or transfer a working Funtoo installation onto a fresh install (on the same or a different host).

It won't speed up an install and it doesn't make it easier, but with it you can do a single reboot and have a complete working system without tedious config file editing.

The Script

Code: /usr/local/bin/transplant

#!/bin/bash # I use heavy amounts of bashisms # ...see if you can find them all! # Copyright 2010 Daniel Cordero # Licensed under the GPLv2 test "$PWD" = "$HOME" && cd /tmp # I don't clean up after myself # When I say "list", I mean space-separated (ahem... $IFS) list. NETIF_LIST="" # List of interface initscripts SERVICES="" # List of services to be placed into default runlevel HOST_FILES="" # List of host-specific /etc files ETC_FILES="" # List of generic/shared /etc files HOME_FILES="" # List of files in $HOME HOME_FOLDERS="" # List of folders in $HOME mkdir -p etc/{portage/{package.use,savedconfig,profile},runlevels/default} mkdir -p etc/init.d mkdir -p home/$USER mkdir -p usr/lib/X11/xdm mkdir -p var/lib/portage mkdir -p host rsync -ar --exclude .keep {/usr/,}local/ rsync -r /etc/portage/{package.use,savedconfig,profile} etc/portage for service in $SERVICES; do ln -sf /etc/init.d/$service etc/runlevels/default/$service done for netif in $NETIF_LIST; do ln -sf /etc/init.d/netif.tmpl etc/init.d/netif.$netif done for home_folder in $HOME_FOLDERS; do rsync -ra $HOME/$home_folder/ home/$USER/$home_folder done for home_file in $HOME_FILES; do cp -a $HOME/$home_file home/$USER/$home_file test x"$home_file" = "x.xinitrc" && ln -sf .xinitrc home/$USER/.xsession done for etc_file in $ETC_FILES; do (test "x$(dirname $etc_file)" != "x." && \ test ! -d "$(dirname $etc_file)") && \ mkdir -p etc/$(dirname $etc_file) cp -a /etc/$etc_file etc/$(dirname $etc_file)/$(basename $etc_file) done for host_file in ${HOST_FILES}; do (test "x$(dirname $host_file)" != "x." && \ test ! -d "$(dirname $host_file)") && \ mkdir -p host/$(dirname $host_file) cp -a /etc/$host_file host/$(dirname $host_file)/$(basename $host_file) done cp -a {/,}usr/lib/X11/xdm/Xsetup_0 cp -a {/,}var/lib/portage/world tar cf $(hostname)-overlay.tar host/ tar cf usrlocal-overlay.tar local/ tar cf home-overlay.tar home/ tar cf funtoo-overlay.tar etc/ usr/ var/ \ home-overlay.tar usrlocal-overlay.tar $(hostname)-overlay.tar # DESTRUCTIVE xz funtoo-overlay.tar # non-destructive

Usage

Fill in the 6 variables at the top of the script. You'll constantly be adding more files as the original system gets more customised.

When you're ready (or as a cron job), run the script and save the resulting tarball somewhere.

Boot your install environment. Partition, format and unpack (or work up to) a stage3. Grab a portage tree.

Unpack the main tarball (you probably don't want to unpack the other tarballs yet):

# tar xvJf --exclude "*.tar" funtoo-overlay.tar.xz -C /mnt/gentoo


Take a peek at the list of files in $HOST_FILES and edit them to the host's specification.

Template:Info

Template:Info

Chroot in and run (I suggest in a screen, nohup or another VT):

# env-update; source /etc/profile # emerge -uDN world


Wait (or finish configuration). Remember to make a kernel and # boot-update (and installing the bootloader to MBR if necessary).

Add an identical user (it's not in the script, but you might want to save the output of $ groups) and unpack home-overlay.tar. If you have anything in usrlocal-overlay.tar you can unpack that too.

Template:Info

If all goes well, reboot (and remove the install environment)!