webbuild: lots of not better detailed changes; added webbuild-functions import script in /usr/share/autodist
This commit is contained in:
parent
e66061e4c3
commit
ffff0b1c10
17
Makefile
17
Makefile
@ -29,7 +29,8 @@ INSTALL_DATA = ${INSTALL} -m 644
|
||||
INSTALL_DIR = ${INSTALL} -d -m 755
|
||||
INSTALL_SCRIPT = ${INSTALL_PROGRAM}
|
||||
|
||||
pck_datadir = $(localstatedir)/$(PACKAGE)
|
||||
pck_datadir = $(datadir)/$(PACKAGE)
|
||||
pck_statedir = $(localstatedir)/$(PACKAGE)
|
||||
pck_logdir = $(localstatedir)/$(PACKAGE)/log
|
||||
|
||||
distdir = $(PACKAGE)-$(VERSION)
|
||||
@ -49,14 +50,15 @@ install-dirs:
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(sbindir)
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(cgidir)
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(pck_datadir)
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(pck_datadir)/template/autoupdate/spec-patches-build/old
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(pck_datadir)/template/autoupdate/spec-patches-update/old
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(pck_statedir)
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(pck_statedir)/template/autoupdate/spec-patches-build/old
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(pck_statedir)/template/autoupdate/spec-patches-update/old
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(pck_logdir)/prepare/{ok,failed}
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(pck_logdir)/update/{ok,failed}
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(pck_logdir)/build/{ok,failed}
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(pck_logdir)/install/{ok,failed}
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(pck_logdir)/send/{ok,failed}
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(pck_datadir)/RPM/{SPECS,SRPMS,BUILD,SOURCES,RPMS/{noarch,i586,ppc,x86_64,arm}}
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(pck_statedir)/RPM/{SPECS,SRPMS,BUILD,SOURCES,RPMS/{noarch,i586,ppc,x86_64,arm}}
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(piddir)
|
||||
@$(INSTALL_DIR) $(DESTDIR)$(libexecdir)
|
||||
|
||||
@ -71,6 +73,7 @@ install-programs:
|
||||
@$(INSTALL_SCRIPT) webbuild/webbuild-cgi $(DESTDIR)$(cgidir)/webbuild
|
||||
@$(INSTALL_SCRIPT) webbuild/webbuild-sudo $(DESTDIR)$(libexecdir)/webbuild-sudo
|
||||
@$(INSTALL_SCRIPT) webbuild/webbuild-checkpassword $(DESTDIR)$(libexecdir)/webbuild-checkpassword
|
||||
@$(INSTALL_SCRIPT) webbuild/webbuild-functions $(DESTDIR)$(pck_datadir)/webbuild-functions
|
||||
|
||||
install-data:
|
||||
@$(INSTALL_DATA) etc/autodist/config $(DESTDIR)$(configdir)/config
|
||||
@ -93,9 +96,9 @@ install-data:
|
||||
@$(INSTALL_SCRIPT) etc/sysconfig/autoport $(DESTDIR)$(sysconfdir)/sysconfig/autoport
|
||||
@$(INSTALL_SCRIPT) etc/cron.hourly/65-autoport $(DESTDIR)$(sysconfdir)/cron.hourly/
|
||||
@$(INSTALL_SCRIPT) etc/cron.daily/40-autodist-cleanold $(DESTDIR)$(sysconfdir)/cron.daily/
|
||||
@$(INSTALL_DATA) autospec-conf $(DESTDIR)$(pck_datadir)/.autospec
|
||||
@touch $(DESTDIR)$(pck_datadir)/template/autoupdate/auto.success
|
||||
@touch $(DESTDIR)$(pck_datadir)/template/autoupdate/auto.skip
|
||||
@$(INSTALL_DATA) autospec-conf $(DESTDIR)$(pck_statedir)/.autospec
|
||||
@touch $(DESTDIR)$(pck_statedir)/template/autoupdate/auto.success
|
||||
@touch $(DESTDIR)$(pck_statedir)/template/autoupdate/auto.skip
|
||||
|
||||
install: \
|
||||
install-dirs \
|
||||
|
File diff suppressed because it is too large
Load Diff
156
webbuild/webbuild-functions
Normal file
156
webbuild/webbuild-functions
Normal file
@ -0,0 +1,156 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# webbuild functions
|
||||
# Copyright (c) 2012 by Silvan Calarco <silvan.calarco@mambasoft.it>
|
||||
#
|
||||
. /etc/autodist/config
|
||||
|
||||
SUDO_WRAPPER="sudo /usr/libexec/webbuild-sudo"
|
||||
#STATEDIR=$WEBBUILD_STATEDIR
|
||||
LOG=$WEBBUILD_STATEDIR/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 $WEBBILD_STATEDIR/users/$stateuser.state ] || touch $WEBBUILD_STATEDIR/users/$stateuser.state
|
||||
sed -i "/^$statevar=/d" $WEBBUILD_STATEDIR/users/$stateuser.state
|
||||
[ "$statevalue" ] && echo "$statevar=$statevalue" >> $WEBBUILD_STATEDIR/users/$stateuser.state
|
||||
}
|
||||
|
||||
function social_log() {
|
||||
local line=$1
|
||||
|
||||
[ "$1" ] || return
|
||||
|
||||
if [ ! "$STATE_FAKEUSER" ]; then
|
||||
STATE_SOCIALLOG_ID=0
|
||||
. $WEBBUILD_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" >> $WEBBUILD_STATEDIR/social_log
|
||||
fi
|
||||
}
|
||||
|
||||
function cgi_encodevar() {
|
||||
local string="${1}"
|
||||
local strlen=${#string}
|
||||
local encoded=""
|
||||
|
||||
for (( pos=0 ; pos<strlen ; pos++ )); do
|
||||
c=${string:$pos:1}
|
||||
case "$c" in
|
||||
[-_.~a-zA-Z0-9] ) o="${c}" ;;
|
||||
* ) printf -v o '%%%02x' "'$c"
|
||||
esac
|
||||
encoded+="${o}"
|
||||
done
|
||||
echo "${encoded}" # You can either set a return variable (FASTER)
|
||||
# REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p
|
||||
}
|
||||
|
||||
#This code for getting code from post data is from http://oinkzwurgl.org/bash_cgi and
|
||||
#was written by Phillippe Kehi <phkehi@gmx.net> 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
|
||||
}
|
||||
|
||||
function kill_tree() {
|
||||
local killpid=$1
|
||||
|
||||
[ $1 ] || return
|
||||
|
||||
kill `pstree -p $killpid | sed 's/(/\n(/g' | grep '(' | sed 's/(\(.*\)).*/\1/' | tr "\n" " "`
|
||||
return $?
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
. /usr/share/autodist/webbuild-functions
|
||||
. /etc/sysconfig/autoport
|
||||
|
||||
ENVIRONMENT=$1
|
||||
@ -14,6 +15,7 @@ fi
|
||||
|
||||
if [ "${AUTOPORT_CHROOT[$ENVIRONMENT]}" ]; then
|
||||
ENVPREFIX="/var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}"
|
||||
ENVUSER=${AUTOPORT_CHROOT_USER[$ENVIRONMENT]}
|
||||
WORKINGHOME="/usr/src/"
|
||||
SUCMDPREFIX="chroot $ENVPREFIX su -l ${AUTOPORT_CHROOT_USER[$ENVIRONMENT]} -c"
|
||||
RPMBUILDROOT="/var/tmp/"
|
||||
@ -23,10 +25,12 @@ if [ "${AUTOPORT_CHROOT[$ENVIRONMENT]}" ]; then
|
||||
}
|
||||
elif [ "${AUTOPORT_NATIVE[$ENVIRONMENT]}" ]; then
|
||||
ENVPREFIX=
|
||||
ENVUSER=${AUTOPORT_CHROOT_USER[$ENVIRONMENT]}
|
||||
WORKINGHOME=`getent passwd ${AUTOPORT_CHROOT_USER[$ENVIRONMENT]} | cut -d: -f6`
|
||||
SUCMDPREFIX="su -l ${AUTOPORT_CHROOT_USER[$ENVIRONMENT]} -c"
|
||||
else
|
||||
ENVPREFIX=
|
||||
ENVUSER=autodist
|
||||
WORKINGHOME="/var/autodist"
|
||||
SUCMDPREFIX="su -l autodist -c"
|
||||
RPMBUILDROOT="/var/tmp/autodist"
|
||||
@ -36,19 +40,17 @@ eval `$SUCMDPREFIX "autospec --eval=tmppath_dir|grep -v '^#'"`
|
||||
RPMBUILDROOT=$tmppath_dir
|
||||
SPECFILE=${ENVPREFIX}${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec
|
||||
if [ -r "$SPECFILE" ]; then
|
||||
# _tmpfile=`mktemp`
|
||||
# _errtmpfile=`mktemp`
|
||||
# rpm -q --specfile $SPECFILE --specedit > ${_tmpfile} 2>${_errtmpfile}
|
||||
# [ -s ${_errtmpfile} ] && {
|
||||
# cat ${_errtmpfile}
|
||||
# rm -f ${_tmpfile} ${_errtmpfile}
|
||||
# exit 254
|
||||
# }
|
||||
rm -f $SPECFILE.tmp
|
||||
$SUCMDPREFIX "rpm -q --specfile ${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec --specedit > ${WORKINGHOME}/RPM/SPECS/$PACKAGE.spec.tmp 2>/dev/null"
|
||||
if [ -e $SPECFILE.tmp ]; then
|
||||
BUILDDIR=`grep -m1 "^%setup.*-n " $SPECFILE.tmp | sed "s|.*-n \([^[:space:]]*\).*|\1|"`
|
||||
rm -f $SPECFILE.tmp
|
||||
fi
|
||||
SPECVERSION=`grep -m1 "^Version:" ${SPECFILE} | sed "s|Version:[[:space:]]*||"`
|
||||
BUILDROOT=$PACKAGE-root
|
||||
#`grep ^BuildRoot: ${_tmpfile} | sed "s|BuildRoot:[[:space:]]*||"`
|
||||
# SPECSETUP=`grep %setup ${_tmpfile} | sed "s|.*-n ||"`
|
||||
BUILDDIR=$PACKAGE-$SPECVERSION
|
||||
[ "$BUILDDIR" ] || BUILDDIR=$PACKAGE-$SPECVERSION
|
||||
fi
|
||||
RPMBUILDDIR=${WORKINGHOME}/RPM/BUILD
|
||||
COMMAND=`echo $COMMAND | sed "s|@BUILDDIR@|$BUILDDIR|g"`
|
||||
@ -56,12 +58,21 @@ COMMAND=`echo $COMMAND | sed "s|@BUILDROOT@|$BUILDROOT|g"`
|
||||
COMMAND=`echo $COMMAND | sed "s|@RPMBUILDDIR@|$RPMBUILDDIR|g"`
|
||||
COMMAND=`echo $COMMAND | sed "s|@RPMBUILDROOT@|$RPMBUILDROOT|g"`
|
||||
|
||||
cmdtmpfile=`mktemp`
|
||||
chgrp nobody $cmdtmpfile
|
||||
chmod 640 $cmdtmpfile
|
||||
|
||||
rettmpfile=`$SUCMDPREFIX mktemp`
|
||||
$SUCMDPREFIX ". /etc/profile;cd $WORKINGHOME/RPM/SPECS;$COMMAND;echo \$? > $rettmpfile" 2>&1 | sed "s|<|\<|g"
|
||||
|
||||
echo "$$ $ENVUSER $ENVIRONMENT $cmdtmpfile $COMMAND" >> $WEBBUILD_STATEDIR/processes
|
||||
|
||||
$SUCMDPREFIX ". /etc/profile;cd $WORKINGHOME/RPM/SPECS;$COMMAND;echo \$? > $rettmpfile" 2>&1 | sed "s|<|\<|g" | tr -d '\f' | tee $cmdtmpfile
|
||||
RET=`cat $rettmpfile`
|
||||
$SUCMDPREFIX "rm -f $rettmpfile"
|
||||
|
||||
echo "Command: $SUCMDPREFIX \"cd $WORKINGHOME/RPM/SPECS;$COMMAND\";RET=$RET" >&2
|
||||
#echo "Command: $SUCMDPREFIX \"cd $WORKINGHOME/RPM/SPECS;$COMMAND\";RET=$RET" >&2
|
||||
sed -i "/^$$ $ENVUSER/d" $WEBBUILD_STATEDIR/processes
|
||||
rm -f $cmdtmpfile
|
||||
|
||||
if [ "$TMPFILE" -a "${AUTOPORT_CHROOT[$ENVIRONMENT]}" ]; then
|
||||
rm -f /var/autoport/${AUTOPORT_CHROOT[$ENVIRONMENT]}/$TMPFILE
|
||||
|
Loading…
Reference in New Issue
Block a user