diff options
Diffstat (limited to 'repoman/bin')
-rwxr-xr-x | repoman/bin/deleteimage | 4 | ||||
-rwxr-xr-x | repoman/bin/importimage | 28 | ||||
-rwxr-xr-x | repoman/bin/sendFileMcast | 25 | ||||
-rwxr-xr-x | repoman/bin/torrent-creator | 6 |
4 files changed, 35 insertions, 28 deletions
diff --git a/repoman/bin/deleteimage b/repoman/bin/deleteimage index 2da477e4..a683d541 100755 --- a/repoman/bin/deleteimage +++ b/repoman/bin/deleteimage @@ -15,7 +15,7 @@ #@version 1.0.6 - Detección automática del tipo de imagen. #@date 2014-10-29 #@author Ramón Gómez, ETSII Univ. Sevilla -#@version 1.1.0 - Aunque no exista imagen permite recuperar la copia. +#@version 1.1.0 - Aunque no exista imagen permite recuperar la copia. #@date 2016-10-14 #@author Irina Gómez, ETSII Univ. Sevilla #*/ ## @@ -60,7 +60,7 @@ for IMG in "$OGIMG/$1.$IMGEXT" "$OGIMG/$1.$IMGEXT.$DIFFEXT" "$OGIMG/$1"; do if [ -r $IMG ] ; then IMGPATH=$IMG echo "Borrando imagen $IMGPATH" - rm -f $IMGPATH{,.sum,.full.sum,.torrent} + rm -fr $IMGPATH{,.sum,.full.sum,.torrent} break fi # Compruebo si existe copia de seguridad diff --git a/repoman/bin/importimage b/repoman/bin/importimage index 3a5a7bf3..63bcf865 100755 --- a/repoman/bin/importimage +++ b/repoman/bin/importimage @@ -9,7 +9,7 @@ #@warning Program will request the repository REST token. #@version 1.1.1 - Initial version #@author Ramón M. Gómez, ETSII Universidad de Sevilla -#@date 2017-10-08 +#@date 2018-10-08 #*/ @@ -17,11 +17,14 @@ PROG="$(basename "$0")" OPENGNSYS="/opt/opengnsys" REPODIR="$OPENGNSYS/images" +REPOCONF="$OPENGNSYS/etc/ogAdmRepo.cfg" SERVERCONF="$OPENGNSYS/etc/ogAdmServer.cfg" DEFAULTFILE="/etc/default/opengnsys" MYCNF=$(mktemp /tmp/.my.cnf.XXXXX) let BACKUP=0 source $DEFAULTFILE +source $REPOCONF &>/dev/null +[ "$RUN_OGADMSERVER" == "yes" ] && source $SERVERCONF &>/dev/null # Functions. source $OPENGNSYS/lib/ogfunctions.sh @@ -32,14 +35,14 @@ source $OPENGNSYS/lib/ogfunctions.sh # Error control. [ "$USER" == "root" ] || raiseError access "Need to be root." [ "$RUN_OGADMREPO" == "yes" ] || raiseError access "This server is not defined as image repository." -[ -w $REPODIR ] || raiseError access "Cannot write in local repository." +[ -w "$REPODIR" ] || raiseError access "Cannot write in local repository." +[ -n "$IPlocal" ] || raiseError access "Cannot read repository configuration file." case $# in 2) USERNAME="$SUDO_USER"; REPO="$1"; IMAGE="$2" ;; 3) USERNAME="$1"; REPO="$2"; IMAGE="$3" ;; *) [ "$*" == "help" ] && help || raiseError usage esac -source $SERVERCONF &>/dev/null -[ "${REPO,,}" == "${HOSTNAME,,}" ] || [ "${REPO,,}" == "localhost" ] || [ "${REPO}" == "127.0.0.1" ] || [ "${REPO,,}" == "${IPlocal,,}}" ] && raiseError access "Cannot import from local repository." +[ "${REPO,,}" == "${HOSTNAME,,}" ] || [ "${REPO,,}" == "localhost" ] || [[ ${REPO} =~ ^127\. ]] || [ "${REPO,,}" == "${IPlocal,,}" ] && raiseError access "Cannot import from local repository." # Fetching image info from the repository. read -rp "Enter repository API token: " APITOKEN @@ -61,9 +64,9 @@ IMAGESIZE="$(jq -r '.size' <<< "$IMAGEINFO" 2>/dev/null)" [ -z "$IMAGESIZE" ] && raiseError access "Cannot retrieve image size" # Checking if local image exists. IMAGEPATH="$REPODIR/$IMAGENAME.$IMAGETYPE" +LOCKFILE="$IMAGEPATH.lock" if [ -e "$IMAGEPATH" ]; then # Checking if local image is locked. - LOCKFILE="$IMAGEPATH.lock" [ -f "$LOCKFILE" ] && raiseError access "Local image is locked, cannot write." # Confirm image download. read -rp "Image $IMAGENAME exists in the local repository. Do you want to continue? (y/N): " ANSWER @@ -93,10 +96,13 @@ fi scp "$USERNAME@$REPO:$IMAGEPATH" $REPODIR ERRCODE=$? if [ $ERRCODE -eq 0 ]; then + # Cheking image size. + DOWNLOADSIZE=$(stat -c "%s" "$IMAGEPATH") + [ $IMAGESIZE -ne $DOWNLOADSIZE ] && echo "Warning: image sizes differ: source=$IMAGESIZE, target=$DOWNLOADSIZE." # Storing creation info. jq -r '.clonator+":"+.compressor+":"+.filesystem+":"+(.datasize|tostring)+":"' <<<"$IMAGEINFO" > "$IMAGEPATH.info" # Updating the database when the repo is also configured as Administration Server. - if [ "$RUN_OGADMREPO" == "yes" ]; then + if [ "$RUN_OGADMSERVER" == "yes" ]; then # Creating credentials file. cat << EOT > $MYCNF [client] @@ -122,11 +128,10 @@ EOT else # Choose image OU. echo "Choose Organization Unit:" - for ((i=0; i<${#OUS[@]}; i++)); do - echo " $i: ${OUS[i]#* }" + PS3="Enter number: " + select opt in "${OUS[@]#* }"; do + [ -n "$opt" ] && let OUID="${OUS[REPLY-1]%% *}" && break done - read -rp "Enter number (0 by default): " ANSWER - let OUID="${OUS[ANSWER]%% *}" 2>/dev/null || let OUID="${OUS[0]%% *}" fi # Creating a new image associated with an empty software profile. mysql --defaults-extra-file=$MYCNF -D "$CATALOG" -e \ @@ -146,9 +151,6 @@ EOT echo "Warning: database cannot be updated." fi fi - # Cheking image size. - DOWNLOADSIZE=$(stat -c "%s" "$IMAGEPATH") - [ $IMAGESIZE -ne $DOWNLOADSIZE ] && echo "Warning: image sizes differ: source=$IMAGESIZE, target=$DOWNLOADSIZE." else # On download error, trying to recover backup. raiseError download "$USERNAME@$REPO:$IMAGEPATH" diff --git a/repoman/bin/sendFileMcast b/repoman/bin/sendFileMcast index 222a6d40..9f6479c9 100755 --- a/repoman/bin/sendFileMcast +++ b/repoman/bin/sendFileMcast @@ -4,7 +4,7 @@ #@param str_session Datos de sesión (Puerto:Duplex:IP:Mpbs:Nclientes:Timeout) -PROG=$(basename $0) +PROG=$(basename "$0") OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} OGIMG=$OPENGNSYS/images OGBIN=$OPENGNSYS/bin @@ -37,16 +37,17 @@ if [ ! -f "$FICHIMG" ]; then fi # Parámetros de sesión separado por ":". -PARAMS=$(echo $2 | \ - awk -F: '$1~/^[0-9]*$/ {print $1} - tolower($2)~/^(half)(-duplex)?$/ {print "half-duplex"} - tolower($2)~/^(full)(-duplex)?$/ {print "full-duplex"} - $3~/^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$/ {print $3} - $4~/^[0-9]*[mM]/ {print toupper($4)} - $5~/^[0-9]*/ {print $5} - $6~/^[0-9]*/ {print $6} +PARAMS=$(echo "$2" | \ + awk -F: '$1~/^[0-9]+$/ {v1=$1} + tolower($2)~/^half(-duplex)?$/ {v2="--half-duplex"} + tolower($2)~/^full(-duplex)?$/ {v2="--full-duplex"} + $3~/^[0-9]+(\.[0-9]+){3}$/ {v3=$3} + $4~/^[0-9]+[mM]$/ {v4=tolower($4)} + $5~/^[0-9]+$/ {v5=$5} + $6~/^[0-9]+$/ {v6=$6} + END {print v1,v2,v3,v4,v5,v6} ') -read -e PORTBASE METHOD ADDRESS BITRATE NCLIENTS MAXTIME <<< $PARAMS +read -re PORTBASE METHOD ADDRESS BITRATE NCLIENTS MAXTIME <<< "$PARAMS" if [ -z "$MAXTIME" ]; then echo "$PROG Error: Datos de sesión incorrectos: \"$2\"" exit 3 @@ -56,7 +57,7 @@ fi CERROR="8x8/128" # Envío de fichero por Multicast. -# Se desabilita el uso de mbuffer: eesta versión del upd-sender no la admite. +# Se desabilita el uso de mbuffer: esta versión del upd-sender no la admite. #which mbuffer &> /dev/null && MBUFFER="--pipe 'mbuffer -m 20M'" -$OGBIN/udp-sender $MBUFFER --nokbd --retries-until-drop 65 --portbase $PORTBASE --$METHOD --interface $REPO_IFACE --mcast-data-address $ADDRESS --fec $CERROR --max-bitrate $BITRATE --ttl 16 --min-clients $NCLIENTS --max-wait $MAXTIME --file "$FICHIMG" +$OGBIN/udp-sender "$MBUFFER" --nokbd --retries-until-drop 65 --portbase "$PORTBASE" "$METHOD" --interface "$REPO_IFACE" --mcast-data-address "$ADDRESS" --fec "$CERROR" --max-bitrate "$BITRATE" --ttl 16 --min-clients "$NCLIENTS" --max-wait "$MAXTIME" --file "$FICHIMG" diff --git a/repoman/bin/torrent-creator b/repoman/bin/torrent-creator index 958683ed..cfca393e 100755 --- a/repoman/bin/torrent-creator +++ b/repoman/bin/torrent-creator @@ -15,6 +15,10 @@ PATH=$PATH:$OPENGNSYS/bin OGIMG="$OPENGNSYS/images" REPOCFG="$OPENGNSYS/etc/ogAdmRepo.cfg" LOGFILE="$OPENGNSYS/log/$PROG.log" +DEFAULTFILE=/etc/default/opengnsys +source $DEFAULTFILE +# No hacer nada si no está definido como repositorio. +[ "$RUN_OGADMREPO" == "yes" ] || exit 0 # Error si no está bien configurado el repositorio de imágenes. [ -d $OGIMG -a -f $REPOCFG ] || exit 1 source $REPOCFG @@ -52,7 +56,7 @@ for IMG in *.{img,pgz,diff,dsk} */*.{img,pgz,diff,dsk} ; do # Datasum completo para transferencias torrent DATAFULLSUM=$(md5sum -b "$IMG"| cut -f1 -d" ") echo $DATAFULLSUM > "$SUMFULLFILE" - nice -8 ctorrent -t "$IMG" -u $TRACKERURL -s "$TORRENT" -c $DATAFULLSUM -l 4194304 2>/dev/null + nice -n ${BTSEEDER_PRIORITY:-0} ctorrent -t "$IMG" -u $TRACKERURL -s "$TORRENT" -c $DATAFULLSUM -l 4194304 2>/dev/null rm -f "$LOCKFILE" if [ -f "$TORRENT" ]; then echo "`date` : Fin creación de fichero $TORRENT" >> $LOGFILE |