summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2023-05-28 17:18:57 -0400
committerAndrew Cady <d@jerkface.net>2023-05-28 17:20:09 -0400
commitace88012251ad607c262dc3263ed7928dbeecc20 (patch)
treecc09031410fae95845987d6dabb22a5d6c2c006a /src
parentf6a5dafe904909bbee1b2da0d3a7786fd8952871 (diff)
endofossil will find *.fossil files in various paths
Diffstat (limited to 'src')
-rw-r--r--src/endofossil46
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 ]
8IFS=: read username realname _ _ gecos homedir shell < <(getent passwd "$uid") 8IFS=: read username realname uid_ gid gecos homedir shell < <(getent passwd "$uid")
9[ "$uid" = "$uid_" ]
9 10
10authtype= 11authtype=
11while read -d '' 12while read -d ''
@@ -29,26 +30,49 @@ do
29done < <(ssh-keygen -f <(printf '%s\n' "$keytype $keyvalue") -r .) 30done < <(ssh-keygen -f <(printf '%s\n' "$keytype $keyvalue") -r .)
30[ "$keyhash" ] 31[ "$keyhash" ]
31 32
33declare -a shared_paths
34shared_paths=("$homedir"/./src /srv/./src /usr/./src /usr/local/./src)
35require_extension=.fossil
36
32case "$SSH_ORIGINAL_COMMAND" in 37case "$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 ;;
36esac 57esac
37 58
38# This is no way to do it. 59fossil_dir=$(dirname "${upstreamDatabase}")
39# Let's just share /home/*/src and /srv/src and /usr/src. 60readWriteDir=$fossil_dir/.fossil-remotes/$keyhash
40fossil_dir=$homedir/src/fossil 61readWriteDbName=$(basename "$upstreamDatabase") # Must end in .fossil for 'fossil test-http' to find it.
41upstreamDatabase=$fossil_dir/db
42readWriteDbName=db.fossil # Must end in .fossil for 'fossil test-http' to find it.
43readWriteDir=$fossil_dir/remotes/$keyhash
44 62
45as_user() 63as_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}
49if ! [ -d "$readWriteDir" ] 67if ! [ -d "$readWriteDir" ]
50then 68then
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"
52fi 76fi
53as_user cp -n --reflink -- "$upstreamDatabase" "$readWriteDir"/"$readWriteDbName" 77as_user cp -n --reflink -- "$upstreamDatabase" "$readWriteDir"/"$readWriteDbName"
54 78