daemons/gc.sh: git repack -A 2G -> -a 1G
[girocco/testingthisout.git] / shlib.sh
blob35b47521414a26f6b5c8170db0a2aee9f0194f7f
1 #!/bin/bash
4 # Import all the variables from Girocco::Config to the local environment,
5 # prefixing them with 'cfg_'. E.g. $cfg_admin is admin's mail address now.
6 __girocco_conf="$GIROCCO_CONF"
7 [ -n "$__girocco_conf" ] || __girocco_conf="Girocco::Config"
8 [ -z "$basedir" ] || __girocco_extrainc="-I$basedir"
9 eval $(perl -I@basedir@ $__girocco_extrainc -M$__girocco_conf -le \
10 'foreach (keys %Girocco::Config::) {
11 my $val = ${$Girocco::Config::{$_}}; $val ||= "";
12 print "cfg_$_=\"$val\"";
13 }')
16 git() { "$cfg_git_bin" "$@"; }
19 # bang CMD... will execute the command with well-defined failure mode;
20 # set bang_action to string of the failed action ('clone', 'update', ...);
21 # pre-set bang_once=1 to make sure jobs banging on a repo repeatedly will
22 # not spam the owner; re-define the bang_trap() function to do custom
23 # cleanup before bailing out
24 bang() {
25 if [ -n "$show_progress" ]; then
26 if "$@" | tee -a "$bang_log" 2>&1; then
27 # All right. Cool.
28 return;
30 else
31 if "$@" >>"$bang_log" 2>&1; then
32 # All right. Cool.
33 return;
36 errcode="$?"
37 if ! [ -e .banged ]; then
39 echo "$* failed with error code $errcode"
40 [ ! -n "$bang_once" ] || echo "you will not receive any more notifications until recovery"
41 echo "Log follows:"
42 cat "$bang_log"
43 } | mail -s "[$cfg_name] $proj $bang_action failed" "$mail,$cfg_admin"
45 touch .banged
46 bang_trap
47 exit 1
50 # Default bang settings:
51 bang_setup() {
52 bang_action="lame_programmer"
53 bang_once=
54 bang_trap() { :; }
55 bang_log="$(mktemp -t repomgr-XXXXXX)"
56 trap "rm \"\$bang_log\"" EXIT
60 # Progress report - if show_progress is set, shows the given message.
61 progress() {
62 [ ! -n "$show_progress" ] || echo "$@"
66 # Project config accessors; must be run in project directory
67 config_get() {
68 git config "gitweb.$1"
71 config_set() {
72 git config "gitweb.$1" "$2" && chgrp repo config && chmod g+w config
76 # Tool for checking whether given number of seconds has not passed yet
77 check_interval() {
78 od="$(config_get "$1")"
79 [ -n "$od" ] || return 1
80 os="$(date +%s -d "$od")"
81 [ -n "$os" ] || return 1
82 ns="$(date +%s)"
83 [ $ns -lt $(($os+$2)) ]
87 # List all Git repositories, with given prefix if specified, one-per-line
88 get_repo_list() {
89 if [ -n "$1" ]; then
90 cut -d : -f 1,3 "$cfg_chroot"/etc/group | grep "^$1"
91 else
92 cut -d : -f 1,3 "$cfg_chroot"/etc/group
93 fi | while IFS=: read name id; do
94 [ $id -lt 65536 ] || echo "$name"
95 done