#!/bin/bash # # arch2parabola - converts an Arch GNU/Linux system to Parabola GNU/Linux-libre # # Copyright © 2010 Joshua Ismael Haase Hernández # Copyright © 2011 Joseph Graham # ^^^ Lies, it's a TaylanUB rewrite ! # Copyright © 2011 Taylan Ulrich Bayırlı # # ---------- GNU General Public License 3 ---------- # # This file is part of Parabola. # # Parabola is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Parabola is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Parabola. If not, see . # blacklist='http://repo.parabolagnulinux.org/docs/blacklist.txt' mirrorlist='http://repo.parabolagnulinux.org/files/mirrorlist' kernel_pkgnames=('kernel26' 'kernel26-lts') logfile="$(pwd)/arch2parabola-$$.log" Usage () { echo >&2 'arch2parabola [-c|--check-nonfree]' } Log () { printf '%s\n' "$@" printf '%s\n' "$@" >> "$logfile" } # Sets $section Section () { section=$1 Log '' "--- $section ---" } Abort () { Log >&2 "$@" Log >&2 "Aborted in section: $section" echo >&2 "Log saved to: $logfile" exit 1 } # Sets $ans Ask () { unset ans while true do printf '%s' "$1" >&2 read -r ans; ans=${ans,} [[ $ans == [yn] ]] && break echo '("y" for yes, "n" for no)' >&2 done } CheckAns () { case $ans in y) ;; n) Abort 'Cancelled by user.' ;; *) echo >&2 'What the fuck?' esac } Download () { wget -nv -O- 2>> "$logfile" } # Sets $nonfree_pkgs and $replacements CheckNonfree () while IFS=: read -r pkg repl _ do if pacman -Q "$pkg" > /dev/null 2>&1 then nonfree_pkgs+=("$pkg") replacements+=("$repl") echo "$pkg, replacement: ${repl:-NONE!}" fi done <<< $(Download "$blacklist" | sort || Abort 'Download failed.') case $# in 0) ;; 1) case $1 in -c|--check-nonfree) CheckNonfree; exit ;; *) Usage; exit 1 esac ;; *) Usage; exit 1 esac Section 'Sanity check' if ! [[ -w / ]] then echo >&2 'This script must be run as root.' exit 1 fi for name in ${kernel_pkgnames[@]} do if pacman -Q "${name}" > /dev/null 2>&1 then what_is_the_kernel="${name}" break fi done if (( ! what_is_the_kernel )) then echo >&2 'The system is running a custom kernel.' echo >&2 'Please uninstall it before re-running this script.' echo >&2 echo >&2 'You can find a PKGBUILD for a linux-libre kernel at' echo >&2 echo >&2 'http://repo.parabolagnulinux.org/pkgbuilds/' exit 1 fi if [[ -e $logfile ]] then Abort "The file '$logfile' already exists, not overwriting." else > "$logfile" || Abort "Can't touch '$logfile'!" echo "Logging to: $logfile" fi Section 'Non-free packages revision' echo '* Downloading blacklist and searching for proprietary software on the system.' CheckNonfree | tee -a "$logfile" Section 'Pacman mirrorlist replacement' echo '* Pacman will be synced. (pacman -S pacman)' echo '* /etc/pacman.d/mirrorlist will be replaced by the Parabola mirrorlist.' echo '* Package databases will be forced to sync, to make the mirrorlist take effect. (pacman -Syy)' echo Ask 'Do you wish to continue? [y/n] ' CheckAns pacman -S --noconfirm pacman 2>&1 | tee -a "$logfile" || Abort 'Syncing pacman failed.' Ask 'Shall the mirrorlist be run through rankmirrors? [y/n] ' case $ans in y) Download "$mirrorlist" | rankmirrors - > /etc/pacman.d/mirrorlist ;; n) Download "$mirrorlist" > /etc/pacman.d/mirrorlist ;; *) echo 'What the fuck?' esac pacman -Syy --noconfirm 2>&1 | tee -a "$logfile" || Abort 'Syncing databases failed.' Section 'Package replacement and removal' echo '* Replacements will be installed when possible.' echo '* Non-free packages will be removed.' echo ' Packages rendered useless by this will be removed.' echo ' (pacman -Rnsc ...) (Will let pacman prompt you once more!)' echo '* Pacman cache will be cleared to purge the old non-free packages. (pacman -Sc)' echo Ask 'Do you wish to continue? [y/n] ' CheckAns i=0 while pkg=${nonfree_pkgs[$i]}; repl=${replacements[$i]}; (( ++i < ${#nonfree_pkgs[@]} )) do if [[ $repl ]] then if ! pacman -Q "$repl" > /dev/null 2>&1 && pacman -Si "$repl" > /dev/null 2>&1 then pacman -S --noconfirm "$pkg" 2>&1 | tee -a "$logfile" || Abort "Installation of '$repl' failed." else Log "The replacement '$repl' for '$pkg' was not found in the repos." fi else Log "There is no known replacement for '$pkg'." fi # The replacement might have caused removal already if pacman -Q "$pkg" > /dev/null 2>&1 then pacman -Rnsc "$pkg" 2>&1 | tee -a "$logfile" || Abort "Removal of '$pkg' failed." fi done Section 'You are now on Parabola GNU/Linux-libre !' echo 'Welcome to Freedom.' echo '* You have to manually remove any non-free packages you installed from the AUR.' echo Ask 'Do you wish to keep the log? [y/n] ' case $ans in y) echo "The log is at: $logfile" ;; n) rm -f "$logfile" ;; *) echo >&2 'What the fuck?' esac