Add support for local settings

While there, also rename the deforaos-irc script.
This commit is contained in:
Pierre Pronchery 2020-11-03 08:29:39 +01:00
parent 287c0da3b4
commit 54cff92589
4 changed files with 97 additions and 64 deletions

View File

@ -26,19 +26,25 @@
#variables #variables
PREFIX="/usr/local" PREFIX="/usr/local"
GITWEB_URL="https://git.defora.org/gitweb" #executables
GIT_MESSAGE="$PREFIX/libexec/deforaos-git-message"
DEFORAOS_IRC="$PREFIX/libexec/deforaos-irc -N -n defora"
DEFORAOS_JOBS="$PREFIX/bin/deforaos-jobs -d /home/jobs/DeforaOS"
MKTEMP="mktemp"
RM="rm -f"
#settings
HOOKS="irc jobs" HOOKS="irc jobs"
IRC_CHANNEL="#DeforaOS" IRC_CHANNEL=
IRC_SERVER="irc.oftc.net" IRC_SERVER=
JOBS_BRANCH_MASTER="$PREFIX/libexec/deforaos-git-mirror.sh JOBS_BRANCH_MASTER="$PREFIX/libexec/deforaos-git-mirror.sh
$PREFIX/libexec/deforaos-git-doc.sh $PREFIX/libexec/deforaos-git-doc.sh
$PREFIX/libexec/deforaos-git-tests.sh" $PREFIX/libexec/deforaos-git-tests.sh"
#executables SYSCONFDIR="$PREFIX/etc"
GIT_MESSAGE="$PREFIX/libexec/deforaos-git-message" #load local settings
IRC="$PREFIX/libexec/deforaos-irc.sh -N -s $IRC_SERVER -c $IRC_CHANNEL -n defora" [ -f "$SYSCONFDIR/DeforaOS/$PROGNAME.conf" ] &&
JOBS="$PREFIX/bin/deforaos-jobs.sh -d /home/jobs/DeforaOS" . "$SYSCONFDIR/DeforaOS/$PROGNAME.conf"
MKTEMP="mktemp" [ -f "$HOME/.config/DeforaOS/$PROGNAME.conf" ] &&
RM="/bin/rm -f" . "$HOME/.config/DeforaOS/$PROGNAME.conf"
#functions #functions
@ -62,7 +68,7 @@ _jobs_branch()
if [ "$branch" = "master" -a -n "$JOBS_BRANCH_MASTER" ]; then if [ "$branch" = "master" -a -n "$JOBS_BRANCH_MASTER" ]; then
for job in $JOBS_BRANCH_MASTER; do for job in $JOBS_BRANCH_MASTER; do
$JOBS add "$job $repository" $DEFORAOS_JOBS add "$job $repository"
done done
fi fi
} }
@ -71,7 +77,11 @@ _jobs_branch()
#hook_irc #hook_irc
_hook_irc() _hook_irc()
{ {
$GIT_MESSAGE -O GITWEB_URL="$GITWEB_URL" "post-receive" | $IRC if [ -z "$IRC_SERVER" -o -z "$IRC_CHANNEL" ]; then
_error "IRC_SERVER and IRC_CHANNEL must be set for the IRC hook"
return $?
fi
$GIT_MESSAGE "post-receive" | $DEFORAOS_IRC "$IRC_SERVER" "$IRC_CHANNEL"
#ignore errors #ignore errors
return 0 return 0
} }

View File

