diff options
author | Andrew Cady <d@jerkface.net> | 2023-05-28 17:18:57 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2023-05-28 17:20:09 -0400 |
commit | ace88012251ad607c262dc3263ed7928dbeecc20 (patch) | |
tree | cc09031410fae95845987d6dabb22a5d6c2c006a /src | |
parent | f6a5dafe904909bbee1b2da0d3a7786fd8952871 (diff) |
endofossil will find *.fossil files in various paths
Diffstat (limited to 'src')
-rw-r--r-- | src/endofossil | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/src/endofossil b/src/endofossil index c4ae60d..f645e9c 100644 --- a/src/endofossil +++ b/src/endofossil | |||
@@ -5,7 +5,8 @@ IFS=/ read n pid uid <<< "$1" | |||
5 | [ "$pid" ] | 5 | [ "$pid" ] |
6 | 6 | ||
7 | [ "$uid" -gt 0 ] | 7 | [ "$uid" -gt 0 ] |
8 | IFS=: read username realname _ _ gecos homedir shell < <(getent passwd "$uid") | 8 | IFS=: read username realname uid_ gid gecos homedir shell < <(getent passwd "$uid") |
9 | [ "$uid" = "$uid_" ] | ||
9 | 10 | ||
10 | authtype= | 11 | authtype= |
11 | while read -d '' | 12 | while read -d '' |
@@ -29,26 +30,49 @@ do | |||
29 | done < <(ssh-keygen -f <(printf '%s\n' "$keytype $keyvalue") -r .) | 30 | done < <(ssh-keygen -f <(printf '%s\n' "$keytype $keyvalue") -r .) |
30 | [ "$keyhash" ] | 31 | [ "$keyhash" ] |
31 | 32 | ||
33 | declare -a shared_paths | ||
34 | shared_paths=("$homedir"/./src /srv/./src /usr/./src /usr/local/./src) | ||
35 | require_extension=.fossil | ||
36 | |||
32 | case "$SSH_ORIGINAL_COMMAND" in | 37 | case "$SSH_ORIGINAL_COMMAND" in |
33 | *\"* ) exit 1 ;; | 38 | *\"* ) exit 1 ;; |
34 | fossil\ test-http\ * ) ;; | 39 | fossil\ test-http\ * ) |
35 | *) exit 1 ;; | 40 | set -- $SSH_ORIGINAL_COMMAND |
41 | [ $# = 3 ] | ||
42 | f=/${f%$require_extension}$require_extension | ||
43 | for d in "${shared_paths[@]}" | ||
44 | do | ||
45 | relativePart=${d#*/./} | ||
46 | absolutePart=${d%$relativePart} | ||
47 | tryPath=$absolutePart$relativePart${f#/$relativePart} | ||
48 | if [ -f "$tryPath" ] | ||
49 | then | ||
50 | upstreamDatabase=$(realpath -e -s "$tryPath") | ||
51 | break | ||
52 | fi | ||
53 | done | ||
54 | [ "$upstreamDatabase" ] | ||
55 | ;; | ||
56 | * ) exit 1 ;; | ||
36 | esac | 57 | esac |
37 | 58 | ||
38 | # This is no way to do it. | 59 | fossil_dir=$(dirname "${upstreamDatabase}") |
39 | # Let's just share /home/*/src and /srv/src and /usr/src. | 60 | readWriteDir=$fossil_dir/.fossil-remotes/$keyhash |
40 | fossil_dir=$homedir/src/fossil | 61 | readWriteDbName=$(basename "$upstreamDatabase") # Must end in .fossil for 'fossil test-http' to find it. |
41 | upstreamDatabase=$fossil_dir/db | ||
42 | readWriteDbName=db.fossil # Must end in .fossil for 'fossil test-http' to find it. | ||
43 | readWriteDir=$fossil_dir/remotes/$keyhash | ||
44 | 62 | ||
45 | as_user() | 63 | as_user() |
46 | { | 64 | { |
47 | setpriv --reuid="$username" --init-groups --inh-caps=-all "$@" | 65 | setpriv --reuid="$uid" --regid="$gid" --clear-groups --inh-caps=-all "$@" |
48 | } | 66 | } |
49 | if ! [ -d "$readWriteDir" ] | 67 | if ! [ -d "$readWriteDir" ] |
50 | then | 68 | then |
51 | as_user mkdir "$readWriteDir" | 69 | make_parents= |
70 | if [[ $readWriteDir == $home/* ]] | ||
71 | then | ||
72 | [ -d "$fossil_dir" ] | ||
73 | make_parents=-p | ||
74 | fi | ||
75 | as_user mkdir $make_parents "$readWriteDir" | ||
52 | fi | 76 | fi |
53 | as_user cp -n --reflink -- "$upstreamDatabase" "$readWriteDir"/"$readWriteDbName" | 77 | as_user cp -n --reflink -- "$upstreamDatabase" "$readWriteDir"/"$readWriteDbName" |
54 | 78 | ||