diff options
-rwxr-xr-x | server/bin/oglivecli | 37 | ||||
-rwxr-xr-x | server/bin/setsmbpass | 32 |
2 files changed, 37 insertions, 32 deletions
diff --git a/server/bin/oglivecli b/server/bin/oglivecli index 3feb5901..8ada7f08 100755 --- a/server/bin/oglivecli +++ b/server/bin/oglivecli @@ -13,6 +13,16 @@ #*/ ## +# Global constants definition. +PROG=$(basename "$(realpath "$0")") +OPENGNSYS=/opt/opengnsys +DOWNLOADDIR=$OPENGNSYS/lib +DOWNLOADURL="http://opengnsys.es/downloads" +TFTPDIR=$OPENGNSYS/tftpboot +DEFOGLIVE="ogLive" +INFOFILE=$OPENGNSYS/etc/ogliveinfo.json + + # Auxiliar functions. # Metafunction to check if JSON result exists. @@ -247,7 +257,7 @@ function download() { OGLIVEFILE="$1" else # Show download menu. - OGLIVE=( $(wget $DOWNLOADURL -O - 2>/dev/null | grep $DEFOGLIVE.*iso) ) + OGLIVE=( $(curl --silent $DOWNLOADURL | grep "$DEFOGLIVE.*iso") ) NISOS=${#OGLIVE[@]} echo "Available downloads (+ = installed, * = full compatibility):" for i in $(seq 1 $NISOS); do @@ -260,12 +270,12 @@ function download() { done fi # Get download size. - SOURCELENGTH=$(LANG=C wget --spider $DOWNLOADURL/$OGLIVEFILE 2>&1 | awk '/Length:/ {print $2}') + SOURCELENGTH=$(curl --head --silent $DOWNLOADURL/$OGLIVEFILE | awk -F: '/Content-Length:/ {print $2}') [ -n "$SOURCELENGTH" ] || raiseError download "$OGLIVEFILE" # Download ogLive. TARGETFILE=$DOWNLOADDIR/$OGLIVEFILE trap "rm -f $TARGETFILE" 1 2 3 6 9 15 - wget $DOWNLOADURL/$OGLIVEFILE -O $TARGETFILE || raiseError download "$OGLIVEFILE" + curl $DOWNLOADURL/$OGLIVEFILE -o $TARGETFILE || raiseError download "$OGLIVEFILE" } # Install an ogLive client from a previously downloaded ISO image. @@ -279,15 +289,15 @@ function install() { [ ! -w $(dirname $INFOFILE) ] && raiseError access "Configuration directory." [ ! -w $TFTPDIR ] && raiseError access "Installation directory." [ -z "$(file -b $OGLIVEFILE | grep "ISO.*ogClient")" ] && raiseError access "File is not an ogLive ISO image." - # Working directory (ogLive-Distribution-KernelVersion-CodeRevision). + # Working directory (ogLive-Distribution-KernelVersion-Architecture-CodeRevision). OGLIVEDIST="$(echo $OGLIVEFILE|cut -f2 -d-)" OGLIVEREV="${OGLIVEFILE##*-}"; OGLIVEREV="${OGLIVEREV%.*}" OGLIVEKRNL="$(echo $OGLIVEFILE|cut -f3- -d-)"; OGLIVEKRNL="${OGLIVEKRNL%-$OGLIVEREV.*}" OGLIVEARCH="$(echo $OGLIVEFILE|awk -F- '{print $(NF-1)}')" case "$OGLIVEARCH" in - i386|amd64) + i386|amd64) # Get architecture. OGLIVEKRNL="${OGLIVEKRNL%-$OGLIVEARCH}" ;; - *) + *) # 32-bit by default. OGLIVEARCH="i386" ;; esac OGLIVEDIR="$TFTPDIR/$DEFOGLIVE-$OGLIVEDIST-${OGLIVEKRNL%%-*}-$OGLIVEARCH-$OGLIVEREV" @@ -318,9 +328,9 @@ function install() { fi # Recover or ask for a new Samba access key. if [ -n "$SAMBAPASS" ]; then - echo -ne "$SAMBAPASS\n$SAMBAPASS\n" | $OPENGNSYS/bin/setsmbpass + echo -ne "$SAMBAPASS\n$SAMBAPASS\n" | $OPENGNSYS/bin/setsmbpass "$(basename $OGLIVEDIR)" else - $OPENGNSYS/bin/setsmbpass + $OPENGNSYS/bin/setsmbpass "$(basename $OGLIVEDIR)" fi # Set permissions. find -L $OGLIVEDIR -type d -exec chmod 755 {} \; @@ -376,7 +386,7 @@ function uninstall() { if [ -n "$INDEX" ]; then jq "del(.oglive[$INDEX])" $INFOFILE | sponge $INFOFILE # Decrement default index if needed (removed < default). - [[ $INDEX < $DEFINDEX ]] && jq ".default=$[DEFINDEX-1]" $INFOFILE | sponge $INFOFILE + [[ $INDEX < $DEFINDEX ]] && jq ".default=$((DEFINDEX-1))" $INFOFILE | sponge $INFOFILE fi } @@ -442,15 +452,6 @@ local ISOFILE DIR # Main progrram. -# Global constants definition. -PROG=$(basename $(realpath "$0")) -OPENGNSYS=/opt/opengnsys -DOWNLOADDIR=$OPENGNSYS/lib -DOWNLOADURL="http://opengnsys.es/downloads" -TFTPDIR=$OPENGNSYS/tftpboot -DEFOGLIVE=ogLive -INFOFILE=$OPENGNSYS/etc/ogliveinfo.json - # Access control. [ -r $OPENGNSYS/www/controlacceso.php ] && ACCESS="web" [ "$USER" = "root" ] && ACCESS="root" diff --git a/server/bin/setsmbpass b/server/bin/setsmbpass index 30bc7603..2162b3be 100755 --- a/server/bin/setsmbpass +++ b/server/bin/setsmbpass @@ -2,7 +2,7 @@ #/** # setsmbpass -#@file setsmbpass +#@file setsmbpass [ogLive] #@brief Cambia la contraseña del usuario del cliente para acceder a los servicios Samba. #@warning Se modifica el Initrd del cliente y se cambia la clave en el servidor. #@warning No se modifica el usuario de acceso (usuario "opengnsys"). @@ -26,24 +26,28 @@ TMPDIR=/tmp/oglive$$ let CHANGES=0 # Control básico de errores. -if [ $# != 0 ]; then - echo "$PROG: Error de ejecución" >&2 - echo "Formato: $PROG" - exit 1 -fi if [ "$USER" != "root" ]; then - echo "$PROG: Error: solo ejecutable por root" >&2 - exit 1 + echo "$PROG: Error: solo ejecutable por root" >&2 + exit 1 fi +case $# in + 0) # Cambios en todos los clientes ogLive instalados. + if which oglivecli &>/dev/null; then + LIST=$(oglivecli list | awk '{print $2}') + else + LIST="ogclient" + fi ;; + 1) # Cambios en único ogLive (AVISO: puede crear inconsistencias con otros ogLive). + LIST="$1" ;; + *) # Error de formato. + echo "$PROG: Error de ejecución" >&2 + echo "Formato: $PROG ogLive" + exit 1 ;; +esac # Recuperar eco de consola si se corta el proceso. trap "stty echo 2>/dev/null" KILL # Buscar todos los clients ogLive instalados. -if which oglivecli &>/dev/null; then - LIST=$(oglivecli list | awk '{print $2}') -else - LIST="ogclient" -fi for OGLIVE in $LIST; do # Crear clave para usuario de acceso a los recursos. CLIENTINITRD="$TFTPDIR/$OGLIVE/$INITRD" @@ -96,7 +100,7 @@ for OGLIVE in $LIST; do md5sum "$CLIENTINITRD" | cut -f1 -d" " > "$CLIENTINITRD.sum" let CHANGES++ else - echo "$PROG: Aviso: no se ha modificado la clave del cliente \"$OGLIVE\"." + echo "$PROG: Cliente \"$OGLIVE\" no accesible." fi done if [[ $CHANGES != 0 ]]; then |