From a77cfac44a0a70038c6e591dd9eeb1071adcf5b5 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 23 Feb 2011 14:52:59 +0000 Subject: Commented, refactored and bugfixed the code. `arch2parabola' does not work yet. --- arch2parabola | 264 ++++++++++++++++++++++++++++++++------------------------- check-non-free | 68 +++++++++++---- 2 files changed, 202 insertions(+), 130 deletions(-) diff --git a/arch2parabola b/arch2parabola index 503a7a2..e2e9118 100755 --- a/arch2parabola +++ b/arch2parabola @@ -1,91 +1,103 @@ #!/bin/bash # (C) Joshua Ismael Haase Hernández 2010 -# 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. +# 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" + +# Make a temporary directory. tempdir=$(mktemp -d) -logdir=$(pwd) -logname=$(echo $logdir/arch2parabola$(date +%Y%m%d).log) -mirrorfile=$() -dependancies=(which date pacman wget seq sed wget test) # "seq" y "test" are in coreutils package - # "sudo" might be optdepend or not be - # used at all and require to use as root - # as I did. + +# This will be the name of the log file. +logname="$(pwd)/arch2parabola$(date +%Y%m%d).log" + +mirror="" + +# These are the dependencies of the script. +dependancies=(which date pacman wget seq sed wget test) + # ---------- Function Declarations ---------- # Define the abort procedure. -abort () { - cat <>$logname <> ${logname} << EOF -$section +${section} EOF - echo "" - echo $section + echo + echo ${section} } -log_cancel () { - if [ $q == "n" ]; then { - echo "The user canceled the procedure" >> $logname +# 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 { - q="" - } + else + unset q fi } - section=" ---------- Sanity Check ----------" -if [ $EUID != 0 ]; then { - cat </dev/null 2>/dev/null || { - issues="yes" - "$x is missing, please install." >> $logname - } +# 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. -pacman -Q kernel26 >/dev/null 2>/dev/null || { - issues="yes" - cat >>$logname </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. @@ -94,71 +106,87 @@ You can find a PKGBUILD for a linux-libre kernel at http://repo.parabolagnulinux.org/pkgbuilds/ EOF -} - -if [ $issues == "yes"]; then { -abort - } fi +# If anything went wrong then abort. +(( issues )) && abort + +unset issues + section="---------- Non free packages revision ----------" log_section -cd $tempdir +cd ${tempdir} echo "Downloading the blacklist of proprietary software packages." -wget http://www.parabolagnulinux.org/docs/blacklist.txt >>$logname 2>> $logname || { - echo "Download failed, exiting" >> $logname + +if ! wget ${blacklist_url} >> ${logname} \ + 2>> ${logname} +then + echo "Download failed, exiting" >> ${logname} abort -} -a=($(cut -d: -f1 blacklist.txt)) +fi -echo "Searching for proprietary software on the system." -echo "" -b[0]="These proprietary software packages have been found on the system:" +declare -a exists -for i in ${a[@]} ; do - pacman -Q $i >/dev/null 2>/dev/null && b[${#b[@]}]=$i +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 -for i in $(seq 0 ${#b[@]}) ; do - echo ${b[$i]} - echo ${b[$i]} >> $logname -done -unset b[0] +unset exists[0] + section="---------- Pacman mirrorlist replacement ----------" log_section -cat <> $logname <> ${logname} abort -} -pacman -U --noconfirm $mirror >>$logname 2>> $logname || { - cat >> $logname <> ${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 section="---------- Package Replacement ----------" log_section -cat <>$logname 2>> $logname || abort -pacman -Syy --noconfirm >>$logname 2>> $logname || abort - -# # Manual way, it should be replaced by a field on blacklist.txt -# # Here we declare packages that have a free replacement. -# replacements=() -# for x in ${replacements[@]}; do -# pacman -S --noconfirm $ -# done - -# ----- blacklist.txt way -----. It should be this way, this way -# linux-libre, etc, should be updated automaticaly - -for x in ${b[@]}; do - if [$x]; then - a=$(grep -e $x[:space:] blacklist.txt | cut -d: f2) - if [$a]; then - pacman -S --noconfirm $a >>$logname 2>>$logname || abort +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 +# Remove the packages that don't have free replacements. +for package in ${exists[@]} +do + pacman -Rc --noconfirm ${package} >> ${logname} 2>> ${logname} || abort done -rm -rf $tempdir +rm -rf ${tempdir} section="---------- You are now on Parabola GNU/Linux ----------" log_section -cat <. - - +# Set this to the URL of the blacklist. +blacklist_url="http://repo.parabolagnulinux.org/docs/blacklist.txt" -dir=$(pwd) +# Make a temproary directory and go to it. tempdir=$(mktemp -d) -cd $tempdir +cd ${tempdir} #Run a sanity check -which pacman wget >/dev/null 2>/dev/null || { - echo "Cannot find pacman or wget, exiting"; +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 http://www.parabolagnulinux.org/docs/blacklist.txt 2>/dev/null || { +echo +wget ${blacklist_url} 2>/dev/null || +{ echo "Download failed, exiting" exit 1 } -a=($(cut -d: -f1 blacklist.txt)) +declare -a exists -for i in ${a[@]} ; do - pacman -Q $i >/dev/null 2>/dev/null && b[${#b[@]}]=$i +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 -echo "This proprietary software found on your system:" -echo "" -for i in $(seq 0 ${#b[@]}) ; do - echo ${b[$i]} + +# 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