#!/bin/bash # # webbuild cgi script # Copyright (c) 2012 by Silvan Calarco # . /etc/sysconfig/autoport SUDO_WRAPPER="sudo /usr/libexec/webbuild-sudo" STATEDIR=/var/autodist/webbuild LOG=/var/autodist/webbuild/access_log DEFAULT_ENVIRONMENT=0 [ "`uname -m`" = "x86_64" ] && HOST_IS_X86_64=1 function set_user_state_var() { local statevar=$1 local statevalue=$2 local stateuser=$3 [ ! "$stateuser" ] && stateuser=$USER [ "$1" ] || return [ -e $STATEDIR/users/$stateuser.state ] || touch $STATEDIR/users/$stateuser.state sed -i "/^$statevar=/d" $STATEDIR/users/$stateuser.state [ "$statevalue" ] && echo "$statevar=$statevalue" >> $STATEDIR/users/$stateuser.state } function social_log() { local line=$1 [ "$1" ] || return if [ ! "$STATE_FAKEUSER" ]; then STATE_SOCIALLOG_ID=0 . $STATEDIR/users/webbuild.state STATE_SOCIALLOG_ID=`expr $STATE_SOCIALLOG_ID + 1` set_user_state_var STATE_SOCIALLOG_ID $STATE_SOCIALLOG_ID webbuild echo "SID=$STATE_SOCIALLOG_ID SPRIVACY=$STATE_PRIVACYMODE $line" >> $STATEDIR/social_log fi } function cgi_encodevar() { local string="${1}" local strlen=${#string} local encoded="" for (( pos=0 ; pos and flipflip industries # (internal) routine to store POST data function cgi_get_POST_vars() { # check content type # FIXME: not sure if we could handle uploads with this.. [ "${CONTENT_TYPE}" != "application/x-www-form-urlencoded" ] && \ echo "Warning: you should probably use MIME type "\ "application/x-www-form-urlencoded!" 1>&2 # save POST variables (only first time this is called) [ -z "$QUERY_STRING_POST" \ -a "$REQUEST_METHOD" = "POST" -a ! -z "$CONTENT_LENGTH" ] && read -n $CONTENT_LENGTH QUERY_STRING_POST return } # (internal) routine to decode urlencoded strings function cgi_decodevar() { [ $# -ne 1 ] && return local v t h # replace all + with whitespace and append %% t="${1//+/ }%%" while [ ${#t} -gt 0 -a "${t}" != "%" ]; do v="${v}${t%%\%*}" # digest up to the first % t="${t#*%}" # remove digested part # decode if there is anything to decode and if not at end of string if [ ${#t} -gt 0 -a "${t}" != "%" ]; then h=${t:0:2} # save first two chars t="${t:2}" # remove these if [ "${h}" = "22" ]; then v="${v}\\\"" elif [ "${h}" = "0A" ]; then v="${v}\\\n" elif [ "${h}" = "24" ]; then v="${v}\\\$" elif [ "${h}" = "60" ]; then v="${v}\\\`" else v="${v}"`echo -e \\\\x${h}` # convert hex to special char fi fi done # return decoded string echo "${v}" return } # routine to get variables from http requests # usage: cgi_getvars method varname1 [.. varnameN] # method is either GET or POST or BOTH # the magic varible name ALL gets everything function cgi_getvars() { [ $# -lt 2 ] && return local q p k v s # get query case $1 in GET) [ ! -z "${QUERY_STRING}" ] && q="${QUERY_STRING}&" ;; POST) cgi_get_POST_vars [ ! -z "${QUERY_STRING_POST}" ] && q="${QUERY_STRING_POST}&" ;; BOTH) [ ! -z "${QUERY_STRING}" ] && q="${QUERY_STRING}&" cgi_get_POST_vars [ ! -z "${QUERY_STRING_POST}" ] && q="${q}${QUERY_STRING_POST}&" ;; esac shift s=" $* " # parse the query data while [ ! -z "$q" ]; do p=`echo $q | sed "s|&.*||"` q=`echo $q | sed "s|[^&]*&||"` k="${p%%=*}" # get the key (variable name) from it v="${p#*=}" # get the value from it # decode and evaluate var if requested if [ "$k" != "SPECTEXT" ]; then v=`cgi_decodevar "$v"` fi eval "$k=\"$v\"" done return } # register all GET and POST variables cgi_getvars BOTH ALL #[ "$PACKAGE" ] && PACKAGEENCODED=`cgi_encodevar "$PACKAGE"` || PACKAGEENCODED= [ "$PACKAGE" ] && PACKAGEENCODED=`cgi_encodevar "$PACKAGE"` || PACKAGEENCODED= #cgi_getvars POST if [ "$REQUEST" != "refresh" ]; then # echo "`date` - $QUERY_STRING_POST" >> $LOG echo "`date` - USER=$USER&REQUEST=$REQUEST&ENVIRONMENT=$ENVIRONMENT&REPOSITORY=$REPOSITORY&PACKAGE=$PACKAGE&MAINTAINERMODE=$MAINTAINERMODE" >> $LOG fi [ "$HOST" ] || HOST=0 [ "$AS_HOST" ] || AS_HOST=0 [ "$AS_HOST" -a "$HOST" != "0" ] && HOST_ADD="&HOST=$HOST" if [ "$AS_HOST" = "0" ]; then echo -e "Content-type: text/xml\nPragma: no-cache\n" echo -n "" else echo -e "Content-type: text/html; charset=UTF-8\n" fi # SECURITY USER_ENABLED= USER_ADMIN= USER_CANIMPORT= USER=${USER/.*\/} if [ "$SECRET" -a "$USER" ]; then if [ -r "$STATEDIR/users/$USER.conf" ]; then . $STATEDIR/users/$USER.conf fi if [ "$USER_ENABLED" ]; then USER_ENABLED= if [ "$SECRET" = "$USER_SECRET" ]; then USER_ENABLED=1 elif [ ! "$SECRET" ]; then USER_ENABLED= elif [ "$USER_SECRET" ]; then echo -n " " echo -n " " echo -n " " echo -n " " echo -n " " echo -n " " echo -n " " echo -n "Unauthorized! If this happened after you changed your password in openmamba website please ask the maintainer to be re-enabled to use this service. Thank you." echo -n "" echo -n " " echo -n "" exit elif [ "$REQUEST" = "password" ]; then /usr/libexec/webbuild-checkpassword "$PASSWORD" "$SECRET" 2>/dev/null if [ $? -eq 0 ]; then tmpfile=`mktemp` cat $STATEDIR/users/$USER.conf > $tmpfile echo "USER_SECRET='$SECRET'" >> $tmpfile USER_ENABLED=1 $SUDO_WRAPPER local "" "mv $tmpfile $STATEDIR/users/$USER.conf" else USER_ENABLED= fi else # no "$USER_SECRET" set; require password echo -n "" echo -n " " echo -n "]]>" echo -n " " echo -n " " echo -n " " echo -n " " echo -n " " echo -n " " echo -n " " echo -n " " echo -n "" exit fi fi fi if [ "$USER_ENABLED" != "1" ]; then echo -n " " echo -n " " echo -n " " echo -n " " echo -n " " echo -n " " echo -n " " if [ "$USER" -a "$SECRET" ]; then if [ "$REQUEST" = "enablerequest" ]; then echo "`date` - USER=$USER USER_EMAIL=$USER_EMAIL REQUEST=$REQUEST SECRET=$SECRET" >> $STATEDIR/requests_log echo -n "Your request has been submitted. Please wait for approval and retry later." elif [ "$REQUEST" = "password" ]; then echo -n "Invalid password. Please reload and retry or ask the maintainer in case of problems." elif [ "`grep \" USER=$USER \" $STATEDIR/requests_log`" ]; then echo -n "Your request is pending for approval. Please try again later or ask the maintainer in case of problems." else echo -n "" echo -n "]]>" fi # else # echo -n "Unauthorized!" fi echo -n " " # echo -n "" # exit fi if [ -e $STATEDIR/webbuild.state ]; then . $STATEDIR/users/webbuild.state else touch $STATEDIR/users/webbuild.state fi if [ "$USER_ADMIN" -a "$FAKEUSERSWITCH" != "" ]; then if [ "$FAKEUSERSWITCH" = "_disabled_" ]; then set_user_state_var STATE_FAKEUSER FAKEUSER= else set_user_state_var STATE_FAKEUSER $FAKEUSERSWITCH fi fi if [ "$USER" -a "$USER_ENABLED" ]; then # set user state changes if [ "$ADVANCEDCONTROLSSWITCH" != "" ]; then if [ "$ADVANCEDCONTROLSSWITCH" = "true" ]; then set_user_state_var STATE_ADVANCEDCONTROLS 1 else set_user_state_var STATE_ADVANCEDCONTROLS fi fi if [ "$PRIVACYMODESWITCH" != "" ]; then if [ "$PRIVACYMODESWITCH" = "true" ]; then set_user_state_var STATE_PRIVACYMODE 1 else set_user_state_var STATE_PRIVACYMODE fi fi # read user state file [ -e $STATEDIR/users/$USER.state ] && . $STATEDIR/users/$USER.state if [ "$USER_ADMIN" -a "$STATE_FAKEUSER" != "" ]; then USER=$STATE_FAKEUSER USER_ENABLED= USER_ADMIN= USER_CANIMPORT= USER_CANINSTALL= USER_ALLENVIRONMENTS= USER_ALLREPOSITORIES= [ -e $STATEDIR/users/$USER.conf ] && . $STATEDIR/users/$USER.conf STATE_ADVANCEDCONTROLS= [ -e $STATEDIR/users/$USER.state ] && . $STATEDIR/users/$USER.state fi fi # social box if [ "$REQUEST" = "refresh" -o ! "$USER" ]; then echo -n "
" count=0 [ -e "$STATEDIR/social_log" ] && tail -n 100 $STATEDIR/social_log | tac | while read line; do STYPE= SPRIVACY= SUSER= eval $line [ "$SUSER" = "$USER" -a "$STYPE" != "broadcastmessage" ] && continue if [ "$SPRIVACY" -a ! "$USER" ]; then USER_GRAVATAR= else USER_GRAVATAR=`echo -n $SEMAIL | md5sum | sed "s| .*||"` fi echo -n "
" echo -n "
" DATENOW=`date +%s` DAYSAGO=`expr \( $DATENOW - $STIME \) / 86400` HOURAGO=`expr \( $DATENOW - $STIME \) / 3600 % 24` MINAGO=`expr \( $DATENOW - $STIME \) / 60 % 60` SECAGO=`expr \( $DATENOW - $STIME \) % 60` TIMEAGO="${SECAGO}s" if [ $DAYSAGO -gt 1 ]; then TIMEAGO="$DAYSAGO days" elif [ $DAYSAGO -eq 1 ]; then TIMEAGO="1 day ${HOURAGO} hours" elif [ $HOURAGO -gt 1 ]; then TIMEAGO="${HOURAGO} hours" elif [ $HOURAGO -eq 1 ]; then TIMEAGO="1 hour ${MINAGO} min" elif [ $MINAGO -gt 1 ]; then TIMEAGO="${MINAGO} minutes" elif [ $MINAGO -eq 1 ]; then TIMEAGO="1 min ${SECAGO} seconds" else TIMEAGO="${SECAGO} seconds" fi if [ "$SPRIVACY" -a ! "$USER" ]; then SUSER="A developer" fi echo -n "
$SUSER $STEXT (${TIMEAGO} ago)

