forked from jeffreyroberts/sub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare.sh
executable file
·79 lines (64 loc) · 1.49 KB
/
prepare.sh
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
#!/usr/bin/env bash
set -e
create_sub() {
file="$1"
SUBNAME="$2"
ENVNAME="$3"
sed "s/sub/$SUBNAME/g;s/SUB_ROOT/$ENVNAME/g" "$file" > $(echo $file | sed "s/sub/$SUBNAME/g")
rm $file
}
chmod_files() {
for file in $1/*; do
chmod a+x $file
done
}
prepare_sub() {
SUBNAME="$2"
mkdir -p $(echo $1 | sed "s/sub/$SUBNAME/g")
for file in $1/sub*; do
if [ -d "$file" ]; then
prepare_sub $file $SUBNAME
elif [ -f "$file" ]; then
create_sub $file $SUBNAME $ENVNAME
fi
done
chmod_files $(echo $1 | sed "s/sub/$SUBNAME/g")
rm -rf $1
}
NAME="$1"
if [ -z "$NAME" ]; then
echo "usage: prepare.sh NAME_OF_YOUR_SUB" >&2
exit 1
fi
SUBNAME=$(echo $NAME | tr '[A-Z]' '[a-z]')
ENVNAME="$(echo $NAME | tr '[a-z-]' '[A-Z_]')_ROOT"
echo "Preparing your '$SUBNAME' sub!"
if [ "$NAME" != "sub" ]; then
rm bin/sub
mv share/sub share/$SUBNAME
for file in **/sub*; do
if [ -d "$file" ]; then
prepare_sub $file $SUBNAME
elif [ -f "$file" ]; then
create_sub $file $SUBNAME $ENVNAME
fi
done
chmod_files "libexec"
ln -s ../libexec/$SUBNAME bin/$SUBNAME
fi
rm README.md
rm prepare.sh
echo "Done! Enjoy your new sub! If you're happy with your sub, run:"
echo
echo " rm -rf .git"
echo " git init"
echo " git add ."
echo " git commit -m 'Starting off $SUBNAME'"
echo " ./bin/$SUBNAME init"
echo
echo "Made a mistake? Want to make a different sub? Run:"
echo
echo " git add ."
echo " git checkout -f"
echo
echo "Thanks for making a sub!"