From c3d3117db18005b667fc000b67b25589294736aa Mon Sep 17 00:00:00 2001 From: Taylan Ulrich B Date: Mon, 11 Apr 2011 21:06:20 +0200 Subject: TaylanUB rewrite --- TODO | 3 + arch2parabola | 436 +++++++++++++++++++++++---------------------------------- check-non-free | 89 ------------ 3 files changed, 176 insertions(+), 352 deletions(-) delete mode 100755 check-non-free diff --git a/TODO b/TODO index 27766e0..62adeaf 100644 --- a/TODO +++ b/TODO @@ -7,10 +7,13 @@ arch2parabola: the user needs to see (such as pacman's output when it installs libre replacements). These things should be output to the terminal, as well as written in the log. Use `tee' to do this. + -- DONE #Low priority: ∙Make a brief explanation of everything it does in the comments at the top of the code. + -- Do we need it after the clean rewrite ? ∙After installing the libre mirrorlist, it should ask they user if `rankmirrors' should be run on the mirrorlist. + -- DONE diff --git a/arch2parabola b/arch2parabola index 87622ff..9a1951b 100755 --- a/arch2parabola +++ b/arch2parabola @@ -1,308 +1,218 @@ #!/bin/bash -# arch2parabola - converts an Arch Gnu/Linux system to Parabola Gnu/Linux-libre - +# +# 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 . - -# 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 +# +# 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_pkgname='kernel26' + +logfile="$(pwd)/arch2parabola-$$.log" + +Usage () { - 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 + echo >&2 'arch2parabola [-c|--check-nonfree]' } -# Ask yes or no (y/n), if given, stop, otherwise keep asking. -# uses variable "q" -function askyn +Log () { - case "$1" in - y | n ) ;; - *) echo Answer "y" or "n" - read q - askyn ${q} - ;; - esac + printf '%s\n' "$@" + printf '%s\n' "$@" >> "$logfile" } -# This function logs, and echos the section. -function log_section +# Sets $section +Section () { - cat >> ${logname} << EOF + section=$1 + Log '' "--- $section ---" +} -${section} +Abort () +{ + Log >&2 "$@" + Log >&2 "Aborted in section: $section" + echo >&2 "Log saved to: $logfile" + exit 1 +} -EOF - echo - echo ${section} +# 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 } -# This function checks if the `askyn' function was cancelled, and if so, logs -# it and aborts. -function if_cancelled +CheckAns () { - if [[ ${q} == "n" ]] - then - echo "The user canceled the procedure" >> ${logname} - abort - else - unset q - fi + case $ans in + y) ;; + n) Abort 'Cancelled by user.' ;; + *) echo >&2 'What the fuck?' + esac } -# 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 +Download () { - local IFS=\> - read -d \< element content + wget -nv -O- 2>> "$logfile" } -section=" ---------- Sanity Check ----------" +# 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 -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 ; } +Section 'Sanity check' -# 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 + if ! [[ -w / ]] then - issues="1" - "${dep} is missing, please install it." >> ${logname} + echo >&2 'This script must be run as root.' + exit 1 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 + if ! pacman -Q "$kernel_pkgname" > /dev/null 2>&1 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} + 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 -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's cache will be erased -* Pacman's database will be updated for parabola -* Non free packages that have free replacements will be replaced - -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} ]] + if [[ -e $logfile ]] then - replacement=$(grep -e ${package}[:space:] blacklist.txt | cut -d: f2) - if [[ ${replacement} ]] - then - pacman -S --noconfirm ${replacement} >> ${logname} 2>> ${logname} || - abort - fi + Abort "The file '$logfile' already exists, not overwriting." + else + > "$logfile" || Abort "Can't touch '$logfile'!" + echo "Logging to: $logfile" fi -done -unset replacement -section="---------- Non-free packages removal ----------" -log_section -cat <> ${logname} 2>> ${logname} || abort -done +Section 'Pacman mirrorlist replacement' -rm -rf ${tempdir} + 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.' -section="---------- You are now on Parabola GNU/Linux ----------" -log_section -cat << EOF -Welcome to Freedom. + 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 -* You have to manually remove any non-free packages you installed from the AUR. + pacman -Syy --noconfirm 2>&1 | tee -a "$logfile" || Abort 'Syncing databases failed.' -Do you wish to keep the log? [y/n] -EOF -askyn +Section 'Package replacement and removal' -# 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 + 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] ' -exit 0 + case $ans in + y) echo "The log is at: $logfile" ;; + n) rm -f "$logfile" ;; + *) echo >&2 'What the fuck?' + esac diff --git a/check-non-free b/check-non-free deleted file mode 100755 index 7022469..0000000 --- a/check-non-free +++ /dev/null @@ -1,89 +0,0 @@ -#!/bin/bash -# check-nonfree -# Copyright 2010 Joshua Ismael Haase Hernández -# Copyright © 2011 Joseph Graham - -# ---------- 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 . - -# Set this to the URL of the blacklist. -blacklist_url="http://repo.parabolagnulinux.org/docs/blacklist.txt" - -# Make a temproary directory and go to it. -tempdir=$(mktemp -d) -cd ${tempdir} - -#Run a sanity check -which pacman wget >/dev/null 2>/dev/null || -{ - echo "Cannot find pacman or wget, exiting" - exit 1 -} - -# Download the blacklist. -echo "Downloading the blacklist of proprietary software packages." -echo -wget ${blacklist_url} 2>/dev/null || -{ - echo "Download failed, exiting" - exit 1 -} - -declare -a exists - -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} - fi -done - -# Check if no proprietray software was found. -if (( ! ${#exists[@]} )) -then - echo "No proprietary software has been found on your system." - - # Exit. - exit 0 - -# Check if one proprietary software package was found. -elif (( ${#exists[@]} = 1 )) -then - echo "This proprietary package has been found on your system:" - -# Multiple proprietary software packages have been found. -else - echo "These proprietary packages have been found on your system:" -fi - -# Echo a blank line as a seperator. -echo - -# Print all the proprietary software packages that have been found, seperated -# by newlines. -for package in ${exists[@]} -do - echo ${package} -done - -rm -rf $tempdir - -exit 0 -- cgit v1.2.3