aboutsummaryrefslogtreecommitdiff
path: root/publish.sh
blob: 45b328759bb99da41dece18017999b24addff139 (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
#!/bin/sh

set -xe

INDIR=${1}
OUTDIR=${2}

[ ! $# -eq 2 ] && echo "Usage: $0 <input dir> <output dir>" && exit 1
[ ! -d $INDIR ] && echo "Error: invalid input" && exit 1

mkdir -p $OUTDIR

MAX_DEPTH=10
publish() {

	[ $1 -gt $MAX_DEPTH ] && echo "Maximum depth exceeded." && exit 1

	for file in $(find "$2" -maxdepth 1 -mindepth 1 -type f); do
		cp $file $3/$(basename $file)
	done

	for dir in $(find "$2" -maxdepth 1 -mindepth 1 -type d); do
		dirname=$(basename $dir)
		# If $dirname starts with an underscore the contents of
		# $dir should be copied into the well-known directorie.
		# It is assumed that $dir only contains files
		if expr $dirname : "_"* 1> /dev/null; then
			mkdir -p $OUTDIR/.well-known
			cp $dir/* $OUTDIR/.well-known/
		else
			output_dir=$3/$dirname
			mkdir -p $output_dir
			publish $(($1+1)) $dir $output_dir
		fi
	done
}

publish 0 $INDIR $OUTDIR