" count=`expr $count + 1` [ $count -ge 10 ] && break echo -n "

" done echo -n "
" echo -n "]]>
" if [ ! "$USER_ENABLED" -o "$REQUEST" = "refresh" ]; then echo "" exit fi fi # ENVIRONMENT select echo -n "" fi if [ "$USER_ADMIN" -o "$STATE_FAKEUSER" ]; then echo -n " Test user: " echo -n " | " fi # new session button echo -n "" # expert mode checkbox [ "$STATE_ADVANCEDCONTROLS" ] && CHECKED="checked=checked" || CHECKED= echo -n " Expert:" # privacy mode checkbox [ "$STATE_PRIVACYMODE" ] && CHECKED="checked=checked" || CHECKED= echo -n " Privacy:" echo -n "" if [ "$MAINTAINERMODE" != "true" ]; then # [ "$USER_CANIMPORT" -o "$STATE_FAKEUSER" -o "$USER_ADMIN" ] && echo -n "
" echo -n "
Build environment:" fi echo -n "]]>
" if [ ! "$ENVIRONMENT" ]; then ENVIRONMENT=$DEFAULT_ENVIRONMENT fi if [ "${AUTOPORT_CHROOT[$ENVIRONMENT]}" ]; then WORKINGROOT="/var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}/" WORKINGHOME="/var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}/usr/src/" BUILDLOGDIR="/var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}/home/${AUTOPORT_CHROOT_USER[$ENVIRONMENT]}/.autodist/log/" AUTOPORTLOGDIR="/var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}/home/${AUTOPORT_CHROOT_USER[$ENVIRONMENT]}/.autoport/${AUTOPORT_ARCH[$ENVIRONMENT]}/" elif [ "${AUTOPORT_NATIVE[$ENVIRONMENT]}" ]; then WORKINGROOT="/" WORKINGHOME=`getent passwd ${AUTOPORT_CHROOT_USER[$ENVIRONMENT]} | cut -d: -f6` BUILDLOGDIR="/home/${AUTOPORT_CHROOT_USER[$ENVIRONMENT]}/.autodist/log/" AUTOPORTLOGDIR="/home/${AUTOPORT_CHROOT_USER[$ENVIRONMENT]}/.autoport/${AUTOPORT_ARCH[$ENVIRONMENT]}/" else WORKINGROOT="/" WORKINGHOME="/var/autodist/" BUILDLOGDIR="/var/autodist/log/" AUTOPORTLOGDIR="/var/autodist/.autoport/${AUTOPORT_ARCH[$ENVIRONMENT]}/" fi if [ "$HOST_IS_X86_64" -a "${AUTOPORT_ARCH[$ENVIRONMENT]}" != "x86_64" ]; then SUDO_WRAPPER="linux32 $SUDO_WRAPPER" fi [ "$PACKAGE" -a ! "$REQUEST" ] && REQUEST=edit # SPECFILES select if [ "$ENVIRONMENT" -a "$MAINTAINERMODE" != "true" ]; then echo -n "" echo -n "" for f in `$SUDO_WRAPPER $ENVIRONMENT "" "ls *.spec"`; do specname=${f/.*} [ "$PACKAGE" = "$specname" ] && SELECTED="selected=\"selected\"" || SELECTED= echo -n "" done echo -n "]]>" elif [ "$MAINTAINERMODE" = "true" ]; then echo -n " " fi # clean output when changing environment if [ ! "$REPOSITORY" -a ! "$PACKAGE" -a ! "$REQUEST" = "repsearch" ]; then echo -n " " # echo -n "]]>" echo -n "]]>" fi # REPOSITORIES search if [ ! "$REPSEARCHTEXT" ]; then echo -n "" if [ "$PACKAGE" ]; then echo -n "" else echo -n "" fi echo -n "]]>" fi if [ ! "${AUTOPORT_UPDATE[$ENVIRONMENT]}" -o "$MAINTAINERMODE" = "true" ]; then # REPOSITORIES select if [ ! "$REPOSITORY" -o "$REQUEST" = "changeenvironment" ]; then echo -n "" echo -n "" for f in `$SUDO_WRAPPER local "" "/usr/sbin/openmamba-repository list"`; do repname=`basename $f` echo -n "" done echo -n "" echo -n "]]>" echo -n " " echo -n " " fi # PACKAGES (SRPM) select if [ "$REPOSITORY" -a "$REQUEST" = "changerepository" ]; then echo -n "" # i=getElementById('repository').selectedIndex;ajax_getvalues(\"REQUEST=changesrpm&" # echo -n "ENVIRONMENT=$ENVIRONMENT&MAINTAINERMODE=\"+getElementById('maintain').checked+\"&" # echo -n "PACKAGE=\"+encodeURIComponent(this.value)+\"&" # echo -n "REPOSITORY=\"+getElementById('repository').options[i].text);>" echo "" for f in $local_ftp/$REPOSITORY/SRPMS.base/*.src.rpm; do [ -r $f ] || continue pkgname=`basename $f` pkgname=${pkgname/.src.rpm} pkgrel=${pkgname/*-} pkgname=${pkgname/-$pkgrel} pkgver=${pkgname/*-} pkgname=${pkgname/-$pkgver} if [ "$PACKAGE" = "$pkgname" ]; then SELECTED="selected=\"selected\""; REQUEST="changesrpm" else SELECTED= fi echo -n "" done echo -n "" echo -n "]]>" echo -n "" fi echo -n "]]>" # if [ "$MAINTAINERMODE" = "true" ]; then # PACKAGE= # echo " " # fi REQUEST=changesrpm fi # SPECFILE creation if [ ! "${AUTOPORT_UPDATE[$ENVIRONMENT]}" -a "$MAINTAINERMODE" != "true" ]; then echo -n "" echo -n " name:" echo -n " type:" echo -n " version:" echo -n "" echo "]]>" elif [ "$MAINTAINERMODE" = "true" ]; then echo -n " " fi else echo -n " " fi if [ "$REQUEST" = "changespec" ]; then if [ "$PACKAGE" ]; then REQUEST="edit"; fi elif [ "$REQUEST" = "broadcastmessage" ]; then BROADCASTMESSAGE=`echo $BROADCASTMESSAGE | sed "s|<|\<|g"` social_log "SUSER=$USER STYPE=broadcastmessage SEMAIL=$USER_EMAIL STEXT=\"said:"$BROADCASTMESSAGE"\" STIME=`date +%s`" REQUEST= fi if [ "$MAINTAINERMODE" != "true" -a ! "$PACKAGE" ]; then echo " " echo " " echo " " fi if [ "$SPECTEXT" ]; then # save specfile tmpfile=`mktemp` echo -n $SPECTEXT | perl -MURI::Escape -e 'print uri_unescape(<>)' > $tmpfile chmod 644 $tmpfile $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "cat $tmpfile > $PACKAGE.spec" $tmpfile rm -f $tmpfile fi # Here requests which update the specfile, so editor is refreshed after if [ "$REQUEST" = "prepare" -o "$REQUEST" = "updatespec" -o "$REQUEST" = "speccreate" -o \ "$REQUEST" = "rebuildspec" -o "$REQUEST" = "renamespec" ]; then echo -n "" echo -n "
"
   RET=255
   case $REQUEST in
      "prepare") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autospec -u $PACKAGE -a1 --server $REPOSITORY"; RET=$? ;;
      "updatespec") if [ "$UPDATESSPECVERSION" -a "$REBUILDSPECCHANGELOG" ]; then
                       echo "ERROR: new version and changelog can't be specified together"
                    elif [ "$REBUILDSPECCHANGELOG" ]; then
                       $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autospec -u $PACKAGE -a4 --rebuild --changelog \"$REBUILDSPECCHANGELOG\""
                    elif [ "$UPDATESSPECVERSION" ]; then
                       $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autospec -u $PACKAGE -a3,4 $UPDATESPECVERSION"
                    else
                       $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autospec -u $PACKAGE -a2:4 $UPDATESPECVERSION"
                    fi
                    RET=$? ;;
      "speccreate") if [ "$SPECCREATEURL" -a "$PACKAGE" ]; then
                       AUTOSPEC_CMDLINE="-n $PACKAGE -o $PACKAGE.spec"
                       #DECODEDURL=`cgi_decodevar $SPECCREATEURL`
                       [ "$SPECCREATETYPE" ] && AUTOSPEC_CMDLINE="$AUTOSPEC_CMDLINE -t $SPECCREATETYPE"
                       [ "$SPECCREATEVERSION" ] && AUTOSPEC_CMDLINE="$AUTOSPEC_CMDLINE -v $SPECCREATEVERSION"
                       $SUDO_WRAPPER $ENVIRONMENT "" "autospec -s \"$SPECCREATEURL\" $AUTOSPEC_CMDLINE"
                       RET=$?
