#!/bin/bash export TEXTDOMAIN="zero-center" MSG_INSTALLING=$(gettext "Installing") MSG_INSTALLED=$(gettext "Installed") MSG_REMOVING=$(gettext "Removing") MSG_REMOVED=$(gettext "Removed") MSG_FINISH_INSTALLED=$(gettext "has been INSTALLED in your system, and you can view the log in") MSG_FINISH_SYSTEM1=$(gettext "has been") MSG_FINISH_SYSTEM=$(gettext "in your system, and you can view the log in") MSG_FINISH_ERROR=$(gettext "Please review your repositories and reinstall it again .If you can\'t resolve the problem please contact with Lliurex Team at http://mestreacasa.gva.es/web/lliurex/forums") PACKAGE_NAME="$1" INSTALL_LOG="/tmp/zero-${PACKAGE_NAME}.log" ZERO_LOG="/tmp/zero-installer.log" ####FUNCIONES #Aqui listaremos las opciones del helper function helper { if [ "$1" = "--help" ] || [ "$1" = "-h" ] || [ "$1" = "" ]; then echo echo "----ZERO-REINSTALL-HELPER----" echo echo "zero-reinstall " echo echo "arg1: Is the name of the package to reinstall" echo echo "example: zero-reinstall hotpotatoes" echo exit 0 fi } #FUNCION QUE TESTEA SI UN PAQUETE ESTA INSTALADO, BORRANDOLO EN CASO AFIRMATIVO function test_install { #Testeamos si el paquete esta instalado, no haciendo nada en el caso afirmativo o instalandolo en el caso negativo. TEST=$( dpkg-query -s $1 2> /dev/null| grep Status | cut -d " " -f 4 ) if [ "$TEST" = 'installed' ]; then echo " " >> $INSTALL_LOG echo "Package $1 already installed, we have to uninstall it" >> $INSTALL_LOG echo "Package $1 already installed, we have to uninstall it" zero-installer remove $1 cat $ZERO_LOG >> $INSTALL_LOG fi } ################MAIN###################### #Log para el zero-center if [ -f $INSTALL_LOG ]; then rm $INSTALL_LOG fi #COMPRUEBA QUE EL PARÁMETRO ESTA BIEN Y NO SE SOLICITA AYUDA helper "$PACKAGE_NAME" #TESTEAMOS SI ESTAN INSTALADOS test_install "$PACKAGE_NAME" #YA SABEMOS QUE EL PROGRAMA ESTA DESINSTALADO, VAMO A INSTALARLO DE NUEVO echo " " >> $INSTALL_LOG echo "Zero-installer install the package $PACKAGE_NAME" >> $INSTALL_LOG echo "Zero-installer install the package $PACKAGE_NAME" zero-installer install "$PACKAGE_NAME" #Me guardo el fichero de los logs por si algo fallase o para revisarlo cat $ZERO_LOG >> $INSTALL_LOG #Testeamos si el paquete se ha instalado bien TEST=$( dpkg-query -s $PACKAGE_NAME 2> /dev/null| grep Status | cut -d " " -f 4 ) if [ "$TEST" = 'installed' ]; then echo " ------------------- " >> $INSTALL_LOG echo "Package $PACKAGE_NAME has been installed, Congratulations" zenity --info --title="Zero-installer" --text="$PACKAGE_NAME $MSG_FINISH_INSTALLED $INSTALL_LOG" > /dev/null 2>&1 & su -c "notify-send -t 2000 -u critical -i /usr/share/icons/lliurex-neu/scalable/apps/zero-center.svg 'Zero-Installer' '$PACKAGE_NAME $MSG_FINISH_INSTALLED $INSTALL_LOG'" $USER exit 0 else echo " ------------------- " >> $INSTALL_LOG echo "$MSG_FINISH_ERROR" zenity --info --title="Zero-installer" --text="$PACKAGE_NAME $MSG_FINISH_ERROR $INSTALL_LOG" > /dev/null 2>&1 & su -c "notify-send -t 2000 -u critical -i /usr/share/icons/lliurex-neu/scalable/apps/zero-center.svg 'Zero-Installer' '$PACKAGE_NAME $MSG_FINISH_ERROR $INSTALL_LOG'" $USER exit 1 fi