#!/bin/bash #zenity --info --title="Zero-jClic-Biblio-Installer" --timeout=4 --text="Welcome to JCLIC biblio installer, please be calm we are testing your net." > /dev/null 2>&1 & export TEXTDOMAIN="zero-lliurex-jclic-biblio-installer" #####################DEFINICION DE VARIABLES############################################## elteumestre="elteumestre_JClic_Infantil_Primaria_17 (4 GB)" #murcia="Murcia_0809 (2 GB)" #ratoli="JaumeBalmes2017 (3 GB)" #MARCA=$(gettext "Check") #LIBRERIAS=$(gettext "Available files") #TITULO=$(gettext "Jclic Libraries to download") #MSG_NO_INTERNET=$(gettext "No Internet Connection has been detected. Please, check it") IMAGENES_EL_TEU="http://www.lliurex.net/recursos/" PACK_EL_TEU="elteumestre_JClic_Infantil_Primaria_17.zip" #IMAGENES_MURCIA="http://www.lliurex.net/recursos/" #PACK_MURCIA="Murcia_0809.tar.gz" #IMAGENES_RATOLI="http://www.lliurex.net/recursos/" #PACK_RATOLI="JaumeBalmes2017.zip" LOG=/tmp/jclic_biblio.log TEST="0" EXITO="1" SALIR="1" PATH_TO_JCLIC_PROJECTS="/net/server-sync/share/jclic-aula/jclic_uploads" ##################FUNCIONES#################################### function test_file { #Funcion que comprueba si lo descargado esta bien o fue antes cancelado #Argumentos #$1: es la URL del fichero original, URL #$2: Es el nombre del fichero descargado por defecto en tmp, NAME #echo "Argumento 1, URL: $1" #echo "Argumento 2, NAME: $2" #Obtengo el tamaño original del fichero. LANGUAGE=en wget --spider -o /tmp/jclic_length.log "$1" LENGTH_ORIG=$( cat /tmp/jclic_length.log | grep Length | awk '{print $2}' ) #Obtengo el tamaño del fichero descargado LENGTH_DOWNLOAD=$( ls -l /tmp/$2 2>/dev/null | awk '{print $5}' ) #echo "LENGTH_ORIG is $LENGTH_ORIG" #echo "LENGTH_DOWNLOAD is $LENGTH_DOWNLOAD" #Comparo ambos valores if [ "$LENGTH_ORIG" != "$LENGTH_DOWNLOAD" ]; then echo "$2 cannot been installed in your system," echo "because you cancel it or the downloading has been a problem." echo "Start again the process if you want to install it and if the problem continues," echo "please contact with Lliurex-Team to resolve it." echo "" zenity --info --title="Zero-jClic-Biblio-Installer" --text="$2 cannot been installed in your system because you cancel it or the downloading has been a problem. Start again the process if you want to install it and if the problem continues, please contact with Lliurex-Team to resolve it." > /dev/null 2>&1 & su -c "notify-send -t 3000 -u critical -i /usr/share/icons/lliurex-neu/scalable/apps/zero-center.svg 'Zero-Installer' '$2 cannot been installed in your system because you cancel it or the downloading has been a problem'" $USER > /dev/null 2>&1 TEST="0" else #La descarga es correcta entonces instalamos la biblioteca TEST="1" fi rm /tmp/jclic_length.log } function install_jclic { #Funcion de instalacion #$1: Argumento con el fichero a instalar, por defecto descargado en tmp, NAME #$2: Argumento para instalar la libreria jclic, PATH_TO_JCLIC_PROJECTS LOG_UN=/tmp/jclic_un.log touch $LOG_UN #Obtengo la extension del fichero, rar, zip.... EXT=$( ls /tmp/$1 | rev | cut -d "." -f 1 | rev ) echo "The file downloaded to install is $1 and the extension is $EXT" if [ ! -d "$2" ]; then mkdir -p "$2" fi #Compruebo que es una de las extensiones esperadas o salgo if [ "$EXT" != "zip" ] && [ "$EXT" != "gz" ]; then echo "$1 cannot been installed in your system," echo "because the extension is $EXT." echo "Jclic needs zip or tar extension to install it." echo "Start again the process if you want to install it and if the problem continues," echo "please contact with Lliurex-Team to resolve it." echo "" #Variable que indica que la extension es la que se esperaba y permitida, me vale para distinguir entre error de extension o de descompresion #Aqui es necesario tb inicializarla porque si ponemos dos o mas paquetes a descargar podria ocurrir que en una segunda pasada tuviese un valor no esperado EXITO="1" #Variable que nos da que hubo error en la extension y como el error ya se mostro no se muestra nada mas y se aborta el resto de la funcion que lo llamo. SALIR="0" zenity --info --title="Zero-jClic-Biblio-Installer" --text="$1 cannot been installed in your system because the archive has the extension $EXT and Jclic needs ZIP or GZ extension. Start again the process if you want to install it and if the problem continues, please contact with Lliurex-Team to resolve it." > /dev/null 2>&1 & su -c "notify-send -t 3000 -u critical -i /usr/share/icons/lliurex-neu/scalable/apps/zero-center.svg 'Zero-Installer' '$1 cannot been installed in your system because the archive has the extension $EXT and Jclic needs ZIP or GZ extension'" $USER > /dev/null 2>&1 return else SALIR="1" EXITO="0" fi case $EXT in "zip") (unzip /tmp/$1 -d "$2" >> $LOG_UN ; if [ "$?" != 0 ] ; then EXITO="1"; else EXITO="0"; fi ; chmod -R 755 $2 ; rm $LOG_UN ) & #Mientras que el fichero de ayuda existe es que estamos descomprimiendo #Cuando ya no exista saldremos del while while [ -f $LOG_UN ]; do echo "The file is a ZIP.....uncompresing" #En la variable PERCENT almacenamos el tanto por cien que llevamos de descarga #accediento a la ultima linea escrita en el fichero de ayuda y seleccionando solo el dato que necesitamos. VAR=$( tail -1 $LOG_UN 2>/dev/null ) #Hacemos echo de los datos que necesita el zenity echo "#Installing $1.......$VAR" | cut -c1-85 #por ultimo entubamos la salida al zenity progress para que nos muestre el resultado en pantalla done | zenity --progress --auto-close --pulsate --width 500 --title="Zero-jClic-Biblio-Installer" --no-cancel > /dev/null 2>&1 ;; "gz") (tar -xvf /tmp/$1 -C $2 >> $LOG_UN ; if [ "$?" != 0 ] ; then EXITO="1"; else EXITO="0"; fi ; chmod -R 755 $2 ; rm $LOG_UN ) & #Mientras que el fichero de ayuda existe es que estamos descomprimiendo #Cuando ya no exista saldremos del while echo "The file is a TAR.....uncompresing" while [ -f $LOG_UN ]; do #En la variable PERCENT almacenamos el tanto por cien que llevamos de descarga #accediento a la ultima linea escrita en el fichero de ayuda y seleccionando solo el dato que necesitamos. VAR=$( tail -1 $LOG_UN 2>/dev/null ) #Hacemos echo de los datos que necesita el zenity echo "#Installing $1.......$VAR" | cut -c1-85 #por ultimo entubamos la salida al zenity progress para que nos muestre el resultado en pantalla done | zenity --progress --auto-close --pulsate --width 500 --title="Zero-jClic-Biblio-Installer" --no-cancel > /dev/null 2>&1 ;; esac } function main { #ARGUMENTOS NECESARIOS #Arg1: Instalar o desinstalar el paquete, install or remove #Arg2: Paquete a instalar, elteumestre, murcia,ratoli #Arg3: Path donde se instalara, segun sea server o desktop #DEFINO LOS CASOS A INSTALAR/REMOVE SEGUN SE SELECCIONEN case "$2" in "elteumestre") #inicializo variables PATH_TO_JCLIC_PROJECTS=$3 PATH_INSTALLED="$(find $3 -maxdepth 1 -mindepth 1 -xtype d -name '*mestre*')" #Creo la URL para la descarga URL="$IMAGENES_EL_TEU$PACK_EL_TEU" PACK_SELECT="$elteumestre" if [ "$1" = "install" ]; then if [ ! -d "$PATH_INSTALLED" ]; then echo "" echo "" echo "Select to install $PACK_SELECT in $3$PATH_INSTALLED" echo "--------------------------------------------------------------" #Compruebo si la URL es operativa if wget --spider -o $LOG "$URL"; then echo "URL $URL exists, download it......." rm $LOG > /dev/null 2>&1 #Obtengo el nombre del fichero a descargar NAME=$(echo $URL | rev | cut -d "/" -f1 | rev) if [ -f /tmp/$NAME ]; then #El fichero fue descargado anteriormente, lo borrro, para descargarlo de nuevo. echo "Delete /tmp/$NAME because it was downloaded before" rm /tmp/$NAME* fi #Creo la variable aux que tiene la instruccion de descarga y la descargo como usuario de la maquina. aux="zero-lliurex-axel $URL /tmp" su $USER -c "$aux" # testeo si lo descargado esta bien test_file "$URL" "$NAME" #Instalo la libreria descargada si todo fue bien anteriormente. if [ "$TEST" = "1" ]; then echo "Install NAME: $NAME in PATH_TO_JCLIC_PROJECTS: $PATH_TO_JCLIC_PROJECTS" install_jclic $NAME $PATH_TO_JCLIC_PROJECTS if [ "$SALIR" = "0" ]; then #salgo de la funcion ya que fallo la extension del fichero, no era la esperada echo "Error in the extension fo the file downloaded" else #La extension del fichero era la correcta if [ "$EXITO" = "0" ]; then #Todo fue bien #Borro la libreria descargada una vez instalada rm /tmp/$NAME* echo "Congratulations!!!!" echo "$PACK_SELECT has been installed in your system the library in $PATH_TO_JCLIC_PROJECTS" echo "Now you can enjoy it." echo "" su -c "notify-send -t 3000 -u critical -i /usr/share/icons/lliurex-neu/scalable/apps/zero-center.svg 'Zero-Installer' '$PACK_SELECT has been installed in your system the library in $PATH_TO_JCLIC_PROJECTS'" $USER zenity --info --title="Zero-jClic-Biblio-Installer" --text="$PACK_SELECT has been installed in your system the library in $PATH_TO_JCLIC_PROJECTS" > /dev/null 2>&1 & else #fallo al descomprimir la biblioteca su -c "notify-send -t 3000 -u critical -i /usr/share/icons/lliurex-neu/scalable/apps/zero-center.svg 'Zero-Installer' '$PACK_SELECT cannot be installed in your system, because the uncompressing fail. Please download it again and if the error persist contact with Lliurex Team'" $USER zenity --info --title="Zero-jClic-Biblio-Installer" --text="$PACK_SELECT cannot be installed in your system, because the uncompressing fail. Please download it again and if the error persist contact with Lliurex Team" > /dev/null 2>&1 & fi fi fi else #La URL no es accesible, salida. echo "You select install $PACK_SELECT," echo "it needs this URL $URL and it is not accesible." echo "Please contact with Lliurex-Team" zenity --info --title="Zero-jClic-Biblio-Installer" --text="You select install $PACK_SELECT, sorry but your URL $URL is not accesible, contact with Lliurex-Team and send this file $LOG" > /dev/null 2>&1 & fi fi fi if [ "$1" = "remove" ]; then if [ -d "$PATH_INSTALLED" ]; then echo "" echo "" echo "Select to remove $PACK_SELECT" echo "--------------------------------------------------------------" echo "$PACK_SELECT has been removed from your system in $PATH_INSTALLED succesfully" rm -R "$PATH_INSTALLED" | zenity --progress --auto-close --pulsate --width 500 --title="Zero-jClic-Biblio-Installer" --text="Removing $PACK_SELECT, please wait........." --no-cancel > /dev/null 2>&1 su -c "notify-send -t 3000 -u critical -i /usr/share/icons/lliurex-neu/scalable/apps/zero-center.svg 'Zero-Installer' '$PACK_SELECT has been removed from your system succesfully'" $USER zenity --info --title="Zero-jClic-Biblio-Installer" --text="$PACK_SELECT has been removed from your system succesfully" > /dev/null 2>&1 & fi fi ;; # "murcia") # # #inicializo variables # PATH_TO_JCLIC_PROJECTS=$3 # PATH_INSTALLED="$(find $3 -maxdepth 1 -mindepth 1 -xtype d -name '*urcia*')" # #Creo la URL para la descarga # URL="$IMAGENES_MURCIA$PACK_MURCIA" # PACK_SELECT="$murcia" # # if [ "$1" = "install" ]; then # if [ ! -d "$PATH_INSTALLED" ]; then # echo "" # echo "" # echo "Select to install $PACK_SELECT in $3$PATH_INSTALLED" # echo "--------------------------------------------------------------" #Compruebo si la URL es operativa # if wget --spider -o $LOG "$URL"; then # # echo "URL $URL exists, download it......." # rm $LOG > /dev/null 2>&1 # #Obtengo el nombre del fichero a descargar # NAME=$(echo $URL | rev | cut -d "/" -f1 | rev) # if [ -f /tmp/$NAME ]; then # #El fichero fue descargado anteriormente, lo borrro, para descargarlo de nuevo. # echo "Delete /tmp/$NAME because it was downloaded before" # rm /tmp/$NAME* # fi #Creo la variable aux que tiene la instruccion de descarga y la descargo como usuario de la maquina. # aux="zero-lliurex-axel $URL /tmp" # su $USER -c "$aux" # testeo si lo descargado esta bien # test_file "$URL" "$NAME" # #Instalo la libreria descargada si todo fue bien anteriormente. # if [ "$TEST" = "1" ]; then # echo "Install NAME: $NAME in PATH_TO_JCLIC_PROJECTS: $PATH_TO_JCLIC_PROJECTS" # install_jclic $NAME $PATH_TO_JCLIC_PROJECTS # # if [ "$SALIR" = "0" ]; then #salgo de la funcion ya que fallo la extension del fichero, no era la esperada # echo "" # else # #La extension del fichero era la correcta # if [ "$EXITO" = "0" ]; then # #Todo fue bien # #Borro la libreria descargada una vez instalada # rm /tmp/$NAME* # #CAMBIO EL NOMBRE AL DIRECTORIO LOS ESPACIOS NO SE LLEVAN BIEN EN EL JCLIC # PATH_INSTALLED="$(/usr/bin/find $3 -maxdepth 1 -mindepth 1 -xtype d -name '*urcia*')" # echo "_________________________________________________" # echo "" # echo "Estaba instalado en $PATH_INSTALLED y se movera a $PATH_TO_JCLIC_PROJECTS/Murcia" # mv "$PATH_INSTALLED" "$PATH_TO_JCLIC_PROJECTS/Murcia" # echo "_________________________________________________" # echo # echo "Congratulations!!!!" # echo "$PACK_SELECT has been installed in your system the library in $PATH_TO_JCLIC_PROJECTS" # echo "Now you can enjoy it." # echo "" # su -c "notify-send -t 3000 -u critical -i /usr/share/icons/lliurex-neu/scalable/apps/zero-center.svg 'Zero-Installer' '$PACK_SELECT has been installed in your system the library in $PATH_TO_JCLIC_PROJECTS'" $USER # zenity --info --title="Zero-jClic-Biblio-Installer" --text="$PACK_SELECT has been installed in your system the library in $PATH_TO_JCLIC_PROJECTS" > /dev/null 2>&1 & # else # #fallo al descomprimir la biblioteca # su -c "notify-send -t 3000 -u critical -i /usr/share/icons/lliurex-neu/scalable/apps/zero-center.svg 'Zero-Installer' '$PACK_SELECT cannot be installed in your system, because the uncompressing fail. Please download it again and if the error persist contact with Lliurex Team'" $USER # zenity --info --title="Zero-jClic-Biblio-Installer" --text="$PACK_SELECT cannot be installed in your system, because the uncompressing fail. Please download it again and if the error persist contact with Lliurex Team" > /dev/null 2>&1 & # fi # fi # fi # # else # #La URL no es accesible, salida. # echo "You select install $PACK_SELECT," # echo "it needs this URL $URL and it is not accesible." # echo "Please contact with Lliurex-Team" # zenity --info --title="Zero-jClic-Biblio-Installer" --text="You select install $PACK_SELECT, sorry but your URL $URL is not accesible, contact with Lliurex-Team and send this file $LOG" > /dev/null 2>&1 & # fi # fi # fi # if [ "$1" = "remove" ]; then # # if [ -d "$PATH_INSTALLED" ]; then # echo "" # echo "" # echo "Select to remove $PACK_SELECT" # echo "--------------------------------------------------------------" # echo "$PACK_SELECT has been removed from your system in $PATH_INSTALLED succesfully" # rm -R "$PATH_INSTALLED" | zenity --progress --auto-close --pulsate --width 500 --title="Zero-jClic-Biblio-Installer" --text="Removing $PACK_SELECT, please wait........." --no-cancel > /dev/null 2>&1 # su -c "notify-send -t 3000 -u critical -i /usr/share/icons/lliurex-neu/scalable/apps/zero-center.svg 'Zero-Installer' '$PACK_SELECT has been removed from your system succesfully'" $USER # zenity --info --title="Zero-jClic-Biblio-Installer" --text="$PACK_SELECT has been removed from your system succesfully" > /dev/null 2>&1 & # fi # fi # # ;; # "ratoli") # # #inicializo variables para el caso del borrado # PATH_TO_JCLIC_PROJECTS=$3 # PATH_INSTALLED="$(find $3 -maxdepth 1 -mindepth 1 -xtype d -name 'ratoli')" # #Creo la URL para la descarga # URL="$IMAGENES_RATOLI$PACK_RATOLI" # PACK_SELECT="$ratoli" # if [ "$1" = "install" ]; then # if [ ! -d "$PATH_INSTALLED" ]; then # echo "" # echo "" # echo "Select to install $PACK_SELECT in $3$PATH_INSTALLED" # echo "--------------------------------------------------------------" # # # #Compruebo si la URL es operativa # if wget --spider -o $LOG "$URL"; then # # echo "URL $URL exists, download it......." # rm $LOG > /dev/null 2>&1 # #Obtengo el nombre del fichero a descargar # NAME=$(echo $URL | rev | cut -d "/" -f1 | rev) # if [ -f /tmp/$NAME ]; then # #El fichero fue descargado anteriormente, lo borrro, para descargarlo de nuevo. # echo "Delete /tmp/$NAME because it was downloaded before" # rm /tmp/$NAME* # fi # # #Creo la variable aux que tiene la instruccion de descarga y la descargo como usuario de la maquina. # aux="zero-lliurex-axel $URL /tmp" # su $USER -c "$aux" # # # testeo si lo descargado esta bien ## test_file "$URL" "$NAME" # # #Instalo la libreria descargada si todo fue bien anteriormente. # if [ "$TEST" = "1" ]; then # echo "Install NAME: $NAME in PATH_TO_JCLIC_PROJECTS: $PATH_TO_JCLIC_PROJECTS" # #install_jclic $NAME $PATH_TO_JCLIC_PROJECTS # mkdir /tmp/ratoli # install_jclic $NAME /tmp/ratoli # # if [ "$SALIR" = "0" ]; then # #salgo de la funcion ya que fallo la extension del fichero, no era la esperada # echo "" # else # #La extension del fichero era la correcta # if [ "$EXITO" = "0" ]; then # #Todo fue bien muevo la libreria a su sitio # ( mv /tmp/ratoli/jclic /tmp/ratoli/ratoli ; mv /tmp/ratoli/ratoli $NAME $PATH_TO_JCLIC_PROJECTS ) | zenity --progress --auto-close --pulsate --width 500 --title="Zero-jClic-Biblio-Installer" --text="Moving files, wait please......." --no-cancel > /dev/null 2>&1 # # #Borro la libreria descargada una vez instalada # rm /tmp/$NAME* # echo "Congratulations!!!!" # echo "$PACK_SELECT has been installed in your system the library in $PATH_TO_JCLIC_PROJECTS" # echo "Now you can enjoy it." # echo "" # su -c "notify-send -t 3000 -u critical -i /usr/share/icons/lliurex-neu/scalable/apps/zero-center.svg 'Zero-Installer' '$PACK_SELECT has been installed in your system the library in $PATH_TO_JCLIC_PROJECTS'" $USER # zenity --info --title="Zero-jClic-Biblio-Installer" --text="$PACK_SELECT has been installed in your system the library in $PATH_TO_JCLIC_PROJECTS" > /dev/null 2>&1 & # else # #fallo al descomprimir la biblioteca # su -c "notify-send -t 3000 -u critical -i /usr/share/icons/lliurex-neu/scalable/apps/zero-center.svg 'Zero-Installer' '$PACK_SELECT cannot be installed in your system, because the uncompressing fail. Please download it again and if the error persist contact with Lliurex Team'" $USER # zenity --info --title="Zero-jClic-Biblio-Installer" --text="$PACK_SELECT cannot be installed in your system, because the uncompressing fail. Please download it again and if the error persist contact with Lliurex Team" > /dev/null 2>&1 & # fi # fi # fi # # else # #La URL no es accesible, salida. # echo "You select install $PACK_SELECT," # echo "it needs this URL $URL and it is not accesible." # echo "Please contact with Lliurex-Team" # zenity --info --title="Zero-jClic-Biblio-Installer" --text="You select install $PACK_SELECT, sorry but your URL $URL is not accesible, contact with Lliurex-Team and send this file $LOG" > /dev/null 2>&1 & # fi # fi # fi # if [ "$1" = "remove" ]; then # # if [ -d "$PATH_INSTALLED" ]; then # echo "" # echo "" # echo "Select to remove $PACK_SELECT" # echo "--------------------------------------------------------------" # echo "$PACK_SELECT has been removed from your system in $PATH_INSTALLED succesfully" # rm -R "$PATH_INSTALLED" | zenity --progress --auto-close --pulsate --width 500 --title="Zero-jClic-Biblio-Installer" --text="Removing $PACK_SELECT, please wait........." --no-cancel > /dev/null 2>&1 # su -c "notify-send -t 3000 -u critical -i /usr/share/icons/lliurex-neu/scalable/apps/zero-center.svg 'Zero-Installer' '$PACK_SELECT has been removed from your system succesfully'" $USER # zenity --info --title="Zero-jClic-Biblio-Installer" --text="$PACK_SELECT has been removed from your system succesfully" > /dev/null 2>&1 & # fi # fi # # ;; esac } #########################MAIN PROGRAM ############################## #zero-center add-pulsating-color zero-lliurex-jclic-biblio-installer #$1 install ::: remove :::: Argument to install or remove this biblio jclic #$2 elteumestre ::: murcia :::: ratoli ::: Argument to jclic name #$3 path_jclic main $1 $2 $3 #zero-center remove-pulsating-color zero-lliurex-jclic-biblio-installer exit 0