-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsl-install-2.sh
executable file
·155 lines (131 loc) · 4.28 KB
/
wsl-install-2.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
set -e
if ! id -nG | grep -q docker; then
# restart script with docker group:
echo 'Please run wsl-install-1.sh first!!!'
exit 1
fi
mkdir -p ~/www/global
mkdir -p ~/www/project
cd ~/www/global/
if [ -f .env ]; then
. .env
fi
NAME=$(git config --global user.name || true)
EMAIL=$(git config --global user.email || true)
git config --global init.defaultBranch main
if [ -z "$NAME" ]; then
read -p "What is your name (Format like this: Matthias Vogel): " NAME
git config --global user.name "$NAME"
fi
if [ -z "$EMAIL" ]; then
read -p "What is your email address (Format like this: m.vogel@andersundsehr.com): " EMAIL
git config --global user.email "$EMAIL"
fi
if [ -z "$TLD_DOMAIN" ]; then
read -p "What is your TLD_DOMAIN https://jira.pluswerk.ag/wiki/display/AUSW/VM+Nummern (Format like this: vm23.iveins.de): " TLD_DOMAIN
echo "TLD_DOMAIN=$TLD_DOMAIN" >> .env
echo "HTTPS_MAIN_DOMAIN=$TLD_DOMAIN" >> .env
fi
if [ -z "$DNS_CLOUDFLARE_API_TOKEN" ]; then
read -p "DNS_CLOUDFLARE_API_TOKEN: " DNS_CLOUDFLARE_API_TOKEN
echo "DNS_CLOUDFLARE_API_TOKEN=$DNS_CLOUDFLARE_API_TOKEN" >> .env
fi
if [ -z "$SENTRY_DSN" ]; then
read -p "SENTRY_DSN: " SENTRY_DSN
echo "SENTRY_DSN=$SENTRY_DSN" >> .env
fi
if [ ! -f /home/user/.ssh/id_ed25519 ]; then
ssh-keygen -t ed25519 -a 100 -C "$EMAIL" -f /home/user/.ssh/id_ed25519 -N ''
echo "-------------"
echo "-------------"
echo "-------------"
echo "-------------"
echo "-------------"
echo "add your SSH key to https://github.com/settings/ssh/new and https://bitbucket.org/account/settings/ssh-keys/"
echo "-------------"
echo "-------------"
echo "-------------"
echo ""
echo "public key:"
cat /home/user/.ssh/id_ed25519.pub
read -p "Press any key to continue... " -n1 -s
echo ""
fi
if [ ! -f /home/user/.ssh/id_rsa ]; then
ssh-keygen -t rsa -b 4096 -C "$EMAIL" -f /home/user/.ssh/id_rsa -N ''
fi
# make user sudo without password.
echo "$USER ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/$USER 1> /dev/null
# install wudo
if ! [ -x "$(command -v wudo)" ]; then
curl -fsSL https://raw.githubusercontent.com/Chronial/wsl-sudo/master/wsl-sudo.py | sudo tee /usr/local/bin/wudo 1> /dev/null
sudo chmod +x /usr/local/bin/wudo
fi
# install inotify
if ! [ -x "$(command -v inotifywait)" ]; then
sudo apt update -y
sudo apt install inotify-tools -y
fi
# install docker
if ! [ -x "$(command -v docker)" ]; then
curl -fsSL https://get.docker.com/ | sudo sh
fi
# configure docker
if [ ! -f /etc/docker/daemon.json ]; then
echo '{"log-driver": "local", "log-opts": {"max-size": "10m"}}' | sudo tee /etc/docker/daemon.json 1> /dev/null
sudo systemctl restart docker
fi
# configure composer
if [ ! -f ~/.composer/auth.json ]; then
mkdir -p ~/.composer/cache
rm -rf ~/.composer/auth.json
echo '{}' > ~/.composer/auth.json
fi
# clone global
if [ ! -d .git ]; then
git clone --no-checkout git@github.com:pluswerk/docker-global.git ./a
mv ./a/.git ./
rm -r a
git restore --staged .
git restore .
fi
# make docker-compose work
if [ ! -f /usr/local/bin/docker-compose ]; then
sudo ln -s $(pwd)/bin/docker-compose /usr/local/bin/docker-compose
fi
function addOnceToFile() {
if [ ! -f $1 ]; then
touch $1
fi
if ! grep -Fxq "$2" $1
then
echo "$2" | sudo tee -a $1 1> /dev/null
fi
}
# install bashrc files
addOnceToFile ~/.bashrc 'source ~/www/global/bashrc-files/.bashrc-ssh-agent'
addOnceToFile ~/.bashrc 'source ~/www/global/bashrc-files/.bashrc-cd'
addOnceToFile ~/.bashrc 'source ~/www/global/bashrc-files/.bashrc-windows-hosts-sync'
# configure wsl
addOnceToFile /etc/wsl.conf '[network]'
addOnceToFile /etc/wsl.conf 'generateHosts = false'
# run hosts file sync now
source bashrc-files/.bashrc-windows-hosts-sync
if ! ssh -o PasswordAuthentication=no root@20.13.155.71 -p221 echo '1' 1> /dev/null ; then
echo "-------------"
echo "-------------"
echo "-------------"
echo "-------------"
echo "-------------"
echo 'ask a colleague to add your SSH Key to the vm-proxy'
echo "ssh root@20.13.155.71 -p221"
read -p "Press any key to continue... " -n1 -s
ssh -o PasswordAuthentication=no root@20.13.155.71 -p221 echo '1'
fi
#start docker global
bash start.sh pull
bash start.sh up
echo "wait for 30s (to create certificates)"
sleep 30
echo "start https://dozzle.$TLD_DOMAIN and check if it is working"