menu TechnoSparks
keyboard_arrow_up

17
Sep

2018

Simple Manjaro Package List Backup and Restore

Easier for future re-installation
Back to blog

I have composed a pretty simple script that would assist you on installing packages automatically for you when you need it.

There are 2 scripts, one is to save all the packages names into a file, and the other is used to install those packages after reading from the file.

AUR Compatibility

This script will of course back up the AUR packages names and also restore them when ran. The script however will attempt to install an AUR helper yay first in order to fully automatically install AUR packages with minimal user interaction.

Some might think: we already have pamac-cli, why must use an AUR helper? The answer is because pamac-cli asks every single time if you want to install a package, and this is rather annoying. AUR helpers do not do this, and I have chosen yay for my needs.

If you wish to use pamac-cli, simply loop each line from the zpkglist.txt file and pass to (where var is the variable containing the line):

pamac build ${var}

Use on Arch

As Manjaro is an Arch derivative, this script can also be used with Arch. However, you will need to figure out on how to install yay from the AUR for your Arch installation. If you are a strictly-repository-person, you may change yay to pacman in Restore.sh. Don't forget to also remove the relevant line in the Backup.sh snippet below.

Code

Restore.sh

#!/bin/bash
unset PROMPT_COMMAND
b=$(tput bold)
n=$(tput sgr0)
function divider {
    echo "--------------------------------------------------------------------------------"
}
title="Restore (Install) Packages"
echo -ne "\033]0;${title}\007"
echo "================================================================================"
echo " ${b}${title}${n}"
echo "================================================================================"
echo "Making sure all currently installed packages are updated"
echo
if hash yay; then
    yay
else
    pacman -Syu
    echo "Installing yay AUR helper"
    pamac build yay-bin
fi
divider
echo "Removing packages not present in backup"
echo
yay -Rsun --noconfirm $(comm -23 <(yay -Qq | sort) <(sort zpkglist.txt))
divider
echo "Restoring"
echo
yay -S --needed --noconfirm - < zpkglist.txt
divider
echo "Clearing cache"
echo
yay -Scc
divider
echo "Restoration completed!"
zenity --info --ellipsize --title="${title}" --text="Restoration completed!"
read

Backup.sh

#!/bin/bash

echo "Storing list of repo packages to pkglist.txt"
pacman -Qqen > zpkglist.txt || { echo "Error occured here. ENTER to continue" && read; }
echo "Storing list of AUR packages to pkglist.txt"
pacman -Qqem >> zpkglist.txt || { echo "Error occured here. ENTER to continue" && read; }

Published on:

Get notified of new posts

Comments