#                          --changelog \"package created by $USER from autodist webbuild interface\""
                    else
                       echo "ERROR: both source archive URL and name are needed."
                       RET=1
                    fi
                    ;;
      "renamespec") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "mv $RENAMESPECFROM.spec $PACKAGE.spec && sed -i \"s|\(Name:[[:space:]]*\).*|\1$PACKAGE|\" $PACKAGE.spec"
                    RET=$?
                    ;;
   esac
   echo -n "
" if [ $RET -eq 0 ]; then echo "Result: OK" else echo "Result: ERROR ($RET)" fi echo -n "" echo -n "]]>
" REQUEST="edit" fi if [ "$REPOSITORY" != "" -a "$MAINTAINERMODE" = "true" ]; then if [ ! "$REQUEST" -o "$REQUEST" = "changesrpm" ]; then echo -n " " echo -n "" echo -n "Recent packages in $REPOSITORY:
" cat $local_ftp/distromatic/$REPOSITORY/_recent.inc echo -n "
Log:
"
      cat $local_ftp/$REPOSITORY/distromatic.log
      echo -n "
" echo -n "" echo -n "]]>
" fi fi if [ "$REQUEST" = "edit" -o "$REQUEST" = "reloadspec" ]; then if [ "$PACKAGE" ]; then $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "ls $PACKAGE.spec" [ $? -eq 0 ] && SPECAVAILABLE=1 fi if [ "$MAINTAINERMODE" != "true" -a "$SPECAVAILABLE" ]; then if [ "$REQUEST" = "edit" ]; then social_log "SUSER=$USER SEMAIL=$USER_EMAIL STEXT=\"is working on $PACKAGE\" STIME=`date +%s`" fi echo -n "$PACKAGE.spec in build environment: " echo -n "new version (empty=autodetect):" echo -n "or new release changelog:" echo -n "" echo -n "]]>" echo -n "" $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "cat $PACKAGE.spec" echo -n "" echo -n "" echo -n "" echo -n "" echo -n ".spec" echo -n "]]>" fi if [ "$MAINTAINERMODE" = "true" -o "$SPECAVAILABLE" ]; then echo -n "" if [ "$MAINTAINERMODE" != "true" ]; then echo -n "Package: $PACKAGE" echo -n "
Target arch:" echo -n "" [ "${AUTOPORT_UPDATE[$ENVIRONMENT]}" -o "$STATE_ADVANCEDCONTROLS" ] && echo -n "
Autodist automatic builds:
" if [ "${AUTOPORT_UPDATE[$ENVIRONMENT]}" ]; then echo -n "Patch:" echo -n "" echo -n "" echo -n "" # autodist schedule echo -n "
Schedule:" # autodist unschedule echo -n "" # autodist skip echo -n "" fi if [ "$STATE_ADVANCEDCONTROLS" ]; then # autodist list-jobs echo -n "Job:" # autodist prepare echo -n "
" # autodist update echo -n "" # autodist build echo -n "" # autodist install [ ! "$USER_CANINSTALL" ] && DISABLED="disabled=disabled" || DISABLED= echo -n "" # autodist send [ ! "$USER_ALLREPOSITORIES" ] && DISABLED="disabled=disabled" || DISABLED= echo -n "" # autodist force checkbox fi if [ "$STATE_ADVANCEDCONTROLS" -o "${AUTOPORT_UPDATE[$ENVIRONMENT]}" ]; then # autodist logs echo -n "
Last autodist logs: " echo -n "OK " echo -n "FAILED
" echo -n "" echo -n "" echo -n "" echo -n "" echo -n "" fi echo -n "
RPM packaging commands:
" # check for updates echo -n "" # unpack echo -n "" # build echo -n "" # buildroot files echo -n "" # unpackaged files echo -n "" # build requirements echo -n "" # recreate SRPM echo -n "" # rpm checks echo -n "" echo -n "" [ ! "$USER_CANINSTALL" ] && DISABLED="disabled=disabled" echo -n "" echo -n "
Add patches:" echo -n "
" echo -n "URL:" echo -n "As: $PACKAGE-.patch" echo -n "
Repository:" echo -n "
" # send echo -n "" # recreate and send SRPM echo -n "" fi if [ "$USER_CANIMPORT" -a "$PACKAGE" ]; then if [ "$MAINTAINERMODE" = "true" ]; then echo -n "
Repository maintenance:
" echo -n "Package: $PACKAGE
" echo -n "Origin: $REPOSITORY
" echo -n "Destination: " echo -n "
" fi if [ "$MAINTAINERMODE" != "true" ]; then echo -n "" # echo -n "
" # echo -n "" else # repository compare echo -n "" # repository import echo -n "" # repository release echo -n "" # repository archive echo -n "" fi echo -n "simulate" fi if [ "$MAINTAINERMODE" != "true" ]; then if [ ! "${AUTOPORT_DISABLE[$ENVIRONMENT]}" -a ! "${AUTOPORT_UPDATE[$ENVIRONMENT]}" ]; then echo -n "
Automatic port:
" echo -n "" echo -n "" fi echo -n "
Info:
" echo -n "" echo -n "" echo -n "" echo -n "" echo -n "
" echo -n "
" fi echo -n "
Broadcast message:
" echo -n "" echo -n "" echo -n "]]>
" else echo "" echo "No pre-existing .spec file $PACKAGE.spec in current working environment. Use 'prepare' to edit." echo -n "" echo -n "]]>" fi elif [ "$REQUEST" = "showlog" ]; then echo -n "" for f in $LOGFILE1 $LOGFILE2 $LOGFILE3 $LOGFILE4; do [ -r $f ] || continue echo "`basename $f` (`stat -c %y $f`)
"
      cat $f | sed "s|<|\<|g"
      echo -n "
