3 # use flock(1) from util-linux to avoid seek contention on slow HDDs
4 # when using multiple `pull_threads' with grok-pull:
5 # [ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock "$0" "$0" "$@" || :
7 # post_update_hook for repos.conf as used by grok-pull, takes a full
8 # git repo path as it's first and only arg.
11 url_base=http://127.0.0.1:8080/
13 # same default as other public-inbox-* tools
14 PI_CONFIG=${PI_CONFIG-~/.public-inbox/config}
16 # FreeBSD expr(1) only supports BRE, so no '+'
17 EPOCH2MAIN='\(..*\)/git/[0-9][0-9]*\.git'
19 # see if it's v2 or v1 based on tree contents, since somebody could
20 # theoretically name a v1 inbox with a path that looks like a v2 epoch
21 if git --git-dir="$full_git_dir" ls-tree --name-only HEAD | \
22 grep -E '^(m|d)$' >/dev/null
25 inbox_dir=$(expr "$full_git_dir" : "$EPOCH2MAIN")
26 inbox_name=$(basename "$inbox_dir")
27 msgmap="$inbox_dir"/msgmap.sqlite3
30 inbox_dir="$full_git_dir"
31 inbox_name=$(basename "$inbox_dir" .git)
32 msgmap="$inbox_dir"/public-inbox/msgmap.sqlite3
35 # run public-inbox-init iff unconfigured
36 cfg_dir=$(git config -f "$PI_CONFIG" publicinbox."$inbox_name".inboxdir)
38 # check legacy name for "inboxdir"
40 '') cfg_dir=$(git config -f "$PI_CONFIG" publicinbox."$inbox_name".mainrepo) ;;
45 remote_git_url=$(git --git-dir="$full_git_dir" config remote.origin.url)
46 case $remote_git_url in
48 echo >&2 "remote.origin.url unset in $full_git_dir/config"
55 remote_inbox_url="$remote_git_url"
58 remote_inbox_url=$(expr "$remote_git_url" : "$EPOCH2MAIN")
62 config_url="$remote_inbox_url"/_/text/config/raw
63 remote_config="$inbox_dir"/remote.config.$$
65 trap 'rm -f "$remote_config"' EXIT
66 if curl --compressed -sSf -v "$config_url" >"$remote_config"
68 # n.b. inbox_name on the remote may not match our local
69 # inbox_name, so we match all addresses in the remote config
70 addresses=$(git config -f "$remote_config" -l | \
71 sed -ne 's/^publicinbox\..\+\.address=//p')
74 echo >&2 'unable to extract address(es) from ' \
79 newsgroups=$(git config -f "$remote_config" -l | \
80 sed -ne 's/^publicinbox\..\+\.newsgroup=//p')
81 infourls=$(git config -f "$remote_config" -l | \
82 sed -ne 's/^publicinbox\..\+.infourl=//p')
85 addresses="$inbox_name@$$.$(hostname).example.com"
86 echo >&2 "E: curl $config_url failed"
87 echo >&2 "E: using bogus <$addresses> for $inbox_dir"
89 local_url="$url_base$inbox_name"
90 public-inbox-init -V$inbox_fmt "$inbox_name" \
91 "$inbox_dir" "$local_url" $addresses
95 echo >&2 "E: public-inbox-init failed on $inbox_dir"
101 git config -f "$PI_CONFIG" \
102 "publicinbox.$inbox_name.newsgroup" "$ng"
103 # only one newsgroup per inbox
108 git config -f "$PI_CONFIG" \
109 "publicinbox.$inbox_name.infourl" "$url"
111 curl -sSfv "$remote_inbox_url"/description >"$inbox_dir"/description
112 echo "I: $inbox_name at $inbox_dir ($addresses) $local_url"
116 # only run public-inbox-index if an index exists and has messages,
117 # since epochs may be cloned out-of-order by grokmirror and we also
118 # don't know what indexlevel a user wants
121 n=$(echo 'SELECT COUNT(*) FROM msgmap' | sqlite3 -readonly "$msgmap")
124 : v2 inboxes may be init-ed with an empty msgmap
127 # if on HDD and limited RAM, add `--sequential-shard'
128 # and possibly a large `--batch-size' if you have much
129 # memory in public-inbox 1.6.0+
130 $EATMYDATA public-inbox-index -v "$inbox_dir"