#!/bin/bash # (C) Joshua Ismael Haase Hernández 2010 # Copyright © 2011 Joseph Graham # This script is free software! You can do what you want with it, as long as # you don't convert it into proprietary software and if you redistribute it # either vertabim or modified you must do so under the same licence. # Set this to the URL of the blacklist. blacklist_url="http://repo.parabolagnulinux.org/docs/blacklist.txt" # Set this to the url of the index page which will be parsed to find out the # url of the mirrorlist. repo_index_page="http://repo.parabolagnulinux.org/core/os/any/" # Set this to the package name of Parabola's mirrorlist (excluding the version # number). parabola_mirrorlist_package_name="pacman-mirrorlist-libre" # Set this to the package name of Arch's default kernel (excluding the version # number). arch_default_kernel_package_name="kernel26" # Make a temporary directory. tempdir=$(mktemp -d) # This will be the name of the log file. logname="$(pwd)/arch2parabola$(date +%Y%m%d).log" # These are the dependencies of the script. dependancies=(which date pacman wget seq sed wget test) # ---------- Function Declarations ---------- # Define the abort procedure. function abort { cat << EOF Something failed in ${section}. A debug log has been saved to ${logname}. Please fix the error and re-run the script to finnish converting your system to Parabola Gnu/Linux. EOF rm -rf ${tempdir} exit 1 } # Ask yes or no (y/n), if given, stop, otherwise keep asking. # uses variable "q" function askyn { case "$1" in y | n ) ;; *) echo Answer "y" or "n" read q askyn ${q} ;; esac } # This function logs, and echos the section. function log_section { cat >> ${logname} << EOF ${section} EOF echo echo ${section} } # This function checks if the `askyn' function was cancelled, and if so, logs # it and aborts. function if_cancelled { if [[ ${q} == "n" ]] then echo "The user canceled the procedure" >> ${logname} abort else unset q fi } # This is an SGML parser function. It reads tags in the same way that `read' # reads lines. The element is assigned to var `element' and the content is # assigned to var `content'. function rdom { local IFS=\> read -d \< element content } section=" ---------- Sanity Check ----------" declare issues=0 # If the user is not root then error and exit. (( EUID )) && { echo "This script should be run as root user." ; exit 1 ; } # Check if the dependencies are available. This won't be needed if this # script is packaged. for dep in ${dependancies[@]} do if ! which ${dep} > /dev/null 2> /dev/null then issues="1" "${dep} is missing, please install it." >> ${logname} fi done # Check if the system is running a custom kernel. if ! pacman -Q ${arch_default_kernel_package_name} >/dev/null 2>/dev/null then issues="1" cat >> ${logname} << EOF The system is running a custom kernel. Please uninstall it before running this script. You can find a PKGBUILD for a linux-libre kernel at http://repo.parabolagnulinux.org/pkgbuilds/ EOF fi # If anything went wrong then abort. (( issues )) && abort unset issues section="---------- Non free packages revision ----------" log_section cd ${tempdir} echo "Downloading the blacklist of proprietary software packages." if ! wget ${blacklist_url} >> ${logname} \ 2>> ${logname} then echo "Download failed, exiting" >> ${logname} abort fi declare -a exists echo "Searching for proprietary software on the system." echo exists[0]="These proprietary software packages have been found on the system:" for package in $(cut -d: -f1 blacklist.txt) do # Check if the package is in pacman's database. if pacman -Q ${package} >/dev/null 2>/dev/null then # Add this package to the array of blacklited packages that have been # found in the system. exists[${#exists[@]}]=${package} # Echo and log the package. echo ${package} | tee -a ${logname} fi done unset exists[0] section="---------- Pacman mirrorlist replacement ----------" log_section cat << EOF * Pacman will be synced to avoid any errors. * Pacman mirror list will be replaced for parabola mirror list. Do you wish to continue? [y/n] EOF askyn if_cancelled # Update pacman. if ! pacman -S --noconfirm pacman then echo "Syncing pacman failed." >> ${logname} abort fi # This piece of code automatically detects the url of the mirrorlist and puts # it in the var `mirror'. while rdom do if [[ ${element%%[[:space:]]*} == "a" ]] then mirror="$(echo ${element##*[[:space:]]} | cut -d\" -f 2 | grep \ "${parabola_mirrorlist_package_name}-")" fi done <<< "$(curl "${repo_index_page}")" # Install the mirrorlist. if ! pacman -U --noconfirm ${mirror} >> ${logname} 2>> ${logname} then cat >> ${logname} << EOF Installing the libre mirror list failed. Maybe there's a new mirrorlist and we need to update the script. If that's the case send a mail to dev@list.parabolagnulinux.org Otherwise, try again. EOF abort fi # Rename `mirrorlist.pacnew' to `mirrorlist'. mv /etc/pacman.d/mirrorlist.pacnew /etc/pacman.d/mirrorlist section="---------- Package Replacement ----------" log_section cat << EOF * Pacman cache will be erased * Pacman database will be updated for parabola * Non free packages that have free replacement will be Synced Do you wish to continue? [y/n] EOF askyn if_cancelled pacman -Scc --noconfirm >> ${logname} 2>> ${logname} || abort pacman -Syy --noconfirm >> ${logname} 2>> ${logname} || abort declare replacement # We search the blacklist to find packages that have libre replacements and # install them. for package in ${exists[@]} do if [[ ${package} ]] then replacement=$(grep -e ${package}[:space:] blacklist.txt | cut -d: f2) if [[ ${replacement} ]] then pacman -S --noconfirm ${replacement} >> ${logname} 2>> ${logname} || abort fi fi done unset replacement section="---------- Non-free packages removal ----------" log_section cat <> ${logname} 2>> ${logname} || abort done rm -rf ${tempdir} section="---------- You are now on Parabola GNU/Linux ----------" log_section cat << EOF Welcome to Freedom. * You have to manually remove any non-free packages you installed from the AUR. Do you wish to keep the log? [y/n] EOF askyn # Ask the user if they want to keep the log and if not then delete it. if [[ ${q} == "y" ]] then echo "The log has been saved in ${logname}" else rm -f ${logname} fi exit 0