@ -16,17 +16,25 @@
#environment
#variables #variables
GITWEB=
PROGNAME="deforaos-git-message.sh"
REDMINE=
#executables #executables
GIT="git" GIT="git"
SED="sed" SED="sed"
SORT="sort" SORT="sort"
TOLOWER="_tolower"
TR="tr" TR="tr"
UNIQ="uniq" UNIQ="uniq"
#settings
GITWEB_URL=
PREFIX="/usr/local"
PROGNAME="deforaos-git-message"
REDMINE_URL=
SYSCONFDIR="$PREFIX/etc"
#load local settings
[ -f "$SYSCONFDIR/DeforaOS/$PROGNAME.conf" ] &&
. "$SYSCONFDIR/DeforaOS/$PROGNAME.conf"
[ -f "$HOME/.config/DeforaOS/$PROGNAME.conf" ] &&
. "$HOME/.config/DeforaOS/$PROGNAME.conf"
#functions #functions
@ -56,8 +64,8 @@ _link_branch()
repository="$1" repository="$1"
branch="$2" branch="$2"
[ -n "$GITWEB" ] && echo "$GITWEB?p=${repository}.git;a=shortlog;h=refs/heads/$branch" [ -n "$GITWEB_URL" ] && echo "$GITWEB_URL?p=${repository}.git;a=shortlog;h=refs/heads/$branch"
[ -n "$REDMINE" ] && echo "$REDMINE/repository/${repository}/show?rev=$branch" | _tolower [ -n "$REDMINE_URL" ] && echo "$REDMINE_URL/repository/${repository}/show?rev=$branch" | $TOLOWER
} }
@ -68,8 +76,8 @@ _link_commit()
rev="$2" rev="$2"
shortrev=$(_shorten 8 "$rev") shortrev=$(_shorten 8 "$rev")
[ -n "$GITWEB" ] && echo "$GITWEB?p=${repository}.git;a=commit;h=$shortrev" [ -n "$GITWEB_URL" ] && echo "$GITWEB_URL?p=${repository}.git;a=commit;h=$shortrev"
[ -n "$REDMINE" ] && echo "$REDMINE/repository/${repository}/revisions/$shortrev" | _tolower [ -n "$REDMINE_URL" ] && echo "$REDMINE_URL/repository/${repository}/revisions/$shortrev" | $TOLOWER
} }
@ -197,13 +205,6 @@ _message_update()
} }
#_tolower
_tolower()
{
$TR A-Z a-z
}
#shorten #shorten
_shorten() _shorten()
{ {
@ -211,6 +212,13 @@ _shorten()
} }
#tolower
_tolower()
{
$TR A-Z a-z
}
#usage #usage
_usage() _usage()
{ {

View File

@ -16,42 +16,47 @@
#environment
#variables #variables
DEVNULL="/dev/null"
JOIN="/j"
NOTICE="/NOTICE"
PREFIX="/var/tmp/ii"
PRIVMSG="/j"
PROGNAME="deforaos-irc.sh"
QUIT="/QUIT"
#executables #executables
CUT="cut" CUT="cut"
FORTUNE="fortune -s" FORTUNE="fortune -s"
HEAD="head" HEAD="head"
II="ii -i $PREFIX" II=
KILL="kill" KILL="kill"
RM="rm -f" RM="rm -f"
SLEEP="sleep 1" SLEEP="sleep 1"
TOLOWER="_tolower"
TR="tr" TR="tr"
#settings
DEVNULL="/dev/null"
II_CMD_JOIN="/j"
II_CMD_NOTICE="/II_CMD_NOTICE"
II_CMD_PRIVMSG="/j"
II_CMD_QUIT="/II_CMD_QUIT"
II_PREFIX="/var/tmp/ii"
PREFIX="/usr/local"
PROGNAME="deforaos-irc"
SYSCONFDIR="$PREFIX/etc"
VERBOSE=0
#load local settings
[ -f "$SYSCONFDIR/DeforaOS/$PROGNAME.conf" ] &&
. "$SYSCONFDIR/DeforaOS/$PROGNAME.conf"
[ -f "$HOME/.config/DeforaOS/$PROGNAME.conf" ] &&
. "$HOME/.config/DeforaOS/$PROGNAME.conf"
#functions #functions
#irc #irc
_irc() _irc()
{ {
if [ $# -ne 4 ]; then
_usage
return 1
fi
ret=0 ret=0
pid=0 pid=0
server=$(echo "$1" | $TR A-Z a-z) server=$(echo "$1" | $TOLOWER)
port="$2" port="$2"
nickname="$3" nickname="$3"
channel=$(echo "$4" | $TR A-Z a-z) channel=$(echo "$4" | $TOLOWER)
serverin="$PREFIX/$server/in" serverin="$II_PREFIX/$server/in"
channelin="$PREFIX/$server/$channel/in" channelin="$II_PREFIX/$server/$channel/in"
#connect to the server #connect to the server
if [ ! -w "$serverin" ]; then if [ ! -w "$serverin" ]; then
@ -75,10 +80,10 @@ _irc()
while read line; do while read line; do
if [ $notice -eq 0 ]; then if [ $notice -eq 0 ]; then
_info "$server: Messaging user $channel" _info "$server: Messaging user $channel"
output="$PRIVMSG $channel $line" output="$II_CMD_PRIVMSG $channel $line"
else else
_info "$server: Notifying user $channel" _info "$server: Notifying user $channel"
output="$NOTICE $channel :$line" output="$II_CMD_NOTICE $channel :$line"
fi fi
echo "$output" echo "$output"
$SLEEP $SLEEP
@ -87,7 +92,7 @@ _irc()
#join the channel #join the channel
if [ ! -w "$channelin" ]; then if [ ! -w "$channelin" ]; then
_info "$server: Joining channel $channel" _info "$server: Joining channel $channel"
echo "$JOIN $channel" > "$serverin" echo "$II_CMD_JOIN $channel" > "$serverin"
fi fi
#wait until the channel is joined #wait until the channel is joined
loop=0 loop=0
@ -110,7 +115,7 @@ _irc()
else else
_info "$server: Notifying channel $channel" _info "$server: Notifying channel $channel"
while read line; do while read line; do
echo "$NOTICE $channel :$line" echo "$II_CMD_NOTICE $channel :$line"
$SLEEP $SLEEP
done > "$serverin" done > "$serverin"
fi fi
@ -122,7 +127,7 @@ _irc()
#quit the server #quit the server
_info "$server: Disconnecting from server" _info "$server: Disconnecting from server"
fortune=$($FORTUNE | $HEAD -n 1 | $CUT -c 1-50) fortune=$($FORTUNE | $HEAD -n 1 | $CUT -c 1-50)
echo "$QUIT :$fortune" > "$serverin" echo "$II_CMD_QUIT :$fortune" > "$serverin"
#wait until the server is disconnected #wait until the server is disconnected
#FIXME ii does not automatically clean up when quitting #FIXME ii does not automatically clean up when quitting
loop=0 loop=0
@ -153,14 +158,21 @@ _error()
#info #info
_info() _info()
{ {
[ $verbose -eq 0 ] || echo "$PROGNAME: $@" [ $VERBOSE -eq 0 ] || echo "$PROGNAME: $@"
}
#tolower
_tolower()
{
$TR A-Z a-z
} }
#usage #usage
_usage() _usage()
{ {
echo "Usage: $PROGNAME [-Nqv] -s server -c channel [-n nickname]" 1>&2 echo "Usage: $PROGNAME [-Nqv][-n nickname] server channel" 1>&2
echo " -N Use notice" 1>&2 echo " -N Use notice" 1>&2
echo " -q Quiet mode (default)" 1>&2 echo " -q Quiet mode (default)" 1>&2
echo " -v Be more verbose" 1>&2 echo " -v Be more verbose" 1>&2
@ -170,34 +182,28 @@ _usage()
#main #main
#parse options #parse options
channel=
nickname="$USER" nickname="$USER"
notice=0 notice=0
port=6667 port=6667
server= while getopts "Nn:O:qv" name; do
verbose=0
while getopts "c:Nn:qs:v" name; do
case "$name" in case "$name" in
c)
channel="$OPTARG"
;;
N) N)
notice=1 notice=1
;; ;;
n) n)
nickname="$OPTARG" nickname="$OPTARG"
;; ;;
O)
export "${OPTARG%%=*}"="${OPTARG#*=}"
;;
p) p)
port="$OPTARG" port="$OPTARG"
;; ;;
q) q)
verbose=0 VERBOSE=0
;;
s)
server="$OPTARG"
;; ;;
v) v)
verbose=$((verbose + 1)) VERBOSE=$((VERBOSE + 1))
;; ;;
*) *)
_usage _usage
@ -205,9 +211,18 @@ while getopts "c:Nn:qs:v" name; do
;; ;;
esac esac
done done
shift $((OPTIND - 1))
if [ $# -ne 2 ]; then
_usage
exit $?
fi
server="$1"
channel="$2"
if [ -z "$server" -o -z "$channel" ]; then if [ -z "$server" -o -z "$channel" ]; then
_usage _usage
exit $? exit $?
fi fi
[ -n "$II" ] || II="ii -i $II_PREFIX"
_irc "$server" "$port" "$nickname" "$channel" _irc "$server" "$port" "$nickname" "$channel"

View File

@ -1,4 +1,4 @@
dist=Makefile,deforaos-build.sh,deforaos-document.sh,deforaos-git-doc.sh,deforaos-git-hook,deforaos-git-message,deforaos-git-mirror.sh,deforaos-git-tests.sh,deforaos-irc.sh,deforaos-jobs.sh,deforaos-lock.sh,deforaos-package.sh,deforaos-release.sh,deforaos-update.sh dist=Makefile,deforaos-build.sh,deforaos-document.sh,deforaos-git-doc.sh,deforaos-git-hook,deforaos-git-message,deforaos-git-mirror.sh,deforaos-git-tests.sh,deforaos-irc,deforaos-jobs.sh,deforaos-lock.sh,deforaos-package.sh,deforaos-release.sh,deforaos-update.sh
[deforaos-build.sh] [deforaos-build.sh]
install=$(PREFIX)/bin install=$(PREFIX)/bin
@ -28,7 +28,7 @@ mode=0755
install=$(PREFIX)/libexec install=$(PREFIX)/libexec
mode=0755 mode=0755
[deforaos-irc.sh] [deforaos-irc]
install=$(PREFIX)/libexec install=$(PREFIX)/libexec
mode=0755 mode=0755