summaryrefslogtreecommitdiff
path: root/ensure-dir.sh
blob: 34f03ac551aef3b6b1ea130e26faf7d6e651dca1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh

pathname=$1
mode=$2
OLDIFS="${IFS}"; IFS=/; set $pathname; IFS="${OLDIFS}"

case $pathname in
	/*)	partial=/; ;;
	*)	partial=""; ;;
esac

for i do
	case i in "") continue; ;; esac
	partial="${partial}${i}"
	if [ ! -d ${partial} ]; then
		mkdir ${partial} || exit 1;
		chmod ${mode} ${partial}
	fi
	partial="${partial}/"
done