Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # PubKey 1.0
- # Script(Gui)to Import PubKey APT Keys
- # By Frannoe@gmail.com (Francisco Luque)
- # http://frannoe.blogspot.com.es/
- # Este Script es para sistemas basados en Debian y añade de forma totalmente automática las Llaves
- # de los repositorios que no se encuentre en Orígenes de Software y que por lo tanto causan error a la hora de actualizar.
- # Tambiénm podemos eliminar Llaves o ver información sobre éstas
- # Este Script necesita de YAD (>= 0.25.1) para su correcto funcionamiento.
- # Esta herramienta es totalmente Libre y puede modificarla y mejorarla tanto como quiera.
- export EXITINFO=" --fixed --width=350 --buttons-layout=center --button=Ok:0 "
- function importkey () {
- #yad --info --fixed --width "400" --buttons-layout=center --button=Salir:1 --button=Continuar:0 --title "PubKeys" --text-align=center --text "Se van a actualizar sus repositorios. Al realizar este proceso se comprobará también que todas las Llaves públicas de estos se encuentren disponibles. Si no es así, recibirá un mensaje advirtiéndole de ello. Podrá luego decidir si quiere o no, importar la llave que necesite.\n¿Desea continuar?."
- #if [ $? != 0 ]; then
- #rm -f /tmp/pubkeys /tmp/tmprogpubkey /tmp/allremovekeys
- #exit
- #fi
- #HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
- #HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
- function updatrepor
- {
- dir / >> /tmp/tmprogpubkey
- tail -f /tmp/tmprogpubkey | yad --fixed --width "400" --title " $2 " --text-align=center --text " $3 " --no-buttons --progress --pulsate --auto-close &
- case "$1" in
- 1)
- LC_ALL=C apt-get update >> /dev/null 2> /tmp/pubkeys
- cp -f /tmp/pubkeys /tmp/allremovekeys
- auxruta="/tmp/pubkeys"
- if [ $? != 0 ]; then
- killall -KILL tail
- yad --info --fixed --width=450 --buttons-layout=center --button=Ok:0 --text-align=center --title "Error al ejecutar Pubkey" --text-align=center --text "Ha ocurrido un error al intentar actualizar los repositorios. Esto puede ser debido a varias causas:\n -- No ha ejecutado el Script con permisos de Administrador\n -- Tiene abierto algún gestor de repositorios tipo:\nSynaptic\nGestor de Actualizaciones\nOrígenes de Software, etc.\n -- No tiene conexión a la Red.\nCompruebe alguno de estos supuesto y vuelva a intentarlo."
- exit
- fi
- sed -i '/NO_PUBKEY/!d' /tmp/pubkeys
- ;;
- 2)
- while read puckselecc
- do
- key=${puckselecc: -8}
- errkey=${puckselecc: -16}
- exp1=` LC_ALL=C gpg --keyserver keyserver.ubuntu.com --recv-key $key && gpg -a --export $key | apt-key add - | awk '{print $1}'`
- if [ "$exp1" != "OK" ]; then
- exp1=` LC_ALL=C gpg --keyserver subkeys.pgp.net --recv-key $key && gpg -a --export $key | apt-key add - | awk '{print $1}'`
- fi
- if [ "$exp1" != "OK" ]; then
- killall -KILL tail
- yad --info $EXITINFO --title "$errkey" --text-align=center --text "Ha ocurrido un error al intentar importar la Llave:\n$errkey\nAsegúrese de que su equipo se encuentre conectado a la Red."
- rm -f /tmp/pubkeys /tmp/tmprogpubkey /tmp/allremovekeys
- exit
- fi
- done < $auxruta
- QUES=$?
- sleep 1
- killall -KILL tail
- if [ $QUES != 0 ]; then
- yad --info EXITINFO --title "Error..." --text-align=center --text "Error inesperado. Se saldra del programa."
- rm -f /tmp/pubkeys /tmp/tmprogpubkey /tmp/allremovekeys
- exit
- else
- yad --info --buttons-layout=center --button=Salir:1 --button=Actualizar:0 --title "Importación exitosa." --text-align=center --text "Las Llaves han sido añadidas con éxito. Ahora es recomendable actualizar nuevamente los repositorios."
- if [ $? != 0 ]; then
- rm -f /tmp/pubkeys /tmp/tmprogpubkey /tmp/allremovekeys
- exit
- fi
- fi
- ;;
- esac
- sleep 1
- killall -KILL tail
- }
- updatrepor 1 "Actualizando..." "Actualizando el Sistema y buscando repositorios sin Llaves. Esto puede tardar un poco, espere por favor..."
- if [ -s /tmp/pubkeys ]; then
- while read encon
- do
- cont=`expr $cont + 1`
- KEYS+=("")
- KEYS+=("$(echo $cont"- " $encon | awk '{print $1,$2,$3,$4,$5,$6,$(NF-0)}')")
- done < /tmp/pubkeys
- QUES=""
- until [[ "$selecc" != "" || $QUES = 2 ]]
- do
- selecc=`yad --buttons-layout=center --button=Salir:1 --button="Importar todas":2 --button="Importar seleccionadas":0 --list --title "Listado de repositorios sin Llave..." --height "200" --width "600" --text-align=center --text "Seleccione de la lista de abajo las Llaves que quiera importar:" --checklist --column "Select" --column "'$cont' Llaves pendientes de importar" "${KEYS[@]}" --no-click`
- QUES=$?
- if [ $QUES = 1 ]; then
- exit
- fi
- done
- if [ $QUES = 2 ]; then
- auxruta="/tmp/allremovekeys"
- else
- echo $selecc | sed -e 's/TRUE|//g' -e 's/|/\n/g' | sed -e 's/^ //g' -e '$d' > /tmp/pubkeys
- fi
- updatrepor 2 "Importando Llaves..." "Importando las Llaves seleccionadas, espere por favor..."
- apt-get update | yad --fixed --width "500" --title "Actualizando..." --text-align=center --text "Poniendo al día los repositorios, esto puede tardar un poco, espere por favor..." --no-buttons --progress --pulsate --auto-close
- if [ $? != 0 ]; then
- sleep 1
- killall -KILL tail
- yad --info $EXITINFO --title "Error" --text-align=center --text "Ha ocurrido un error al intentar actualizar nuevamente los repositorios."
- rm -f /tmp/pubkeys /tmp/tmprogpubkey /tmp/allremovekeys
- exit
- else
- sleep 1
- killall -KILL tail
- yad --info $EXITINFO --title "Actualización" --text-align=center --text "Los repositorios han sido actualizados con éxito."
- rm -f /tmp/pubkeys /tmp/tmprogpubkey /tmp/allremovekeys
- exit
- fi
- else
- yad --info $EXITINFO --title "PubKey" --text-align=center --text "Sus repositorios están correctos y no es necesaria ninguna Llave."
- rm -f /tmp/pubkeys /tmp/tmprogpubkey /tmp/allremovekeys
- exit
- fi
- }
- #HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
- #HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
- function deletekey ()
- {
- apt-key update
- sleep 1
- #gpg --no-default-keyring --keyring "/etc/apt/trusted.gpg" --list-keys | grep -e pub -e uid | awk '{print $0 }'| sed '1d' > /tmp/delpubkey
- LC_ALL=C gpg -k | grep -e pub -e uid | awk '{print $0 }'| sed '1d' > /tmp/delpubkey
- dupl="x"
- while [ "$dupl" != "" ]
- do
- dupl=$(awk 'x==$1{print NR; while(getline)(x!=$1)}{x=$1}' /tmp/delpubkey)
- if [ "$dupl" != "" ]; then
- sed -i ''$dupl'd' /tmp/delpubkey
- fi
- done
- #apt-key list | grep -e uid | awk '{print $0 }' | sed -e "s/pub//g" -e "s/uid//g" -e "s/^ *//g" | cut -d "<" -f 1 | sort -u > /tmp/delpubkey
- uids=$(cat /tmp/delpubkey | grep -e uid | awk '{print $0 }' | sed -e "s/pub//g" -e "s/uid//g" -e "s/^ *//g" | cut -d "<" -f 1 | uniq)
- pubs=$(cat /tmp/delpubkey | grep -e pub | awk '{print $2 }' | sed -e "s/pub//g" -e "s/uid//g" -e "s/^ *//g"| cut -d "/" -f 2)
- paste <(printf "$uids") <(printf "$pubs") > /tmp/delpubkey
- while read delkeys
- do
- cont=`expr $cont + 1`
- list+=("")
- list+=("$(echo $cont"- " $delkeys)")
- done < /tmp/delpubkey
- key=""
- QUES=""
- until [ "$delselecc" != "" ]
- do
- delselecc=`yad --button=Salir:1 --button="Eliminar seleccionadas":0 --buttons-layout=center --list --title "Listado de llaves públicas" --height "600" --width "600" --text-align=center --text "Listado de llaves públicas encontradas en el sistema." --checklist --column "" --column "Llaves posibles de eliminar" "${list[@]}" --no-click`
- QUES=$?
- if [ $QUES != 0 ]; then
- rm -f /tmp/delpubkey
- exit
- fi
- done
- QUES=""
- yad --info --fixed --width=450 --buttons-layout=center --button=Abortar:1 --button=Continuar:0 --title "Listados de Llaves públicas" --text-align=center --text "Confirme que desea eliminar las llaves seleccionadas."
- QUES=$?
- if [ $QUES != 0 ]; then
- rm -f /tmp/delpubkey
- exit
- fi
- echo $delselecc | sed -e 's/TRUE|//g' -e 's/|/\n/g' | sed -e 's/^ //g' -e '$d' > /tmp/delpubkey
- while read puckdelselecc
- do
- delkey=${puckdelselecc: -8}
- errdelkey=`apt-key del $delkey && gpg --batch --yes --delete-key $delkey | awk '{print $1}'`
- if [ "$errdelkey" != "OK" ]; then
- killall -KILL tail
- yad --info $EXITINFO --title "$delkey" --text-align=center --text "Ha ocurrido un error al intentar eliminar la Llave:\n$delkey"
- rm -f /tmp/delpubkey
- exit
- else
- yad --info $EXITINFO --title "Llave eliminada..." --text-align=center --text "Llave <b>$delkey</b> ha sido eliminada correctamete."
- rm -f /tmp/delpubkey
- fi
- done < /tmp/delpubkey
- apt-key update
- sleep 1
- }
- #HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
- #HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
- function infokey ()
- {
- apt-key update
- sleep 1
- #gpg --no-default-keyring --keyring "/etc/apt/trusted.gpg" --list-keys | grep -e pub -e uid | awk '{print $0 }'| sed '1d' > /tmp/delpubkey
- LC_ALL=C gpg -k | grep -e pub -e uid | awk '{print $0 }'| sed '1d' > /tmp/delpubkey
- dupl="x"
- while [ "$dupl" != "" ]
- do
- dupl=$(awk 'x==$1{print NR; while(getline)(x!=$1)}{x=$1}' /tmp/delpubkey)
- if [ "$dupl" != "" ]; then
- sed -i ''$dupl'd' /tmp/delpubkey
- fi
- done
- #apt-key list | grep -e uid | awk '{print $0 }' | sed -e "s/pub//g" -e "s/uid//g" -e "s/^ *//g" | cut -d "<" -f 1 | sort -u > /tmp/delpubkey
- uids=$(cat /tmp/delpubkey | grep -e uid | awk '{print $0 }' | sed -e "s/pub//g" -e "s/uid//g" -e "s/^ *//g" | cut -d "<" -f 1 | uniq)
- pubs=$(cat /tmp/delpubkey | grep -e pub | awk '{print $2 }' | sed -e "s/pub//g" -e "s/uid//g" -e "s/^ *//g"| cut -d "/" -f 2)
- paste <(printf "$uids") <(printf "$pubs") > /tmp/delpubkey
- while read infokeys
- do
- cont=`expr $cont + 1`
- list+=("")
- list+=("$(echo $cont"- " $infokeys)")
- done < /tmp/delpubkey
- key=""
- QUES=""
- until [ "$infoselecc" != "" ]
- do
- infoselecc=`yad --button=Salir:1 --buttons-layout=center --title "Listado de llaves públicas" --height "600" --width "600" --text-align=center --text "<b>Doble-clic para ver más información sobre una Llave.</b>" --list --column=STRING:HD --column "Llaves encontradas" "${list[@]}" --no-click`
- QUES=$?
- if [ $QUES != 0 ]; then
- rm -f /tmp/delpubkey
- exit
- fi
- infoselecc=`echo $infoselecc | awk '{print $NF}' | sed -e "s/|//g"`
- LC_ALL=C gpg --fingerprint $infoselecc > /tmp/delpubkey
- sed -i -e "s/pub/Pub = /g" -e "s/sub/Sub = /g" -e "s/uid/UID = /g" -e "s/ [ ]*/ /g" /tmp/delpubkey
- yad --buttons-layout=center --width=550 --height=200 --button="Salir":1 --title "Llave: $infoselecc" --text-align=center --text-info --text "Datos sobre la Llave seleccionada: <b>$infoselecc</b>" --filename=/tmp/delpubkey
- rm -f /tmp/delpubkey
- done
- }
- #HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
- #HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
- export -f importkey
- export -f deletekey
- export -f infokey
- `yad --fixed --width "400" --buttons-layout=center --button="Salir":1 --text-align=center --title "PubKey 1.0" --text "<b>Pulse la opción que necesite procesar:</b>" \
- --form \
- --field=:LBL '' \
- --field=:LBL '' \
- --field="Añadir llaves públicas":BTN 'bash -c "importkey"' \
- --field=:LBL '' \
- --field="Ver listado de Llaves públicas":BTN 'bash -c "infokey"' \
- --field=:LBL '' \
- --field="Eliminar llaves públicas":BTN 'bash -c "deletekey"' \
- --field=:LBL '' \
- --field=:LBL ''`
- if [ $? != "0" ]; then
- rm -f /tmp/pubkeys /tmp/tmprogpubkey /tmp/allremovekeys
- exit
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement