-
Notifications
You must be signed in to change notification settings - Fork 0
/
rebuild-provision.sh
executable file
·64 lines (53 loc) · 1.5 KB
/
rebuild-provision.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
#!/usr/bin/env bash
PROVISION_PATH=`pwd`/.provision/;
PROVISION_FIRST_LINE='config.vm.provision "shell", inline: <<-SHELL'
PROVISION_LAST_LINE=' SHELL'
VAGRANT_FILE=/vagrant/Vagrantfile
VAGRANT_FILE_TMP=/vagrant/Vagrantfile.tmp
chmod 744 $PROVISION_PATH*.sh
cp $VAGRANT_FILE $VAGRANT_FILE_TMP
SED_STRING='/'$PROVISION_FIRST_LINE'/,/'$PROVISION_LAST_LINE'/d'
SED_STRING="${SED_STRING//\./\\.}"
sed -i "$SED_STRING" $VAGRANT_FILE_TMP
sed -i '/^end$/d' $VAGRANT_FILE_TMP
LINE=$(grep "$PROVISION_FIRST_LINE" $VAGRANT_FILE)
if [ "$LINE" = "" ]
then
LINE=" # "$PROVISION_FIRST_LINE
fi
echo "$LINE" >> $VAGRANT_FILE_TMP
LINE=$(grep "apt-get update" $VAGRANT_FILE)
if [ "$LINE" = "" ]
then
LINE=" # apt-get update"
fi
echo "$LINE" >> $VAGRANT_FILE_TMP
LINE=$(grep "cd `pwd`/.provision/" $VAGRANT_FILE)
if [ "$LINE" = "" ]
then
LINE=" # cd `pwd`/.provision/"
fi
echo "$LINE" >> $VAGRANT_FILE_TMP
for file in $PROVISION_PATH*.sh
do
FILE_NAME=`basename $file`
LINE=$(grep -m 1 "$FILE_NAME" $VAGRANT_FILE)
if [ "$LINE" = "" ]
then
LINE=" # ./"$FILE_NAME
fi
echo "$LINE" >> $VAGRANT_FILE_TMP
done
LINE=$(grep "$PROVISION_LAST_LINE" $VAGRANT_FILE)
if [ "$LINE" = "" ]
then
LINE=" # "$PROVISION_LAST_LINE
fi
echo "$LINE" >> $VAGRANT_FILE_TMP
if [ `grep "BASH_ENV=/etc/profile exec bash" $VAGRANT_FILE_TMP | wc -l` = 0 ]
then
echo "config.ssh.shell = \"bash -c 'BASH_ENV=/etc/profile exec bash'\"" >> $VAGRANT_FILE_TMP
fi
echo "end" >> $VAGRANT_FILE_TMP
rm $VAGRANT_FILE
mv $VAGRANT_FILE_TMP $VAGRANT_FILE