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
28 inbox_lock
="$inbox_dir"/inbox.lock
31 inbox_dir
="$full_git_dir"
32 inbox_name
=$
(basename "$inbox_dir" .git
)
33 msgmap
="$inbox_dir"/public-inbox
/msgmap.sqlite3
34 inbox_lock
="$inbox_dir"/ssoma.lock
37 # run public-inbox-init iff unconfigured
38 cfg_dir
=$
(git config
-f "$PI_CONFIG" publicinbox.
"$inbox_name".inboxdir
)
40 # check legacy name for "inboxdir"
42 '') cfg_dir
=$
(git config
-f "$PI_CONFIG" publicinbox.
"$inbox_name".mainrepo
) ;;
47 remote_git_url
=$
(git
--git-dir="$full_git_dir" config remote.origin.url
)
48 case $remote_git_url in
50 echo >&2 "remote.origin.url unset in $full_git_dir/config"
57 remote_inbox_url
="$remote_git_url"
60 remote_inbox_url
=$
(expr "$remote_git_url" : "$EPOCH2MAIN")
64 config_url
="$remote_inbox_url"/_
/text
/config
/raw
65 remote_config
="$inbox_dir"/remote.config.$$
67 trap 'rm -f "$remote_config"' EXIT
68 if curl
--compressed -sSf -v "$config_url" >"$remote_config"
70 # n.b. inbox_name on the remote may not match our local
71 # inbox_name, so we match all addresses in the remote config
72 addresses
=$
(git config
-f "$remote_config" -l | \
73 sed -ne 's/^publicinbox\..\+\.address=//p')
76 echo >&2 'unable to extract address(es) from ' \
81 newsgroups
=$
(git config
-f "$remote_config" -l | \
82 sed -ne 's/^publicinbox\..\+\.newsgroup=//p')
83 infourls
=$
(git config
-f "$remote_config" -l | \
84 sed -ne 's/^publicinbox\..\+.infourl=//p')
87 addresses
="$inbox_name@$$.$(hostname).example.com"
88 echo >&2 "E: curl $config_url failed"
89 echo >&2 "E: using bogus <$addresses> for $inbox_dir"
91 local_url
="$url_base$inbox_name"
92 public-inbox-init
-V$inbox_fmt "$inbox_name" \
93 "$inbox_dir" "$local_url" $addresses
97 echo >&2 "E: public-inbox-init failed on $inbox_dir"
101 for ng
in $newsgroups
103 git config
-f "$PI_CONFIG" \
104 "publicinbox.$inbox_name.newsgroup" "$ng"
105 # only one newsgroup per inbox
110 git config
-f "$PI_CONFIG" \
111 "publicinbox.$inbox_name.infourl" "$url"
113 curl
-sSfv "$remote_inbox_url"/description
>"$inbox_dir"/description
114 echo "# $inbox_name at $inbox_dir ($addresses) $local_url"
118 # only run public-inbox-index if an index exists and has messages,
119 # since epochs may be cloned out-of-order by grokmirror and we also
120 # don't know what indexlevel a user wants
123 # We need to use flock(1) (from util-linux) to avoid timeouts
124 # and SQLite locking problems.
125 # FreeBSD has a similar lockf(1) utility, but it unlinks by
126 # default so we use `-k' to keep the lock on the FS.
129 FreeBSD
) FLOCK
='lockf -k' ;;
130 # ... other OSes here
133 n
=$
(echo 'SELECT COUNT(*) FROM msgmap' | \
134 $FLOCK $inbox_lock sqlite3
-readonly "$msgmap")
137 : v2 inboxes may be init-ed with an empty msgmap
140 # if on HDD and limited RAM, add `--sequential-shard'
141 # and possibly a large `--batch-size' if you have much
142 # memory in public-inbox 1.6.0+
143 $EATMYDATA public-inbox-index
-v "$inbox_dir"