delproj.cgi: Include absolute path in form action
[girocco.git] / shlib.sh
blob8c3ea42d64f94a2b4dbd5f9d66d6912b56e7809c
1 #!/bin/bash
3 # This is generic shell library for all the scripts used by Girocco;
4 # most importantly, it introduces all the $cfg_* shell variables.
7 # Import all the variables from Girocco::Config to the local environment,
8 # prefixing them with 'cfg_'. E.g. $cfg_admin is admin's mail address now.
9 __girocco_conf="$GIROCCO_CONF"
10 [ -n "$__girocco_conf" ] || __girocco_conf="Girocco::Config"
11 [ -z "$basedir" ] || __girocco_extrainc="-I$basedir"
12 eval $(perl -I@basedir@ $__girocco_extrainc -M$__girocco_conf -le \
13 'foreach (keys %Girocco::Config::) {
14 my $val = ${$Girocco::Config::{$_}}; $val ||= "";
15 print "cfg_$_=\"$val\"";
16 }')
19 git() { "$cfg_git_bin" "$@"; }
22 # bang CMD... will execute the command with well-defined failure mode;
23 # set bang_action to string of the failed action ('clone', 'update', ...);
24 # pre-set bang_once=1 to make sure jobs banging on a repo repeatedly will
25 # not spam the owner; re-define the bang_trap() function to do custom
26 # cleanup before bailing out
27 bang() {
28 if [ -n "$show_progress" ]; then
29 if "$@" | tee -a "$bang_log" 2>&1; then
30 # All right. Cool.
31 return;
33 else
34 if "$@" >>"$bang_log" 2>&1; then
35 # All right. Cool.
36 return;
39 errcode="$?"
40 if ! [ -e .banged ]; then
41 bangmailok=true
42 ! [ -f HEAD -a -f config -a -d objects ] ||
43 bangmailok="$(GIT_DIR=. git config --bool gitweb.statusupdates 2>/dev/null || echo true)"
44 bangaddrs=''
45 [ "$bangmailok" = "false" -o -z "$mail" ] || bangaddrs="$mail"
46 [ -z "$cfg_admincc" -o "$cfg_admincc" = "0" -o -z "$cfg_admin" ] ||
47 if [ -z "$bangaddrs" ]; then bangaddrs="$cfg_admin"; else bangaddrs="$bangaddrs,$cfg_admin"; fi
48 [ -z "$bangaddrs" ] ||
50 echo "$* failed with error code $errcode"
51 [ ! -n "$bang_once" ] || echo "you will not receive any more notifications until recovery"
52 echo "this status message may be disabled on the project admin page"
53 echo "Log follows:"
54 cat "$bang_log"
55 } | mail -s "[$cfg_name] $proj $bang_action failed" "$bangaddrs"
57 touch .banged
58 bang_trap
59 exit 1
62 # Default bang settings:
63 bang_setup() {
64 bang_action="lame_programmer"
65 bang_once=
66 bang_trap() { :; }
67 bang_log="$(mktemp -t repomgr-XXXXXX)"
68 trap "rm \"\$bang_log\"" EXIT
72 # Progress report - if show_progress is set, shows the given message.
73 progress() {
74 [ ! -n "$show_progress" ] || echo "$@"
78 # Project config accessors; must be run in project directory
79 config_get() {
80 git config "gitweb.$1"
83 config_set() {
84 git config "gitweb.$1" "$2" && chgrp repo config && chmod g+w config
87 config_set_raw() {
88 git config "$1" "$2" && chgrp repo config && chmod g+w config
92 # Tool for checking whether given number of seconds has not passed yet
93 check_interval() {
94 od="$(config_get "$1")"
95 [ -n "$od" ] || return 1
96 os="$(date +%s -d "$od")"
97 [ -n "$os" ] || return 1
98 ns="$(date +%s)"
99 [ $ns -lt $(($os+$2)) ]
103 # List all Git repositories, with given prefix if specified, one-per-line
104 get_repo_list() {
105 if [ -n "$1" ]; then
106 cut -d : -f 1,3 "$cfg_chroot"/etc/group | grep "^$1"
107 else
108 cut -d : -f 1,3 "$cfg_chroot"/etc/group
109 fi | while IFS=: read name id; do
110 [ $id -lt 65536 ] || echo "$name"
111 done