" done echo -n "]]>
" else if [ "$REQUEST" != "" ]; then echo -n "
"
      RET=255
   fi
   case $REQUEST in
      "showpatch") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autodist-tool makepatch $PACKAGE"; RET=$? ;;
      "removepatch") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autodist-tool makepatch $PACKAGE remove"
                     RET=$?
                     if [ $RET -eq 0 ]; then
                        social_log "SUSER=$USER SEMAIL=$USER_EMAIL STEXT=\"removed the autodist patch for $PACKAGE\" STIME=`date +%s`"
                     fi ;;
      "updatepatch") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autodist-tool makepatch $PACKAGE update"
                     RET=$?
                     if [ $RET -eq 0 ]; then
                        social_log "SUSER=$USER SEMAIL=$USER_EMAIL STEXT=\"made an autodist update patch for $PACKAGE\" STIME=`date +%s`"
                     fi ;;
      "buildpatch") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autodist-tool makepatch $PACKAGE build"
                    RET=$?
                    if [ $RET -eq 0 ]; then
                       social_log "SUSER=$USER SEMAIL=$USER_EMAIL STEXT=\"made an autodist build patch for $PACKAGE\" STIME=`date +%s`"
                    fi ;;
      "showscheduled") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autodist-tool schedule"; RET=$? ;;
      "unschedule") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autodist-tool unschedule $PACKAGE"
                    RET=$?
                    if [ $RET -eq 0 ]; then
                       social_log "SUSER=$USER SEMAIL=$USER_EMAIL STEXT=\"unscheduled autodist job $PACKAGE\" STIME=`date +%s`"
                    fi ;;
      "skip") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autodist-tool skip $PACKAGE"
              RET=$?
              if [ $RET -eq 0 ]; then
                 social_log "SUSER=$USER SEMAIL=$USER_EMAIL STEXT=\"added autodist job $PACKAGE to skipped list\" STIME=`date +%s`"
              fi ;;
      "autodistprepare") [ "$AUTODISTFORCE" = "true" ] && AUTODISTADD="--force" || AUTODISTADD=
                         $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autodist -p $AUTODISTJOB --arch $AUTODISTARCH $AUTODISTADD"
                         RET=$? ;;
      "autodistupdate") [ "$AUTODISTFORCE" = "true" ] && AUTODISTADD="--force" || AUTODISTADD=
                        $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autodist -u $AUTODISTJOB --arch $AUTODISTARCH $AUTODISTADD"
                        RET=$? ;;
      "autodistbuild") [ "$AUTODISTFORCE" = "true" ] && AUTODISTADD="--force" || AUTODISTADD=
                       $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autodist -b $AUTODISTJOB --arch $AUTODISTARCH $AUTODISTADD"
                       RET=$? ;;
      "autodistinstall") [ "$AUTODISTFORCE" = "true" ] && AUTODISTADD="--force" || AUTODISTADD=
                         $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autodist -i $AUTODISTJOB --arch $AUTODISTARCH $AUTODISTADD"
                         RET=$? ;;
      "autodistsend") [ "$AUTODISTFORCE" = "true" ] && AUTODISTADD="--force" || AUTODISTADD=
                      $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autodist -s $AUTODISTJOB --arch $AUTODISTARCH $AUTODISTADD"
                      RET=$? ;;
      "buildrootfiles") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "cd @RPMBUILDROOT@ && find @BUILDROOT@"; RET=$? ;;
      "autospecupdatescheck") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autospec -u $PACKAGE -a2"; RET=$? ;;
      "rpmprepare") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "rpmbuild -bp $PACKAGE.spec"; RET=$? ;;
      "rpmbuild") echo "`date` - RPMBUILD=$PACKAGE USER=$USER ENVIRONMENT=$ENVIRONMENT" >> $STATEDIR/buildingnow_log
                  [ "$RPMFORCE" = "true" ] && RPMFORCEADD="--force-build"
                  [ "$RPMBUILDARCH" -a "$RPMBUILDARCH" != "${AUTOPORT_ARCH[$ENVIRONMENT]}" ] && \
                     RPMARCHADD="-A $RPMBUILDARCH --define \"cross_target_cpu=$RPMBUILDARCH\""
                  $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autospec -u $PACKAGE -a5 $RPMFORCEADD $RPMARCHADD"
                  RET=$?
                  if [ $RET -eq 0 ]; then
                     social_log "SUSER=$USER SEMAIL=$USER_EMAIL STEXT=\"successfully built $PACKAGE\" STIME=`date +%s`"
                  fi
                  sed -i "|RPMBUILD=$PACKAGE USER=$USER ENVIRONMENT=$ENVIRONMENT|d" $STATEDIR/buildingnow_log
                  #kill `pstree -p 25541 | sed 's/(/\n(/g' | grep '(' | sed 's/(\(.*\)).*/\1/' | tr "\n" " "`
                  ;;
      "srpmbuild") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "rpmbuild -bs $PACKAGE.spec"
                   RET=$? ;;
      "autospeclistcheck")
                   [ "$RPMBUILDARCH" -a "$RPMBUILDARCH" != "${AUTOPORT_ARCH[$ENVIRONMENT]}" ] && \
                      RPMARCHADD="-A $RPMBUILDARCH --define \"cross_target_cpu=$RPMBUILDARCH\""
                   $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autospec -u $PACKAGE -a5 --list-check $RPMARCHADD"
                   RET=$? ;;
      "autospecbuildreq") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autospec -u $PACKAGE -a6"
                   RET=$? ;;
      "rpmchecks") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autospec -u $PACKAGE -a8"; RET=$? ;;
      "rpmsimulateinstall") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autospec -u $PACKAGE -a7"; RET=$? ;;
      "rpminstall") if [ "$USER_CANINSTALL" ]; then
                       [ "$RPMFORCE" = "true" ] && RPMFORCEADD="--force-install"
                       $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autospec -u $PACKAGE -a11 $RPMFORCEADD"; RET=$?
                    else
                       echo "Install function disabled."
                       RET=1
                    fi ;;
      "addpatch") if [ "$ADDPATCHURL" -a "$ADDPATCHNAME" ]; then
                     $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "curl -s \"$ADDPATCHURL\" -o ../SOURCES/$PACKAGE-$ADDPATCHNAME.patch"
                     RET=$?
                     [ $RET -eq 0 ] && echo "Patch added with name $PACKAGE-$ADDPATCHNAME.patch"
                  else
                     echo "Patch URL or destination name not provided."
                     RET=1
                  fi ;;
      "sendpackage") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autospec -u $PACKAGE -a10 --server $SENDREPOSITORY"
                     RET=$?
                     if [ $RET -eq 0 ]; then
                        social_log "SUSER=$USER SEMAIL=$USER_EMAIL STEXT=\"sent $PACKAGE to $SENDREPOSITORY\" STIME=`date +%s`"
                     fi ;;
      "sendsource") [ "$RPMFORCE" = "true" ] && RPMFORCEADD="--force --nodeps"
                    if [ "$SENDREPOSITORY" ]; then
                       $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "rpmbuild -bs $PACKAGE.spec $RPMFORCEADD && autospec -u $PACKAGE -a10 --server $SENDREPOSITORY --norpm"
                       RET=$?
                    else
                       echo "ERROR: send repository is not defined."
                       RET=255
                    fi ;;
      "repositoryimport")
                      [ "$REPOSITORYSIMULATE" = "true" -o ! "$USER_CANIMPORT" ] && SIMULATEADD="-s" || SIMULATEADD=
                      $SUDO_WRAPPER local $PACKAGE "openmamba-repository import $SENDREPOSITORY $PACKAGE -d $REPOSITORYIMPORTTO $SIMULATEADD -y"
                      RET=$?
                      if [ ! "$SIMULATEADD" -a $RET -eq 0 ]; then
                         social_log "SUSER=$USER SEMAIL=$USER_EMAIL STEXT=\"imported $PACKAGE from $SENDREPOSITORY to $REPOSITORYIMPORTTO\" STIME=`date +%s`"
                      fi
                      ;;
      "repositoryrelease")
                      [ "$REPOSITORYSIMULATE" = "true" -o ! "$USER_CANIMPORT" ] && SIMULATEADD="-s" || SIMULATEADD=
                      $SUDO_WRAPPER local $PACKAGE "openmamba-repository release $SENDREPOSITORY $PACKAGE -d $REPOSITORYIMPORTTO $SIMULATEADD -y"
                      RET=$?
                      if [ ! "$SIMULATEADD" -a $RET -eq 0 ]; then
                         social_log "SUSER=$USER SEMAIL=$USER_EMAIL STEXT=\"released $PACKAGE from $SENDREPOSITORY to $REPOSITORYIMPORTTO\" STIME=`date +%s`"
                      fi
                      ;;
      "repositorydiff")
                      $SUDO_WRAPPER local $PACKAGE "openmamba-repository diff $SENDREPOSITORY $PACKAGE -d $REPOSITORYIMPORTTO"
                      RET=$?
                      ;;
      "repositoryarchive")
                      [ "$REPOSITORYSIMULATE" = "true" -o ! "$USER_CANIMPORT" ] && SIMULATEADD="-s" || SIMULATEADD=
                      $SUDO_WRAPPER local $PACKAGE "openmamba-repository archive $SENDREPOSITORY $PACKAGE -y"
                      RET=$?
                      if [ ! "$SIMULATEADD" -a $RET -eq 0 ]; then
                         social_log "SUSER=$USER SEMAIL=$USER_EMAIL STEXT=\"archived $PACKAGE in $SENDREPOSITORY\" STIME=`date +%s`"
                      fi
                      ;;
      "autoportnp") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "autoport -np $PACKAGE"; RET=$? ;;
      "autoportlog") cat "$AUTOPORTLOGDIR/current.log"; RET=$? ;;
      "repsearch") $SUDO_WRAPPER local "" "openmamba-repository search -i $REPSEARCHTEXT"; RET=$? ;;
      "allowedgroups") $SUDO_WRAPPER $ENVIRONMENT "" "autospec --eval rpm_allowed_groups"; RET=$? ;;
      "approvedlicenses") $SUDO_WRAPPER $ENVIRONMENT "" "autospec --eval rpm_approved_licenses | grep -v \"^#\"" | \
                          while read line; do
                             echo $line
                          done
                          RET=0
                          ;;
      "builddirfiles") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "cd @RPMBUILDDIR@ && find @BUILDDIR@"; RET=$? ;;
      "configurehelp") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "cd @RPMBUILDDIR@/@BUILDDIR@ && ./configure --help"; RET=$? ;;
      "showmacrosfile") $SUDO_WRAPPER $ENVIRONMENT $PACKAGE "cat /etc/rpm/macros.$MACROSFILE"; RET=$? ;;
      *) RET=0 ;;
   esac
   if [ "$REQUEST" != "" ]; then
      echo -n "
" if [ $RET -eq 0 ]; then echo "Result: OK" else echo "Result: ERROR ($RET)" fi echo -n "" echo -n "]]>
" fi fi #if [ ! "$REQUEST" -o "$REQUEST" = "output" ]; then # echo -n "All hosts] [Build hosts monitor]
" # for h in `seq 0 ${#AUTOPORT_CGI_HOST[*]}`; do # curl "${AUTOPORT_CGI_HOST[$h]}?AS_HOST=$h&SHOWINDEX=1" 2>/dev/null # done # echo "
" # # [ "$HOST" = "$AS_HOST" ] && echo "

Host: `hostname -s` (`uname -m`, kernel `uname -r`)

" # # echo -n "]]>
" #fi echo ""