blob: 5241283568ffaa7b989ea0e0d8cf5e099c91ed29 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#!/bin/bash
# This software is released into public domain.
# It is provided "as is", without warranties or conditions of any kind.
# Anyone is free to modify, redistribute and do anything with this software.
# pomf2gomf.bash: convert pomf-style flat folders with uploads to gomf storage
set -eu
for req in basename sha1sum cut xxd base64 tr touch; do
if ! type "$req" >/dev/null; then
printf "fatal error: missing command %s\n" "$req" >&2
exit 1
fi
done
usage() {
printf "usage: %s POMF_DIR GOMF_DIR\n" "$(basename "$0")"
printf " where POMF_DIR is a flat directory with files named after their file IDs and\n"
printf " extensions and GOMF_DIR is the root dir (created if necessary) of gomf-web\n"
}
if [ $# -ne 2 ]; then
usage >&2
exit 2
fi
pomf="$1"
gomf="$2"
if ! [ -d "$pomf" ]; then
printf "directory %s does not exist\n" "$pomf" >&2
exit 1
fi
mkdir -p "$gomf/upload/files"
mkdir -p "$gomf/upload/ids"
for file in "$pomf"/*; do
name="$(basename "$file")"
id="${name%%.*}"
ext="${name#*.}"
sha="$(sha1sum -b "$file" | cut -d' ' -f1 | xxd -r -p | base64 | tr -d = | tr '+/' '-_')"
if [ "$name" = "$ext" ]; then # no ext
ext=
else
ext=".$ext"
fi
while [ ${#id} -lt 3 ]; do
id="_$id"
done
id1="${id:0:1}" # first letter
id2="${id:1:2}" # second and third letter
hash1="${sha:0:1}" # first letter
hash2="${sha:1:2}" # second and third letter
hashd="$gomf/upload/files/$hash1/$hash2/$sha"
idd="$gomf/upload/ids/$id1/$id2/$id"
mkdir -p "$hashd"
cp -va "$file" "$hashd/file"
mkdir -p "$idd"
ln -vs "../../../../files/$hash1/$hash2/$sha/file" "$idd/file$ext" # relative link to $gomf/upload/ids file
touch --no-dereference --reference "$file" "$idd/file$ext"
done
|