2 # post_update_hook for repos.conf as used by grok-pull, takes a full
3 # git repo path as it's first and only arg.
6 # same default as other public-inbox-* tools
7 PI_CONFIG=${PI_CONFIG-~/.public-inbox/config}
9 # FreeBSD expr(1) only supports BRE, so no '+'
10 EPOCH2MAIN='\(..*\)/git/[0-9][0-9]*\.git'
12 # see if it's v2 or v1 based on tree contents, since somebody could
13 # theoretically name a v1 inbox with a path that looks like a v2 epoch
14 if git --git-dir="$full_git_dir" ls-tree --name-only HEAD | \
15 grep -E '^(m|d)$' >/dev/null
18 inbox_dir=$(expr "$full_git_dir" : "$EPOCH2MAIN")
19 inbox_name=$(basename "$inbox_dir")
20 msgmap="$inbox_dir"/msgmap.sqlite3
23 inbox_dir="$full_git_dir"
24 inbox_name=$(basename "$inbox_dir" .git)
25 msgmap="$inbox_dir"/public-inbox/msgmap.sqlite3
28 # run public-inbox-init iff unconfigured
29 cfg_dir=$(git config -f "$PI_CONFIG" publicinbox."$inbox_name".inboxdir)
31 # check legacy name for "inboxdir"
33 '') cfg_dir=$(git config -f "$PI_CONFIG" publicinbox."$inbox_name".mainrepo) ;;
38 remote_git_url=$(git --git-dir="$full_git_dir" config remote.origin.url)
39 case $remote_git_url in
41 echo >&2 "remote.origin.url unset in $full_git_dir/config"
48 remote_inbox_url="$remote_git_url"
51 remote_inbox_url=$(expr "$remote_git_url" : "$EPOCH2MAIN")
55 config_url="$remote_inbox_url"/_/text/config/raw
56 remote_config="$inbox_dir"/remote.config.$$
58 trap 'rm -f "$remote_config"' EXIT
59 if curl --compressed -sSf -v "$config_url" >"$remote_config"
61 # n.b. inbox_name on the remote may not match our local
62 # inbox_name, so we match all addresses in the remote config
63 addresses=$(git config -f "$remote_config" -l | \
64 sed -ne 's/^publicinbox\..\+\.address=//p')
67 echo >&2 'unable to extract address(es) from ' \
72 newsgroups=$(git config -f "$remote_config" -l | \
73 sed -ne 's/^publicinbox\..\+\.newsgroup=//p')
74 infourls=$(git config -f "$remote_config" -l | \
75 sed -ne 's/^publicinbox\..\+.infourl=//p')
78 addresses="$inbox_name@$$.$(hostname).example.com"
79 echo >&2 "E: curl $config_url failed"
80 echo >&2 "E: using bogus <$addresses> for $inbox_dir"
82 local_url="http://127.0.0.1:8080/$inbox_name"
83 public-inbox-init -V$inbox_fmt "$inbox_name" \
84 "$inbox_dir" "$local_url" $addresses
88 echo >&2 "E: public-inbox-init failed on $inbox_dir"
94 git config -f "$PI_CONFIG" \
95 "publicinbox.$inbox_name.newsgroup" "$ng"
96 # only one newsgroup per inbox
101 git config -f "$PI_CONFIG" \
102 "publicinbox.$inbox_name.infourl" "$url"
104 curl -sSfv "remote_inbox_url"/description >"$inbox_dir"/description
105 echo "I: $inbox_name at $inbox_dir ($addresses) $local_url"
109 # only run public-inbox-index if an index exists and has messages,
110 # since epochs may be cloned out-of-order by grokmirror and we also
111 # don't know what indexlevel a user wants
114 n=$(echo 'SELECT COUNT(*) FROM msgmap' | sqlite3 -readonly "$msgmap")
117 : v2 inboxes may be init-ed with an empty msgmap
120 $EATMYDATA public-inbox-index -v "$inbox_dir"