EDIT: 06/18/14, it is simple for me to syncronise my code with our Ultimate Edition Copy account. The latest apps will always be there.
EDIT: 04/15/15:Wow, how times fly, at version 1.0.8 and has been there for a long minute. I feel prefection has been met with this tool. I have since created our own keyserver with over 3 million keys & is faster then any of the other keyservers A SSD cloud is hard to beat down.
EDIT: 09/25/15, I stand corrected, found another error it does not address and that is duplicate sources. Found this issue by accident trying to install a beta of Google Chrome. Already had it in my sources and added it anyway and here comes the errors. KeySnatcher 1.0.9 will now detect and fix this error as well.
Changelog first:
# ==============================================================================
# Change-log:
# 1.0: First public release
# 1.0.1: Added bc to dependancy list
# Removed locale was causing minor issues
# 1.0.2: Added fix routine for missing repositories
# Added Server Timeout function for IPV6
# Many bug fixes in permission rights.
# 1.0.3: Wrote help system. Not a fantastic job, but I hope it
# gets the point across.
# 1.0.4: Adjusted servers, added version dumping header.
# Now checks permissions prior to engaging software.
# Added eyecandy routines & a new one Encapsulate.
# Adjusted Help system and commands.
# 1.0.5 Added fixing of 403 Forbidden errors.
# Repaired bash_autocompletion to coincide with options
# 1.0.6 Added ability to skip connectivity tests.
# Adjusted eyecandy routines.
# Wrote a manual in man format, pdf and postscript.
# 1.0.7 Added repair of "Failure to fetch" (Architecture)
# related issues.
# 1.0.8 Added ueserver.space to the keyserver mix (3+ million keys)
# Corrected indexing of servers.
# 1.0.9 Added repair of duplicate sources.
# ==============================================================================
Lets snap open the help system:
theemahn@JackHammer:~/Downloads$ keysnatcher --help
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ KeySnatcher 1.0.8, 04/15/2015 ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒ GNU KeySnatcher home page: <http://ultimateedition.info/>. ▒
▒ E-mail bug reports to: <[email protected]>. ▒
▒ Be sure to include the word KeySnatcher somewhere in the Subject: field. ▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒ Usage: KeySnatcher -<-COMMAND> ▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
Mandatory arguments to long options are identical for short options.
possible commands...
-f --fixerrors fix 403 / 404 errors with repositories
-s --snatch snatch missing keys
-h --help this help message
-r --rescan rescan servers to determine which is fastest
-t --timeout fix IPV6 timeout issues
-v --version dump version info
KeySnatcher --help [COMMAND] for further information.
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
theemahn@JackHammer:~/Downloads$
It is sitting ony your build servers by the way. I guess somewhat cryptic to a *nix noobie. I try to not re-invent the wheel, and by the same token re-explain info that can be obtained elsewhere. First what is a GPG key? Enough on with the code:
- Code: Select all
#!/bin/bash
# ==============================================================================
# title :KeySnatcher
# description :Grabs missing GPG keys & fixes missing repositories
# author :theemahn <[email protected]>
# date :04/15/2015
# version :1.0.8
# usage :KeySnatcher --help
# manual :man KeySnatcher
# notes :See change-log below for further information.
# ==============================================================================
# Change-log:
# 1.0: First public release
# 1.0.1: Added bc to dependancy list
# Removed locale was causing minor issues
# 1.0.2: Added fix routine for missing repositories
# Added Server Timeout function for IPV6
# Many bug fixes in permission rights.
# 1.0.3: Wrote help system. Not a fantastic job, but I hope it
# gets the point across.
# 1.0.4: Adjusted servers, added version dumping header.
# Now checks permissions prior to engaging software.
# Added eyecandy routines & a new one Encapsulate.
# Adjusted Help system and commands.
# 1.0.5 Added fixing of 403 Forbidden errors.
# Repaired bash_autocompletion to coincide with options
# 1.0.6 Added ability to skip connectivity tests.
# Adjusted eyecandy routines.
# Wrote a manual in man format, pdf and postscript.
# 1.0.7 Added repair of "Failure to fetch" (Architecture)
# related issues.
# 1.0.8 Added ueserver.space to the keyserver mix (3+ million keys)
# Corrected indexing of servers.
# ==============================================================================
#INTERNAL VARIBLES
PROGNAME="KeySnatcher"
BUILDDATE="04/15/2015"
VERSION="1.0.8"
EXEC=$PWD
WEBSITE="ultimateedition.info"
AUTHOR="TheeMahn"
EMAIL="<"$AUTHOR"@"$WEBSITE">"
# Retrieve number of lines & columns the screen supports.
LINEZ=$(tput lines)
COLUMNZ=$(tput cols)
SPLIT=0
# check to see if notify is installed & if sound is supported.
# a recommended (not required dependancy)
# To add notification support
# sudo apt-get install libnotify-bin notify-osd
# To add sound support
# apt-get install gnome-session-canberra
NOTIFY=$(which notify-send)
SOUND=$(which canberra-gtk-play)
# Declare integer to span eye-candy routine
declare -i RR
RR=0
declare -i TT
TT=0
declare -i CALC
CALC=0
declare -a KEYSERVERS=('ueserver.space' 'keyserver.ubuntu.com' 'pool.sks-keyservers.net' 'subkeys.pgp.net' 'keys.nayr.net' 'keys.gnupg.net');
declare -a PINGTIME=();
#LOCALE=`localectl | grep "System Locale" | cut -d'_' -f2 | cut -d'.' -f1`
#LASTRESORT='wwwkeys.'$LOCALE'.pgp.net' # UNUSED CURRENTLY & will eventually be a last resort.
#Pull info we will use to compare against later
IUSER=${SUDO_USER:-$USER}
IHOME="/home/$IUSER"
# set colors so errors etc. stand out.
txtblk='\e[0;30m' # Black - Regular
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtylw='\e[0;33m' # Yellow
txtblu='\e[0;34m' # Blue
txtpur='\e[0;35m' # Purple
txtcyn='\e[0;36m' # Cyan
txtwht='\e[0;37m' # White
bldblk='\e[1;30m' # Black - Bold
bldred='\e[1;31m' # Red
bldgrn='\e[1;32m' # Green
bldylw='\e[1;33m' # Yellow
bldblu='\e[1;34m' # Blue
bldpur='\e[1;35m' # Purple
bldcyn='\e[1;36m' # Cyan
bldwht='\e[1;37m' # White
unkblk='\e[4;30m' # Black - Underline
undred='\e[4;31m' # Red
undgrn='\e[4;32m' # Green
undylw='\e[4;33m' # Yellow
undblu='\e[4;34m' # Blue
undpur='\e[4;35m' # Purple
undcyn='\e[4;36m' # Cyan
undwht='\e[4;37m' # White
bakblk='\e[40m' # Black - Background
bakred='\e[41m' # Red
badgrn='\e[42m' # Green
bakylw='\e[43m' # Yellow
bakblu='\e[44m' # Blue
bakpur='\e[45m' # Purple
bakcyn='\e[46m' # Cyan
bakwht='\e[47m' # White
txtrst='\e[0m' # Text Reset
# Currently Unused function. I have thought about using this function for the help system.
function Columnize () {
# Columnize is an internally called function exclusively.
# EXAMPLE
# -t to shove through the column titles we will count the number of switches and
# calculate spacing eventually.
if [[ $1 == '-t' ]]; then
#echo -e "${bldgrn}Number of switches passed: $#"
for ARG in "$@"
do
array_counter=$(($array_counter + 1))
if [[ $array_counter -gt 2 ]]; then
#echo "Switch $array_counter: $ARG"
ARGUMENTS[$array_counter]=$ARG
tLen=${#ARGUMENTS[$array_counter]}
if [[ $tLen -ge $WIDEST ]]; then
WIDEST=$tLen
fi
#echo "Length of ${ARGUMENTS[$array_counter]} is $tLen"
fi
#echo "The widest passed varible is $WIDEST"
done
else
#echo -e "${bldgrn}Number of switches passed: $#"
for ARG in "$@"
do
array_counter=$(($array_counter + 1))
if [[ $array_counter -gt 1 ]]; then
#echo "Switch $array_counter: $ARG"
ARGUMENTS[$array_counter]=$ARG
tLen=${#ARGUMENTS[$array_counter]}
if [[ $tLen -ge $WIDEST ]]; then
WIDEST=$tLen
fi
#echo "Length of ${ARGUMENTS[$array_counter]} is $tLen"
fi
#echo "The widest passed varible is $WIDEST"
done
fi
#echo "#: $# VARS: $*"
LONGESTLENGTH=${#2}
#echo "Length of $2 is $LONGESTLENGTH"
#echo $COLUMNZ
MAINS=$(echo "scale=2; $COLUMNZ-30" | bc)
MAINS=${MAINS%.*}
#echo $MAINS
MAINS=$(expr $MAINS - 2)
MAINS=$(expr $MAINS / 4)
#echo $MAINS
if [[ $1 = '-t' ]]; then
#"#" "DEV" "VENDOR" "LABEL" "TYPE" "SIZE"
printf "%-0s %-16s %-7s %-16s %-7s %-3s %-13s %-3s %-16s %-1s\n" "▒" "$2" "$3" "$4" "$5" "$6" "$7" "$8"
else
#MAINS=$(expr $MAINS / 2)
printf "%-0s %-16s %-7s %-16s %-7s %-3s %-13s %-3s %-16s %-1s\n" "▒" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8"
fi
}
function Error () {
echo -en "${bldred}"
#FullBar
Center "$1" "--ERROR"
#echo -en "${bldred}"
#FullBar
echo -en "${txtrst}"
}
# Function for outputting to X-11 screen a notification of completion and playing sound.
# The sound file is from the "Optional" ultimate-edition-sound-theme
function Notification () {
# Is X11 running?
X=$( pidof X )
# Does the user have the optional Ultimate Edition Sound scheme installed?
if [[ -f "/usr/share/sounds/Ultimate Edition Sound Scheme/stereo/itisdone.wav" ]]; then
WAVE=1
fi
# Is the user in an X11 GUI environment and have notification OSD installed?
if [[ $X && $NOTIFY ]]; then
a=$((notify-send "KEYSNATCHER" "$1" -i /usr/share/ultimate_edition/logo.png -t 5000) 2>/dev/null)
fi
# Does the user have pre-requisites? If so, break out the Cylon voice.
if [[ $SOUND && $WAVE ]]; then
a=$(canberra-gtk-play -i itisdone 2>/dev/null)
fi
# Display message in terminal unconditionally
Center "$1"
FullBar
}
# Usage: Eye Candy "Message"
function EyeCandy() {
# Verify a message has been sent to this function otherwise do squat.
# Example: Eye Candy ('Repostorm $REPOVERSION is entering extraction mode.')
# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
# ▒ Repostorm 1.7.7 is entering extraction mode. ▒
# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
STP="$1"
if [[ $STP ]]; then
STRLEN=${#STP}
STRLEN=$(expr $STRLEN + 3)
GREPPED=$(echo $STP | grep -E '\e')
if [[ $GREPPED ]]; then
STRLEN=$(expr $STRLEN - 13)
fi
RR=0; while [ $RR -le $STRLEN ]; do echo -n "▒"; RR=RR+1; done; echo;
echo -e "▒ "$STP" ▒"
RR=0; while [ $RR -le $STRLEN ]; do echo -n "▒"; RR=RR+1; done; echo;
fi
}
function Encapsulate() {
# Verify a message has been sent to this function otherwise do squat.
# Example: Encapsulate ('Repostorm $REPOVERSION is entering extraction mode.')
# ▒ Repostorm 1.7.7 is entering extraction mode. ▒
STP="$1"
if [[ $STP ]]; then
STRLEN=${#STP}
STRLEN=$(expr $STRLEN + 3)
DISTANCE=$(expr $COLUMNZ - $STRLEN)
GREPPED=$(echo $STP | grep -E '\e')
if [[ $GREPPED ]]; then
STRLEN=$(expr $STRLEN - 13)
fi
echo -en "▒ "$STP
RR=0; while [ $RR -lt $DISTANCE ]; do echo -n " "; RR=RR+1; done; echo "▒";
fi
}
# Draws a bar across the screen based on screen size detected (columnz)
function FullBar() {
RR=1; while [ $RR -le $COLUMNZ ]; do echo -n "▒"; RR=RR+1; done; echo;
}
# Center data passed to function on screen
function Center () {
STP=$1
ERROR=$2
if [[ $STP ]]; then
STRLEN=${#STP}
CENTER=$(expr $STRLEN / 2 )
#CENTER=CENTER-1
TCENTER=$(expr $COLUMNZ / 2 )
#TCENTER=TCENTER-1
DISTANCE=$(expr $TCENTER - $CENTER)
DISTANCE=$(expr $DISTANCE - 2)
if ! [[ $ERROR ]]; then
echo -en "${txtrst}"
else
echo -en "${bldred}"
fi
RR=0; while [ $RR -lt $DISTANCE ]; do echo -n "▒"; RR=RR+1; done;
echo -en "${bldgrn} $STP "
if ! [[ $ERROR ]]; then
echo -en "${txtrst}"
else
echo -en "${bldred}"
fi
TT=0; while [ $TT -lt $DISTANCE ]; do echo -n "▒"; TT=TT+1; done;
CALC=$(expr $RR + $TT + $STRLEN + 2)
if [[ $CALC -lt $COLUMNZ ]]; then
while [ $CALC -lt $COLUMNZ ]; do echo -n "▒"; CALC=CALC+1; done; echo;
fi
fi # echo "STRING LEN: $STRLEN CENTER: $CENTER TOTAL CNTER: $TCENTER RR=$RR TT=$TT COLUMNZ: $COLUMNZ CALC: $CALC DISTANCE: $DISTANCE"
echo -en "${txtrst}"
}
function VersionDump {
Center "$PROGNAME $VERSION, $BUILDDATE"
Encapsulate "GNU $PROGNAME home page: <http://$WEBSITE/>."
Encapsulate "E-mail bug reports to: $EMAIL."
Encapsulate "Be sure to include the word $PROGNAME somewhere in the Subject: field."
FullBar
}
function GrabKeys {
#VersionDump
#KEY SERVER AVG PING
#keyserver.ubuntu.com 100
#pool.sks-keyservers.net 47
#subkeys.pgp.net DOWN
#pgp.mit.edu DOWN
#keys.nayr.net 64
#keys.gnupg.net 32
#Setting default keyserver as fastest server: keys.gnupg.net | 32
#Scanning for missing keys.
#Hit http://us.archive.ubuntu.com raring Release.gpg
#...
#Fetched 316 B in 40s (7 B/s)
#Processing key: 2E183FA1E260F5B0
#gpg: requesting key E260F5B0 from hkp server keys.gnupg.net
#gpg: /home/tonie/.gnupg/trustdb.gpg: trustdb created
#gpg: key E260F5B0: public key "Launchpad PPA for Ubuntu Tweak Testing Team" imported
#gpg: Total number processed: 1
#gpg: imported: 1 (RSA: 1)
#In the above example the software has determined keys.gnupg.net is the
#fastest server, this operation is only performed once to accelerate any future
#grabbing of missing keys. The sofware then scans for missing keys and retrieves
# any missing key from that server.
if ! [[ -w /etc/apt/sources.list ]]; then
Error "Insufficent privilages. Please prefix sudo, or perform as super user." "--error"
Encapsulate "sudo keysnatcher --snatch"
FullBar
exit 0;
fi
Encapsulate "Scanning for missing keys."
FullBar
if [[ -f ~/.keysnatcher ]]; then
KEYSERVER=`cat ~/.keysnatcher`
fi
if [[ $IUSER != $USER ]]; then
apt-get update 2> /tmp/keymissing; for key in $(grep "NO_PUBKEY" /tmp/keymissing |sed "s/.*NO_PUBKEY //"); do echo -e "\nProcessing key: $key"; gpg --keyserver $KEYSERVER --recv $key && gpg --export --armor $key | apt-key add -; done
else
sudo apt-get update 2> /tmp/keymissing; for key in $(grep "NO_PUBKEY" /tmp/keymissing |sed "s/.*NO_PUBKEY //"); do echo -e "\nProcessing key: $key"; gpg --keyserver $KEYSERVER --recv $key && gpg --export --armor $key | apt-key add -; done
fi
FullBar
Notification "Missing keys if any successfully snatched."
}
function Connectivity {
VersionDump
GREPIR=$(echo "$*" | grep -i 'skip')
if ! [[ $GREPIR ]]; then
if ! [[ -f ~/.keysnatcher ]]; then
Center "Scanning for fastest host, this only needs to be done once. Please wait..."
FullBar
echo -e "${bldwht}${undwht}"
printf '%-30s %s\n' \
"KEY SERVER" "AVG PING"
echo -en "${txtrst}"
FullBar
array_counter=0
for number in ${KEYSERVERS[@]}
do
TESTVALUE=${KEYSERVERS[$array_counter]}
if [[ $TESTVALUE ]]; then
PINGTIME[$array_counter]=`ping -qc 10 $TESTVALUE | awk -F/ '/^rtt/ { print $5 }' | bc | sed 's/[.].*//'`
PINGSPEED=${PINGTIME[$array_counter]}
if [[ $PINGSPEED ]]; then
echo -e -n "${bldgrn}";
printf '%-30s %s\n' \
"$TESTVALUE" "$PINGSPEED"
else
echo -e -n "${bldred}";
printf '%-30s %s\n' \
"$TESTVALUE" "DOWN"
fi
fi
array_counter=$(($array_counter + 1))
done
FASTEST=9999
INDEX=0
for i in ${PINGTIME[@]}
do
INDEX=$(($INDEX + 1))
if [[ $i -lt $FASTEST ]]; then
FASTEST="$i"
CURRENT=$(($INDEX - 1))
fi
done
echo -e "${txtrst}"
FullBar
Center "Setting default keyserver: ${KEYSERVERS[$CURRENT]} | $FASTEST"
FullBar
echo ${KEYSERVERS[$CURRENT]} > ~/.keysnatcher
else
Center "Fastest keyserver has already been set"
FullBar
cat ~/.keysnatcher
fi
else
Center "Skipping connectivity test as requested."
FullBar
fi
}
function FixErrors(){
VersionDump
if [[ $UID != '0' ]]; then
Error "Insufficent privilages. Please prefix sudo, or perform as super user."
Encapsulate "sudo keysnatcher --fixerrors"
FullBar
exit 0;
fi
#verify there is an error log
if [[ -s /tmp/keymissing ]]; then
#strip empty lines from error log
sed -i '/^\s*$/d' /tmp/keymissing
#read error log, turn on IFS to keep things contingent
Encapsulate "Fixing 404 (File not found) error(s) if any."
while IFS= read line
do
#parse error long, searching... seek and destroy. ;)
#comment out 404 repositories.
for FILEZ in $(ls /etc/apt/sources.list.d/*.list)
do
#Nullify varible each pass.
GREPIT=''
#chop out only necessary information. SS is for search string.
SS=$(echo "$line" | grep '404' | cut -d' ' -f5 | cut -d'/' -f1-4)
#echo "Processing $FILEZ looking for $SS"
GREPIT=$(cat $FILEZ | grep "$SS")
if [[ $GREPIT && $SS ]]; then
if [[ -w $FILEZ ]]; then
sed -i 's/^deb/# deb/g' $FILEZ
Encapsulate "Fixing error in "$FILEZ": Success"
else
Error "Fixing error in "$FILEZ": Error, insufficient privilages, please prefix sudo."
fi
fi
done
done <"/tmp/keymissing"
# Fix 403 Error(s)
Encapsulate "Fixing 403 (Forbidden) error(s) if any."
while IFS= read line
do
#parse error long, searching... seek and destroy. ;)
#comment out 404 repositories.
for FILEZ in $(ls /etc/apt/sources.list.d/*.list)
do
#Nullify varible each pass.
GREPIT=''
#chop out only necessary information. SS is for search string.
SS=$(echo "$line" | grep '403' | cut -d' ' -f5 | cut -d'/' -f1-4)
#echo "Processing $FILEZ looking for $SS"
GREPIT=$(cat $FILEZ | grep "$SS")
if [[ $GREPIT && $SS ]]; then
if [[ -w $FILEZ ]]; then
sed -i 's/^deb/# deb/g' $FILEZ
Encapsulate "Fixing error in "$FILEZ": Success"
else
Error "Fixing error in "$FILEZ": Error, insufficient privilages, please prefix sudo."
fi
fi
done
done <"/tmp/keymissing"
# Fix Arch related issue(s)
Encapsulate "Fixing \"Failed to fetch\" (Architecture) error(s) if any."
while IFS= read line
do
#comment out missing repositories (architecture related issues).
for FILEZ in $(ls /etc/apt/sources.list.d/*.list)
do
#Nullify varible each pass.
GREPIT=''
#chop out only necessary information. SS is for search string.
SS=$(echo "$line" | grep 'Failed to fetch' | cut -d' ' -f5 | cut -d'/' -f1-4)
#echo "Processing $FILEZ looking for $SS"
GREPIT=$(cat $FILEZ | grep "$SS")
if [[ $GREPIT && $SS ]]; then
if [[ -w $FILEZ ]]; then
sed -i 's/^deb/# deb/g' $FILEZ
Encapsulate "Fixing error in "$FILEZ": Success"
else
Error "Fixing error in "$FILEZ": Error, insufficient privilages, please prefix sudo."
fi
fi
done
done <"/tmp/keymissing"
FullBar
else
Center "Fix Errors"
Encapsulate "There are no errors to fix."
FullBar
fi
exit 0;
}
function ServerTimeOut(){
#Fix for the following:
#[Connecting to mirror1.mate-desktop.org (2a01:4f8:100:7003::10)]
#(2a01:4f8:100:7003::10) is IPV6 and causes great delays in retriving package lists
#The Fix or "Workaround" is to set a 2 second timeout in apt conf
VersionDump
# Turn of case sensitivity ReMoVe will work ;)
shopt -s nocasematch
# check [optional] secondary switch.
if [[ $2 == "remove" || $2 == '--remove' ]]; then
# Make sure the file exists, if not bail out.
if ! [[ -f /etc/apt/apt.conf.d/70debconf ]]; then
Error "ERROR: /etc/apt/apt.conf.d/70debconf does not exist."
exit 0;
fi
if ! [[ -w /etc/apt/apt.conf.d/70debconf && -f /etc/apt/apt.conf.d/70debconf ]]; then
Error "Insufficent privilages. Please prefix sudo, or perform as super user."
Encapsulate "sudo keysnatcher --timeout remove"
FullBar
exit 0;
fi
sed -i '/^\/\/Server down takes too long, add timeout/ d' /etc/apt/apt.conf.d/70debconf
sed -i '/^Acquire::http::Timeout "2";/ d' /etc/apt/apt.conf.d/70debconf
sed -i '/^Acquire::ftp::Timeout "2";/ d' /etc/apt/apt.conf.d/70debconf
GREPPED=$(cat /etc/apt/apt.conf.d/70debconf | grep -i "Timeout")
if ! [[ $GREPPED ]]; then
Encapsulate "Removing server timeout setting: Success"
FullBar
else
Error "Removing server timeout setting: Failure"
fi
else
if [[ -f /etc/apt/apt.conf.d/70debconf ]]; then
SUCCESS=$(cat /etc/apt/apt.conf.d/70debconf | grep -i 'Timeout')
if ! [[ $SUCCESS ]]; then
if ! [[ -w /etc/apt/apt.conf.d/70debconf ]]; then
Error "Insufficent privilages. Please prefix sudo, or perform as super user."
Encapsulate "sudo keysnatcher --timeout"
FullBar
exit 0;
fi
SUCCESS=$(echo '//Server down takes too long, add timeout' | tee -a /etc/apt/apt.conf.d/70debconf)
SUCCESS=$(echo 'Acquire::http::Timeout "2";' | tee -a /etc/apt/apt.conf.d/70debconf)
SUCCESS=$(echo 'Acquire::ftp::Timeout "2";' | tee -a /etc/apt/apt.conf.d/70debconf)
if [[ $SUCCESS ]]; then
Encapsulate "Setting 2 second server timeout a fix for IPV6 issues: Success"
FullBar
else
Encapsulate "Setting 2 second server timeout a fix for IPV6 issues: Failure"
FullBar
fi
else
Encapsulate "Server Timeout has already been configured."
FullBar
fi
else
echo -e -n "${bldgrn}Setting 2 second server timeout a fix for IPV6 issues: "
SUCCESS=$(echo '//Server down takes too long, add timeout' | sudo tee -a /etc/apt/apt.conf.d/70debconf)
SUCCESS=$(echo 'Acquire::http::Timeout "2";' | sudo tee -a /etc/apt/apt.conf.d/70debconf)
SUCCESS=$(echo 'Acquire::ftp::Timeout "2";' | sudo tee -a /etc/apt/apt.conf.d/70debconf)
if [[ $SUCCESS ]]; then
Encapsulate "Setting 2 second server timeout a fix for IPV6 issues: Success"
else
Encapsulate "Setting 2 second server timeout a fix for IPV6 issues: Failure"
fi
fi
fi
}
function ReScan(){
if [[ -f ~/.keysnatcher ]]; then
if [[ -w ~/.keysnatcher ]]; then
SUCCESS=$(rm ~/.keysnatcher)
Connectivity
else
VersionDump
Error "Insufficent privilages. Please prefix sudo, or perform as super user."
Encapsulate "sudo keysnatcher --rescan"
exit 0;
fi
else
VersionDump
Error "Error: No configuration found, please run keysnatcher --snatch first."
exit 0;
fi
}
function Help() {
VersionDump
if [[ $1 == "" ]];
then
PRAM="ALL"
else
PRAM=$1
fi
case $PRAM in
ALL)
echo -e "\n"
EyeCandy "${bldgrn}Usage: $PROGNAME -<-COMMAND>${txtrst}"
echo -e "Mandatory arguments to long options are identical for short options."
echo -e " possible commands..."
echo -e ""
echo -e " -f --fixerrors fix 403 / 404 errors with repositories"
echo -e " -s --snatch snatch missing keys"
echo -e " -h --help this help message"
echo -e " -r --rescan rescan servers to determine which is fastest"
echo -e " -t --timeout fix IPV6 timeout issues"
echo -e " -v --version dump version info"
echo -e ""
echo -e "${bldgrn}$PROGNAME --help [COMMAND] for further information.${txtrst}";;
ALL|f|fixerrors)
echo -e ""
EyeCandy "${bldgrn}Usage fixerrors;${txtrst}"
echo -e "${txtgrn}$PROGNAME -f${txtrst}"
echo -e " Fixes repository based error(s). Any repository that gives a 404 or 403 error"
echo -e " is pushed into a error log, this error log is parsed and scans your"
echo -e " software sources looking for the offending repository. The offending"
echo -e " repository is then commented out allowing you to if so desired reverse"
echo -e " it's effect, for example if the server should happen to come back online.\n";;
ALL|s|snatch)
echo -e ""
EyeCandy "${bldgrn}Usage snatch;${txtrst}"
echo -e "${txtgrn}$PROGNAME -s [OPTION]${txtrst}"
echo -e " Snatches missing GPG keys. The software will determine the fastest GPG"
echo -e " key server this operation is only performed once (see help rescan) to"
echo -e " accelerate any future grabbing of missing keys. The sofware then scans"
echo -e " for missing keys and retrieves any missing key from the fastest detected"
echo -e " key server. You may optionally [skip] the connectivity test.\n"
echo -e "${bldgrn}Example: keysnatcher --snatch skip\n${txtrst}";;
ALL|r|rescan)
echo -e ""
EyeCandy "${bldgrn}Usage rescan;${txtrst}"
echo -e "${txtgrn}$PROGNAME -r${txtrst}"
echo -e " Rescans GPG key servers and sets the fastest server as your default for"
echo -e " retriving GPG keys.\n";;
ALL|t|timeout)
echo -e ""
EyeCandy "${bldgrn}Usage timeout [remove];${txtrst}"
echo -e "${txtgrn}$PROGNAME -t${txtrst}"
echo -e " Sets the default timeout for a server response to 2 seconds. IPV6"
echo -e " servers can take up to 3 minutes to resolve, this \"workaround\" accelerates"
echo -e " this operation. If you are for some reason not happy with this resolve"
echo -e " you can remove it with the [OPTIONAL] remove switch.\n"
echo -e "${bldgrn}Example: keysnatcher --timeout remove\n${txtrst}";;
ALL|v|version)
echo -e ""
EyeCandy "${bldgrn}Usage version;${txtrst}"
echo -e "${txtgrn}$PROGNAME -v${txtrst}"
echo -e " Displays $PROGNAMEs version number and exits.\n";;
ALL|h|help|\?)
echo -e ""
EyeCandy "${bldgrn}Useage Help [COMMAND];${txtrst}"
echo -e "${txtgrn}$PROGNAME -h [COMMAND]${txtrst}"
echo -e " Displays this message. For futher information $PROGNAME help [COMMAND]"
echo -e " or refer to the manpages.\n"
echo -e ""
echo -e "man $PROGNAME"
echo -e "${txtgrn}"
echo -e "Example: $PROGNAME -h version"
echo -e "${txtwht}Will display help about the command version${txtrst}";;
*)
echo -e ""
EyeCandy "${bldgrn}Useage Help [COMMAND];${txtrst}"
echo -e "${txtgrn}$PROGNAME -h [COMMAND]${txtrst}"
echo -e " Displays this message. For futher information $PROGNAME help [COMMAND]"
echo -e " or refer to the manpages."
echo -e ""
echo -e "man $PROGNAME"
echo -e "${txtgrn}"
echo -e "Example: $PROGNAME -h version"
echo -e "${txtwht}Will display help about the command version${txtrst}\n";;
esac
FullBar
exit 0
}
# Command line pre-processor
case "$1" in
-r|--rescan) ReScan; exit 0;;
-f|--fixerrors) FixErrors; exit 0;;
-t|--timeout) ServerTimeOut $*; exit 0;;
-s|--snatch) Connectivity $*; GrabKeys; exit 0;;
-h|--help|-\?) Help $2; exit 0;;
-v|--version) VersionDump; exit 0;;
*) Help; exit 0;;
esac
Bash autocompletion:
- Code: Select all
# Debian keysnatcher(8) completion.
have keysnatcher &&
_keysnatcher()
{
dashify()
{
local i
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
if [ ${#COMPREPLY[i]} -le 2 ]; then
COMPREPLY[i]=-${COMPREPLY[i]}
else
COMPREPLY[i]=--${COMPREPLY[i]}
fi
done
}
local cur cur_nodash prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
cur_nodash=${cur#-}
prev=${COMP_WORDS[COMP_CWORD-1][COMP_CWORD-2]}
if [ $COMP_CWORD = 1 ]; then
# first parameter on line
case "$cur" in
-s*)
COMPREPLY=( $( compgen -W 'snatch' \
$cur_nodash ) )
dashify
return 0
;;
-f*)
COMPREPLY=( $( compgen -W 'fixerrors' \
$cur_nodash ) )
dashify
return 0
;;
-t*)
COMPREPLY=( $( compgen -W 'timeout' \
$cur_nodash ) )
dashify
return 0
;;
-r*)
COMPREPLY=( $( compgen -W 'rescan' \
$cur_nodash ) )
dashify
return 0
;;
-h*)
COMPREPLY=( $( compgen -W 'help' \
$cur_nodash ) )
dashify
return 0
;;
-v*)
COMPREPLY=( $( compgen -W 'verbose version' \
$cur_nodash ) )
dashify
return 0
;;
--*)
COMPREPLY=( $( compgen -W 'fixerrors snatch help timeout rescan version' ${cur_nodash#-} ) )
dashify;
return 0
;;
*)
COMPREPLY=( $( compgen -W 'f s h r t v' \
$cur_nodash ) )
dashify
return 0
;;
esac
fi
if [ $COMP_CWORD = 2 ]; then
case "${COMP_WORDS[1]}" in
--t*)
# analyze completion
COMPREPLY=( $( compgen -W 'remove' \
$cur_nodash ) )
dashify
return 0
;;
-t*)
# analyze completion
COMPREPLY=( $( compgen -W 'remove' \
$cur_nodash ) )
dashify
return 0
;;
-s*)
# analyze completion
COMPREPLY=( $( compgen -W 'skip' \
$cur_nodash ) )
dashify
return 0
;;
--s*)
# analyze completion
COMPREPLY=( $( compgen -W 'skip' \
$cur_nodash ) )
dashify
return 0
;;
--h*)
# complete on list of relevant options
COMPREPLY=( $( compgen -W 'fixerrors help rescan snatch timeout version' ${cur_nodash#-} ) )
#dashify;
return 0
;;
-h)
# complete on list of relevant options
COMPREPLY=( $( compgen -W 'fixerrors help rescan snatch timeout version' ${cur_nodash#-} ) )
#dashify;
return 0
;;
esac
fi
case "${COMP_WORDS[2]}" in
timeout)
# standard filename completion
COMPREPLY=( $( compgen -W 'remove' ${cur_nodash#-} ) )
return 0
;;
-t*)
# standard filename completion
COMPREPLY=( $( compgen -W 'remove' ${cur_nodash#-} ) )
return 0
;;
snatch)
# standard filename completion
COMPREPLY=( $( compgen -W 'skip' ${cur_nodash#-} ) )
return 0
;;
-s*)
# standard filename completion
COMPREPLY=( $( compgen -W 'skip' ${cur_nodash#-} ) )
return 0
;;
esac
}
complete -F _keysnatcher keysnatcher
The App:
http://os-builder.com/UETOYS/
There are comments in the code for any further reading. Any questions please feel free to ask.