forked from virtimus/i3c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap-dtb.sh
106 lines (96 loc) · 3.67 KB
/
bootstrap-dtb.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
echo "###################################################################################";
echo "";
echo " BOOTSTRAP-DTB.SH - Start ...";
echo "###################################################################################";
#set
_fixWinPath(){
name=$1;
value=$2;
#cho $name': '$value
valuer=${value//\\/\/}
valuer=${valuer,[A-Z]}
valuer=${valuer/:/}
valuer='/'$valuer
#cho $name': '$valuer
if [ "$3" == "1" ]; then
if [ ! -e "$valuer" ]; then
echo "Problem with $name ($value:$valuer).";
echo "Check if folder exists on Your host machine and is properly linked/mounted to bash shell.";
exit 1;
fi
fi
eval "$name='$valuer'"
return 0;
}
dtInstallPath=$VBOX_INSTALL_PATH
if [ "x$dtInstallPath" == "x" ]; then
dtInstallPath=$VBOX_MSI_INSTALL_PATH;
fi
if [ "x$dtInstallPath" == "x" ]; then
echo "Problem with VBOX_INSTALL_PATH/VBOX_MSI_INSTALL_PATH.";
echo "Check if DockerToolBox/VirtualBox is installed.";
exit 1;
fi
STEP="Processing environment paths ..."
_fixWinPath 'I3C_ROOT_PATH' "$I3C_ROOT_WIN" 1;
echo 'I3C_ROOT_WIN: '$I3C_ROOT_WIN;
echo 'I3C_ROOT_PATH: '$I3C_ROOT_PATH;
_fixWinPath 'VBOX_INSTALL_PATH' "$dtInstallPath" 1;
echo 'VBOX_INSTALL_PATH: '$VBOX_INSTALL_PATH;
_fixWinPath 'DOCKER_TOOLBOX_INSTALL_PATH' "$DOCKER_TOOLBOX_INSTALL_PATH" 1;
echo 'DOCKER_TOOLBOX_INSTALL_PATH: '$DOCKER_TOOLBOX_INSTALL_PATH;
_fixWinPath 'DOCKER_CERT_PATH' "$DOCKER_CERT_PATH" 1;
echo 'DOCKER_CERT_PATH: '$DOCKER_CERT_PATH;
#_fixWinPath 'DOCKER_HOST' $WINDHOST;
echo 'DOCKER_HOST: '$DOCKER_HOST;
#_fixWinPath 'DOCKER_MACHINE_NAME' $WINDMNAME;
echo 'DOCKER_MACHINE_NAME: '$DOCKER_MACHINE_NAME;
#_fixWinPath 'DOCKER_TLS_VERIFY' $WINDTVERIFY;
echo 'DOCKER_TLS_VERIFY: '$DOCKER_TLS_VERIFY;
echo 'WINUSERNAME: '$WINUSERNAME;
echo 'LUSERNAME: '$LUSERNAME;
STEP="Adding shared folder to docker machine"
docker-machine stop
"$VBOX_INSTALL_PATH\VBoxManage" sharedfolder add "$DOCKER_MACHINE_NAME" --name i3c --hostpath "$I3C_ROOT_WIN" --automount
docker-machine start
STEP="Creating i3cRoot/bootstrap ..."
tPath="$I3C_ROOT_PATH/env.sh";
echo "#!/bin/bash" > $tPath
echo "export I3C_ROOT_PATH='/mnt$I3C_ROOT_PATH'" >> $tPath
echo "export DOCKER_HOST='$DOCKER_HOST'" >> $tPath
echo "export DOCKER_MACHINE_NAME='$DOCKER_MACHINE_NAME'" >> $tPath
echo "export DOCKER_TLS_VERIFY=$DOCKER_TLS_VERIFY" >> $tPath
echo "export VBOX_INSTALL_PATH='/mnt$VBOX_INSTALL_PATH'" >> $tPath
echo "export DOCKER_CERT_PATH='/mnt$DOCKER_CERT_PATH'" >> $tPath
echo "export DOCKER_TOOLBOX_INSTALL_PATH='/mnt$DOCKER_TOOLBOX_INSTALL_PATH'" >> $tPath
echo "export WINUSERNAME='$WINUSERNAME'" >> $tPath
printf "if [ ! -e /i ] || [ ! -L /i ]; then\n curl -sSL https://raw.githubusercontent.com/virtimus/i3c/master/bootstrap-wsl.sh | bash;\n fi\n" >> $tPath
echo "end0."
exit 0;
STEP="Merging environment paths into .bashrc ..."
rPath=/c/Users/$WINUSERNAME/AppData/Local/lxss/$LUSERNAME;
echo 'Bash profile path: '$rPath;
#tPath=$rPath/.i3cbashrc
tPath2=/c/Users/$WINUSERNAME/AppData/Local/lxss/$LUSERNAME/.i3cbashrc.tmp
tPathT=/c/Users/$WINUSERNAME/AppData/Local/lxss/$LUSERNAME/.bashrc
exs=$(grep '### BEGIN I3C AUTOCONF ###' $tPathT);
if [ "x$exs" == "x" ]; then
echo "### BEGIN I3C AUTOCONF ###" >> $tPathT
cat $tPath >> $tPathT
echo "### END I3C AUTOCONF ###" >> $tPathT
else
echo "Section present."
#nc=$(cat $tPath);
#perl -0777 -i -pe "s/(### BEGIN I3C AUTOCONF ###\\n).*(\\n### END I3C AUTOCONF ###)/\$1$nc\$2/s" $tPathT
lead='^### BEGIN I3C AUTOCONF ###$'
tail='^### END I3C AUTOCONF ###$'
sed -e "/$lead/,/$tail/{ /$lead/{p; r $tPath
}; /$tail/p; d }" $tPathT > $tPath2
dtnow=$(date +%Y%m%d%H%M%S);
cp $tPathT $tPathT.$dtnow.bak
cat $tPath2 > $tPathT
rm $tPath2
#echo $ret > $tPathT
fi
echo "end."