-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagw_install_ubuntu.sh
213 lines (182 loc) · 6.82 KB
/
agw_install_ubuntu.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
# Copyright 2021 The Magma Authors.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Setting up env variable, user and project path
set -x
addr1="$1"
gw_addr="$2"
MAGMA_USER="magma"
AGW_INSTALL_CONFIG_LINK="/etc/systemd/system/multi-user.target.wants/agw_installation.service"
AGW_INSTALL_CONFIG="/lib/systemd/system/agw_installation.service"
AGW_SCRIPT_PATH="/root/agw_install_ubuntu.sh"
DEPLOY_PATH="/home/$MAGMA_USER/magma/lte/gateway/deploy"
SUCCESS_MESSAGE="ok"
NEED_REBOOT=0
WHOAMI=$(whoami)
MAGMA_VERSION="${MAGMA_VERSION:-v1.8}"
CLOUD_INSTALL="cloud"
GIT_URL="${GIT_URL:-https://github.com/magma/magma.git}"
#INTERFACE_DIR="/etc/network/interfaces.d"
echo "Checking if the script has been executed by root user"
if [ "$WHOAMI" != "root" ]; then
echo "You're executing the script as $WHOAMI instead of root.. exiting"
exit 1
fi
echo "Checking if Ubuntu is installed"
if ! grep -q 'Ubuntu' /etc/issue; then
echo "Ubuntu is not installed"
exit 1
fi
#if [ "$SKIP_PRECHECK" != "$SUCCESS_MESSAGE" ]; then
# wget https://raw.githubusercontent.com/magma/magma/"$MAGMA_VERSION"/lte/gateway/deploy/agw_pre_check_ubuntu.sh
# if [[ -f ./agw_pre_check_ubuntu.sh ]]; then
# bash agw_pre_check_ubuntu.sh
# while true; do
# read -p "Do you accept those modifications and want to proceed with magma installation?(y/n)" yn
# case $yn in
# [Yy]* ) break;;
# [Nn]* ) exit;;
# * ) echo "Please answer yes or no.";;
# esac
# done
# else
# echo "agw_pre_check_ubuntu.sh is not available in your version"
# fi
#fi
apt-get update
#echo "Need to check if both interfaces are named eth0 and eth1"
#INTERFACES=$(ip -br a)
#if [[ $1 != "$CLOUD_INSTALL" ]] && ( [[ ! $INTERFACES == *'eth0'* ]] || [[ ! $INTERFACES == *'eth1'* ]] || ! grep -q 'GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"' /etc/default/grub); then
# changing intefaces name
# sed -i 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"/g' /etc/default/grub
# sed -i 's/enp0s3/eth0/g' /etc/netplan/50-cloud-init.yaml
# # changing interface name
# grub-mkconfig -o /boot/grub/grub.cfg
# name server config
# ln -sf /var/run/systemd/resolve/resolv.conf /etc/resolv.conf
# sed -i 's/#DNS=/DNS=8.8.8.8 208.67.222.222/' /etc/systemd/resolved.conf
# service systemd-resolved restart
# interface config
# apt install -y ifupdown net-tools ipcalc
# mkdir -p "$INTERFACE_DIR"
#echo "source-directory $INTERFACE_DIR" > /etc/network/interfaces
#if [ -z "$addr1" ] || [ -z "$gw_addr" ]
#then
# DHCP allocated interface IP
# echo "auto eth0
# iface eth0 inet dhcp" > "$INTERFACE_DIR"/eth0
#else
# Statically allocated interface IP
# if ipcalc -c "$addr1" | grep INVALID
# then
# echo "Interface ip is not valid IP"
# exit 1
#fi
#if ipcalc -c "$gw_addr" | grep INVALID
#then
# echo "Upstream Router ip is not valid IP"
# exit 1
#fi
#addr=$( ipcalc -n "$addr1" | grep Address | awk '{print $2}')
#netmask=$(ipcalc -n "$addr1" | grep Netmask | awk '{print $2}')
#gw_addr=$(ipcalc -n "$gw_addr"| grep Address | awk '{print $2}')
#echo "auto eth0
#iface eth0 inet static
#address $addr
#netmask $netmask
#gateway $gw_addr" > "$INTERFACE_DIR"/eth0
#fi
# configuring eth1
#echo "auto eth1
#iface eth1 inet static
#address 10.0.2.1
#netmask 255.255.255.0" > "$INTERFACE_DIR"/eth1
# get rid of netplan
#systemctl unmask networking
#systemctl enable networking
#apt-get --assume-yes purge nplan netplan.i
# Setting REBOOT flag to 1 because we need to reload new interface and network services.
#NEED_REBOOT=1
#else
# echo "Interfaces name are correct, let's check if network and DNS are up"
# while ! nslookup google.com; do
# echo "DNS not reachable"
# sleep 1
#done
#while ! ping -c 1 -W 1 -I eth0 8.8.8.8; do
# echo "Network not ready yet"
# sleep 1
#done
#fi
echo "Making sure $MAGMA_USER user is sudoers"
if ! grep -q "$MAGMA_USER ALL=(ALL) NOPASSWD:ALL" /etc/sudoers; then
apt install -y sudo
adduser --disabled-password --gecos "" $MAGMA_USER
adduser $MAGMA_USER sudo
echo "$MAGMA_USER ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
fi
#if [ $NEED_REBOOT = 1 ]; then
# echo "Will reboot in a few seconds, loading a boot script in order to install magma"
# if [ ! -f "$AGW_SCRIPT_PATH" ]; then
# cp "$(realpath $0)" "${AGW_SCRIPT_PATH}"
#fi
#cat <<EOF > $AGW_INSTALL_CONFIG
#[Unit]
#D#escription=AGW Installation
#After=network-online.target
#Wants=network-online.target
#[Service]
#Environment=MAGMA_VERSION=${MAGMA_VERSION}
#Environment=GIT_URL=${GIT_URL}
#Environment=REPO_PROTO=${REPO_PROTO}
#Environment=REPO_HOST=${REPO_HOST}
#Environment=REPO_DIST=${REPO_DIST}
#Environment=REPO_COMPONENT=${REPO_COMPONENT}
#Environment=REPO_KEY=${REPO_KEY}
#Environment=REPO_KEY_FINGERPRINT=${REPO_KEY_FINGERPRINT}
#Environment=SKIP_PRECHECK=${SUCCESS_MESSAGE}
#Type=oneshot
#ExecStart=/bin/bash ${AGW_SCRIPT_PATH}
#TimeoutStartSec=3800
#TimeoutSec=3600
#User=root
#Group=root
#[Install]
#WantedBy=multi-user.target
#EOF
# chmod 644 $AGW_INSTALL_CONFIG
# ln -sf $AGW_INSTALL_CONFIG $AGW_INSTALL_CONFIG_LINK
# reboot
#fi
#echo "Checking if magma has been installed"
#MAGMA_INSTALLED=$(apt-cache show magma > /dev/null 2>&1 echo "$SUCCESS_MESSAGE")
#if [ "$MAGMA_INSTALLED" != "$SUCCESS_MESSAGE" ]; then
# echo "Magma not installed, processing installation"
apt-get -y install curl make virtualenv zip rsync git software-properties-common python3-pip python-dev apt-transport-https
alias python=python3
pip3 install ansible==5.10.0
git clone "${GIT_URL}" /home/$MAGMA_USER/magma
cd /home/$MAGMA_USER/magma || exit
git checkout "$MAGMA_VERSION"
echo "Generating localhost hostfile for Ansible"
echo "[magma_deploy]
127.0.0.1 ansible_connection=local" > $DEPLOY_PATH/agw_hosts
# install magma and its dependencies including OVS.
su - $MAGMA_USER -c "ansible-playbook -e \"MAGMA_ROOT='/home/$MAGMA_USER/magma' OUTPUT_DIR='/tmp'\" -i $DEPLOY_PATH/agw_hosts $DEPLOY_PATH/magma_deploy.yml"
echo "Cleanup temp files"
cd /root || exit
rm -rf $AGW_INSTALL_CONFIG
rm -rf /home/$MAGMA_USER/build
rm -rf /home/$MAGMA_USER/magma
echo "AGW installation is done, Run agw_post_install_ubuntu.sh install script after reboot to finish installation"
#wget https://raw.githubusercontent.com/magma/magma/"$MAGMA_VERSION"/lte/gateway/deploy/agw_post_install_ubuntu.sh -P /root/
#reboot
#else
# echo "Magma already installed, skipping.."
#fi