-
Notifications
You must be signed in to change notification settings - Fork 4
/
template
executable file
·86 lines (76 loc) · 1.49 KB
/
template
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# set as you install this script
templatedir="TEMPLATEDIR"
targetdir=`pwd`
VERSION="1.0"
# print usage
function usage () {
echo "Usage: $0 [-d templatedir] [-f targetdir] [-h] [-v] template" >&2
echo -n "template: "
find $templatedir -maxdepth 1 -mindepth 1 -type d | sed -e "s%${templatedir}/%%" | tr '\n' ' '
echo
}
function version () {
echo "template -- version ${VERSION}"
}
# parse option
while getopts :d:f:hv opt
do
case $opt in
d)
templatedir=$OPTARG
;;
h)
usage
exit 0
;;
f)
targetdir=$OPTARG
;;
v)
version
exit 0
;;
?)
echo "$0: Illegal option -$OPTARG" >&2
echo ""
usage
exit 1
;;
esac
done
shift $((OPTIND - 1))
# check # of args
if [ $# -ne 1 ]; then
echo "Specify ONE template: $@"
echo ""
usage
exit 1;
fi
# set path to template
template=${templatedir}"/"$1
if [ ! -d $template ]; then
echo "Unknown Template: $template"
echo ""
usage
exit 1
fi
# check path to target
if [ ! -d $targetdir ]; then
echo "Unknown Target: $targetdir"
echo ""
usage
exit 1
fi
# copy
echo "Copy from \"$1\" to \"$targetdir\""
# enable dotglob (Bash Built-in Command!!)
shopt -s dotglob
cp -r $template/* $targetdir
if [ $? -ne 0 ]; then
echo "Copy is failed"
exit 1
else
echo "Finished!"
fi
exit 0