All pastes #102146 Raw Edit

MetaPhaze

public text v1 · immutable
#102146 ·published 2006-07-27 11:07 UTC
rendered paste body
# ***************************** This script was written by:
# ***************************** Gabriel Homeier
# ***************************** 7/27/2006
# ***************************** It should be easy enough for a beginner to follow
# ***************************** Have fun with Gentoo ;-)
#!/bin/bash
clear
echo "//----------------------------------------------------------------\\\\"
echo "||----------------------------------------------------------------||"
echo "||     This script will make a backup of all of the packages      ||"
echo "||     you have compiled and installed making re-installation     ||"
echo "||     with this script a breeze.                                 ||"
echo "||                                                                ||"
echo "||     ***  If you choose option #1 you must be root!!!  ***      ||"
echo "||                                                                ||"
echo "||     *** If you choose option #2, you MUST run this    ***      ||"
echo "||     *** script from /mnt/gentoo and have your portage ***      ||"
echo "||     *** snapshot and stage 3 tarball in /mnt/gentoo   ***      ||"
echo "||     *** along with your backup packages.              ***      ||"
echo "||                                                                ||"
echo "||     Please choose from the following options:                  ||"
echo "||                                                                ||"
echo "||     1. Backup                                                  ||"
echo "||     2. Restore From Backup                                     ||"
echo "||                                                                ||"
echo "||________________________________________________________________||"
echo "\\\\________________________________________________________________//"
read Option 
case "$Option" in
"1" )
	cd /usr/portage/packages/All
	if [ $PWD == "/usr/portage/packages/All" ] 
		then
			# Remove Packages Because Some May Be Old
			echo "Removing Previous Packages"
			rm *
		else
			echo "failed to cwd /usr/portage/packages/All"
			exit 0
	fi

	echo "Gathering Information On Installed Programs"
	cd /var/db/pkg

	if [ $PWD == "/var/db/pkg" ] 
		then
			# Make Packages Of All Installed Applications
			array=(*)
			for directory in "${array[@]}"
			do
				{
				echo "changing to ${directory}"
				cd "$directory"
				quickpkg $(ls)
				cd ..
				}
			done
		else
			echo "failed to cwd /var/db/pkg"
			exit 0
	fi

	cd /usr/portage/packages/All

	if [ $PWD == "/usr/portage/packages/All" ]
		then
			# Make An Archive Of The Packages We've Made
			mkdir packages
			mv * packages
			tar -cvf packages.tar packages
			bzip2 -zf9 packages.tar
			# Label The Archive So We Know What It's For
			mv packages.tar.bz2 $HOSTNAME.packages.tar.bz2
			# Move The Archive To A Place We Will See It, And Move To Safe Storage
			mv $HOSTNAME.packages.tar.bz2 /root
			# Backup Important Settings Or We Will Be Hurtin
			mkdir etc
			cd etc
			cp -a /etc .
			cd ..
			# Make An Archive Of Important Settings To Save Space
			tar -cvf $HOSTNAME.etc.tar etc
			bzip2 -zf9 $HOSTNAME.etc.tar
			# Again We Move It To A Noticeable Place
			mv $HOSTNAME.etc.tar.bz2 /root
			# Backup Our User Settings
			mkdir home
			cd home
			cp -a /home .
			cd ..
			# Archive Them
			tar -cvf $HOSTNAME.home.tar home
			bzip2 -zf9 $HOSTNAME.home.tar
			# Move Them
			mv $HOSTNAME.home.tar.bz2 /root
	fi
;;
# This Starts The Re-Install Section
"2" )
	if [ -e stage3-x86-200?.?.tar.bz2 ] then
		if [ $PWD == "/mnt/gentoo" ] then
			tar -jxvpf stage3-x86-200?.?.tar.bz2
		else
			echo "Please move your stage 3 bz2 file to /mnt/gentoo"
			echo "This script should be there too."
			exit 0
		fi
	else
		echo "stage 3 bz2 file not found in /mnt/gentoo"
		echo "Please move this script and your stage 3 bz2 file"
		echo "and your portage snapshot to /mnt/gentoo and run this again"
		exit 0
	fi
	if [ -e portage-*.tar.bz2 ] then
		if [ $PWD == "/mnt/gentoo" ] then
			tar -jxvf portage-*.tar.bz2 -C /mnt/gentoo/usr
		else
			echo "Please move your portage snapshot to /mnt/gentoo"
			echo "This script should be there too."
			exit 0
		fi
	else
		echo "portage snapshot not found in /mnt/gentoo"
		echo "Please move this script and your stage 3 bz2 file"
		echo "and your portage snapshot to /mnt/gentoo and run this again"
		exit 0
	fi
	echo "Please choose one of the following processors:"
	echo "1. Pentium classic (i586)"
	echo "2. I don't know but it's not a Pentium classic (-mtune=i686)"
	echo "3. it's a Pentium 2 (-mtune=pentium2)"
;;

* )
echo "Error."
echo "You must choose 1 or 2."
echo "Exiting"
;;
exit 0