[HOW TO] Easily reinstall programs when Reinstalling Zorin

Sometimes, bad things happen even to good people. Maybe it was a power outage or some spilled coffee... But whatever it was, you now must wipe and reinstall Zorin OS.
What makes this particularly daunting is all your software you have installed must now be reinstalled.

To make that easier, we will use some scripts. Or as noted below, you can use Y PPA Manager GUI tool.
The first script gathers your PPA's from your system so that you can easily transfer them to the new installation.

Summary

#!/bin/sh

usage () {
cat >&2 <<USAGE
$0 [--ppa-only]

Options:
--ppa-only only list PPAs
USAGE
exit $1
}

list_sources () {
grep -E '^deb\s' /etc/apt/sources.list /etc/apt/sources.list.d/.list |
cut -f2- -d: |
cut -f2 -d' ' |
sed -re 's#http://ppa.launchpad.net/([^/]+)/([^/]+)(.
?)$#ppa:\1/\2#g'
}

list_ppa () {
list_sources | grep '^ppa:'
}

generate=list_sources

while test -n "$1"
do
case "$1" in
-h|--help) usage 1;;
--ppa-only) generate=list_ppa;;
*)
printf -- "Unknown argument '$1'\n" >&2
usage 2
;;
esac
shift
done

$generate

Copy that to a text file and name it whatever you want. ppa-list.sh works.
The next script is to run add-apt-repository on that list to get those repositories added in to your sources. You can save this as ppa-reinstall.sh and will run this on the New Installation. (You may need to mark the scripts to run as executable).

Summary

#!/bin/sh

if test -n "$1"
then
cat >&2 <<USAGE
Usage: $0 < PATH_TO_LIST_OF_REPOS
list-apt-repositories [--ppa-only] | $0

No options recognized.

Reads list of repositories from stdin and generates a script to install them
using `add-apt-repository(1)`. The script is printed to stdout.

The generated script supports an optional
`-y` or `--yes` argument which causes the `add-apt-repository` commands
to be run with the `--yes` flag.
USAGE
exit 1
fi

cat <<INSTALL_SCRIPT
#!/bin/sh
y=
case "$1" in
-y|--yes) y=$1;;
'') y=;;
*)
printf '%s\n' "Unknown option '$1'" "Usage: $0 [{-y|--yes}]" >&2
exit 1
;;
esac
INSTALL_SCRIPT

xargs -d'\n' printf "add-apt-repository $y '%s'\n"

Run sudo apt update to ensure all repos are good and in their place.

Alternatively, you can use Y PPA Manager to make back ups and restore PPAs from back up. sudo add-apt-repository ppa:webupd8team/y-ppa-manager sudo apt update sudo apt install y-ppa-manager. Click the Advanced button, then the Backup repositories button. Move the saved file to new installation and (You'd have to install y ppa manager over there... lol) and you can use the Restore repositories backup button.

Now that your repos are in place, you need a list of all installed software. Chances are, you only want the Manually installed software. While this list will include auto-installed stuff, it should mostly suffice:

apt-mark showmanual

You can use this command to produce a package-list file in your home folder that lists all packages installed on your computer

sudo dpkg -l | awk '/^ii/ { print $2 }' >package-list

Move that package-list to the new installation (On a new computer- through USB on the same computer; whatever it is you need).
Then run the following command in terminal opened in the same directory that contains the package-list file on hte new installation:

sudo xargs apt-get install -y < package-list

Save those scripts and the package-list on a USB or cloud drive. This is also handy for creating backups of your PPA's and installed software as a reference even if a full reinstallation is not needed. You can reference the script that lists the PPAs in order to replace one you lost.

Source:

5 Likes