-
Notifications
You must be signed in to change notification settings - Fork 1
/
gns3-installer.sh
executable file
·561 lines (458 loc) · 17.4 KB
/
gns3-installer.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
#!/bin/bash
# This script will attempt to install/uninstall the following software:
# GNS3 Network Simulator
# Dynamips Router Firmware Emulator
# VPCs Virtual PC Emulator
# As of this time only Ubunutu 14.04 ( or trusty derivatives ) are accepted.
# If your distro uses apt package manager, and you want to attempt to use this script, you need
# to edit a section. To do this run "lsb_release -a 2>/dev/null | grep Codename | cut -f2"
# in your terminal and then replace "trusty" ( on line 426 ) with the output from the command.
# Absolutely no guarantees it will work though.
#-----------------------------------------------------------------#
#-----------------------------------------------------------------#
#---###########################################################---#
#---##################### Functions Start #####################---#
#---###########################################################---#
#-----------------------------------------------------------------#
#-----------------------------------------------------------------#
#-----------------------------------------------------------------#
###################################################################
####################### Installer Functions #######################
############################# START ###############################
###################################################################
#-----------------------------------------------------------------#
# Dynamips installer function
function dynamips_install {
cd /tmp/gns3/GNS3*.source/dynamips*
mkdir build ; cd build
cmake ..
make
echo -e "\e[31m****** Installing Dynamips ******\e[0m "
sudo make install
echo
# Send System Notification
notify-send -t 4000 -u low -i $working_directory/dyn.png "Dynamips Installed"
echo -e "\e[32m****** Dynamips installed ******\e[0m "
echo
}
# GNS3 Server installer function
function gns3_srv_install {
cd /tmp/gns3/GNS3*.source/gns3-server*
echo -e "\e[31m****** Installing GNS Server ******\e[0m "
sudo python3 setup.py install
echo
echo -e "\e[32m****** GNS3 Server installed ******\e[0m "
}
# GUI install function
function gns3_gui_install {
cd /tmp/gns3/GNS3*.source/gns3-gui*
echo
echo -e "\e[31m****** Installing GNS GUI ******\e[0m "
sudo python3 setup.py install
echo
# Send System Notification
notify-send -t 4000 -u low -i $working_directory/gns3.png "GNS3 Installed"
echo -e "\e[32m****** GNS3 GUI installed ******\e[0m "
echo
}
# Function to create the desktop icon for gns3
function create_icon {
text="[Desktop Entry]\n
Name=GNS3\n
Comment=Graphical Network Simulator\n
Keywords=network;simulator\n
Exec=/usr/local/bin/gns3\n
Icon=/usr/share/applications/gns3.png\n
Terminal=false\n
Type=Application\n
StartupNotify=true\n
Categories=Development"
echo -e "\e[31m****** Creating an Application Icon for GNS3 ******\e[0m "
echo
sudo cp $working_directory/gns3.png /usr/share/applications
echo -e $text > $working_directory/gns3.desktop && sudo mv $working_directory/gns3.desktop /usr/share/applications
# Give the file the proper permissions
sudo chmod u+x /usr/share/applications/gns3.desktop
echo -e "\e[32m****** All Done ******\e[0m "
echo
}
# VPCS Installer function
function vpcs_install {
cd /tmp/gns3/GNS3*.source/vpcs*/src
echo -e "\e[31m****** Attempting to install VPCS ******\e[0m "
echo
if [ "$architecture" = "x86_64" ];then
echo -e "\e[34m****** 64 Bit Install ******\e[0m "
echo $(sudo ./mk.sh 64)
else
echo -e "\e[34m****** 32 Bit Install ******\e[0m "
echo $(sudo ./mk.sh 32 )
fi
# Copy the binary to /usr/bin
sudo cp vpcs /usr/bin
# Send System Notification
notify-send -t 4000 -u low -i $working_directory/vpcs.png "VPCS Installed"
echo -e "\e[93m****** Virtual PC is installed ******\e[0m "
echo
echo -e "\e[93m*** You can execute it from terminal by typing 'vpcs' and hitting enter ***\e[0m "
echo
}
#-----------------------------------------------------------------#
###################################################################
####################### Installer Functions #######################
############################## END ################################
###################################################################
#-----------------------------------------------------------------#
#-----------------------------------------------------------------#
###################################################################
##################### Uninstaller Functions #######################
############################ START ################################
###################################################################
#-----------------------------------------------------------------#
function gns3_uninstall {
gns3=$(which gns3)
pip3=$(which pip3)
# As long as GNS3 is installed, download and install Pip for the removal procedure
if [[ -z "$pip3" && -n "$gns3" ]]; then
echo -e "\e[32m*** Installing Pip ***\e[0m"
echo
sleep 1
# Use pip to uninstall package; Note that pip needs to be upgraded to latest release to work properly
sudo apt-get update && sudo apt-get install -y python3-pip && sudo easy_install3 -U pip
echo
echo -e "\e[32m*** Continuing ***\e[0m"
fi
# If GNS 3 is installed, continue. Otherwise exit
if [[ -n "$gns3" ]]; then
echo -e "\e[31m*** Removing GNS3 ***\e[0m"
# Uninstall GNS3
sudo -H pip3 uninstall -y gns3-server 2>/dev/null
sudo -H pip3 uninstall -y gns3-gui 2>/dev/null
sudo -H pip3 uninstall -y gns3-converter 2>/dev/null
sudo -H pip3 uninstall -y gns3dms gnsserver 2>/dev/null
# Remove unwanted files associated with GNS3
sudo rm /usr/local/bin/gns3
sudo rm -r ~/GNS3 2>/dev/null
sudo rm -r ~/.config/GNS3 2>/dev/null
sudo rm -r /usr/local/lib/python3.4/dist-packages/gns3*.egg 2>/dev/null
sudo rm /usr/share/app-install/icons/gns3.png 2>/dev/null
sudo rm /usr/share/app-install/desktop/gns3:gns3.desktop 2>/dev/null
echo
echo -e "\e[32m*** Uninstall GNS3 Complete ***\e[0m"
echo
# Remove the desktop entry and icon file
echo -e "\e[31m*** Removing Desktop Shortcut! ***\e[0m"
echo
sudo rm /usr/share/applications/gns3.desktop
sudo rm /usr/share/applications/gns3.png
echo -e "\e[32m*** Done ***\e[0m"
echo
else
echo -e "\e[31m*** Nothing to Uninstall ***\e[0m"
fi
}
function dyn_uninstall {
dyn=$(which dynamips)
# If Dynamips is installed, continue. Otherwise exit
if [[ -n "$dyn" ]]; then
# Remove the Dynamips binary and associated files/folders
echo -e "\e[31m*** Removing Dynamips ***\e[0m"
echo
sudo rm /usr/local/bin/dynamips
sudo rm -r /usr/local/share/doc/dynamips
sudo rm /usr/local/share/man/man1/dynamips.1
echo -e "\e[32m*** All Done ***\e[0m"
sleep 1
#echo -e "\e[32m*** Exiting ***\e[0m"
echo
else
echo -e "\e[31m*** Nothing to Uninstall ***\e[0m"
fi
}
function vpcs_uninstall {
vpcs=$(which vpcs)
# If VPCS is installed, continue. Otherwise exit
if [[ -n "$vpcs" ]]; then
# Remove the VPCS binary
echo -e "\e[31m*** Removing VPCS ***\e[0m"
sudo rm /usr/bin/vpcs
echo
echo -e "\e[32m** Done ***\e[0m"
echo
else
echo -e "\e[31m*** Nothing to Uninstall ***\e[0m"
fi
}
#-----------------------------------------------------------------#
###################################################################
##################### Uninstaller Functions #######################
############################# END #################################
###################################################################
#-----------------------------------------------------------------#
#-----------------------------------------------------------------#
###################################################################
############## Clean up and verification functions ################
###################################################################
#-----------------------------------------------------------------#
# Clean up function
function clean_up {
cd
echo -e "\e[31m****** House Cleaning! ******\e[0m "
echo
sudo rm -R /tmp/gns3
# Send System Notification
notify-send -t 5000 -u low "Cleanup Complete"
}
# Detects if the software has been installed correctly.
function sw_check {
# Check for GNS3
gns=$(which gns3)
gns_exit=$?
if [ -n "$gns" ]; then
echo -e "\e[32m****** GNS3 Install Successful! ******\e[0m ";echo
echo -e "\e[31m*** Exit status of command is $gns_exit\e[0m";echo
else
echo -e "\e[31mError, gns value = $gns\e[0m ";echo
echo -e "\e[31m*** Exit status of command is $gns_exit\e[0m";echo
fi
# Check for VPCS
vpc=$(which vpcs)
vpcs_exit=$?
if [ -n "$vpc" ]; then
echo -e "\e[32m****** VPCS Install Successful! ******\e[0m ";echo
echo -e "\e[31m*** Exit status of command is $vpcs_exit\e[0m";echo
else
echo -e "\e[31mError, vpcs value = $vpc\e[0m ";echo
echo -e "\e[31m*** Exit status of command is $vpcs_exit\e[0m";echo
fi
# Checks for Dynamips
dmips=$(which dynamips)
dyn_exit=$?
if [ -n "$dmips" ]; then
echo -e "\e[32m****** Dynamips Install Successful! ******\e[0m ";echo
echo -e "\e[31m*** Exit status of command is $dyn_exit\e[0m";echo
else
echo -e "\e[31mError, dynamips value = $dmips\e[0m ";echo
echo -e "\e[31m*** Exit status of command is $dyn_exit\e[0m";echo
fi
}
#-----------------------------------------------------------------#
###################################################################
######################### Exit Function ###########################
###################################################################
#-----------------------------------------------------------------#
function script_exit {
echo -e "\e[31m*** Don't forget to remove the Working Directory as it is no longer needed! ***\e[0m"
echo
end=$(date +%s)
runtime=$(($end-$start))
echo -e "\e[32m****** Total Runtime is "$runtime" sec's ******\e[0m"
echo
echo -e "\e[31m****** Exiting from the script! ******\e[0m "
exit 0
}
#-----------------------------------------------------------------#
#---###########################################################---#
#---##################### Functions END #######################---#
#---###########################################################---#
#-----------------------------------------------------------------#
#-----------------------------------------------------------------#
#------------------------################-------------------------#
#---#####################----------------######################---#
#---##################### Begin Main ######################---#
#---#####################----------------######################---#
#------------------------################-------------------------#
#-----------------------------------------------------------------#
#-----------------------------------------------------------------#
###################################################################
#################### Check For Arguments ##########################
###################################################################
#-----------------------------------------------------------------#
# Check for arguments, "U" switch will call the uninstaller if found
# If there are no arguments then continue with the installer
if [ "$#" -eq 0 ]; then
echo -e "\e[32m*** No arguments ***\e[0m"
# Set the start time
start=$(date +%s)
# Otherwise an argument was passed, process the argument
else
# If the argument is equal to U then run the uninstaller menu
if [ "$1" = "-U" ]; then
while true;
do
echo "Choose which packages you wish to remove :" ;echo
echo "[A]ll"
echo "[D]ynamips"
echo "[V]pcs"
echo "[G]NS3"
echo "[Q]uit" ;echo
read choice
# Match the response through case
case $choice in
[Aa]) # If user chooses All
start=$(date +%s)
gns3_uninstall
notify-send -t 4000 -u low "GNS3 Uninstall Complete"; sleep 1
dyn_uninstall
notify-send -t 4000 -u low "Dynamips Uninstall Complete"; sleep 1
vpcs_uninstall
notify-send -t 4000 -u low "VPCS Uninstall Complete"; sleep 1
end=$(date +%s)
runtime=$(($end-$start))
echo "took $runtime seconds"
exit 0
;;
[Dd]) # If user chooses Dynampis
start=$(date +%s)
dyn_uninstall
notify-send -t 4000 -u low "Dynamips Uninstall Complete"
end=$(date +%s)
runtime=$(($end-$start))
echo "took $runtime seconds"
continue
;;
[Vv]) # If user chooses VPCS
start=$(date +%s)
vpcs_uninstall
notify-send -t 4000 -u low "VPCS Uninstall Complete"
end=$(date +%s)
runtime=$(($end-$start))
echo "took $runtime seconds"
continue
;;
[Gg]) # If user chooses GNS3
start=$(date +%s)
gns3_uninstall
notify-send -t 4000 -u low "GNS3 Uninstall Complete"
end=$(date +%s)
runtime=$(($end-$start))
echo "took $runtime seconds"
continue
;;
[Qq]) # If user chooses Quit
exit 0
;;
*)
echo "Invalid Entry"
;;
# Close the case statement
esac
# Close the while loop
done
else
echo "Error, Invalid Argument "$1" "
exit 1
fi
fi
#-----------------------------------------------------------------#
###################################################################
########################## Check System ###########################
########################## Requirements ###########################
###################################################################
#-----------------------------------------------------------------#
distro=$(lsb_release -a 2>/dev/null | grep Codename | cut -f2)
echo $distro
# If it doesn't match requirements display error
if [[ "$distro" != *"trusty"* ]]; then
echo -e "\e[31m********* Error, Wrong Distro **********\e[0m "
sleep 1
echo
echo -e "\e[31m****** Quitting script! ******\e[0m "
echo
end=$(date +%s)
runtime=$(($end-$start))
echo -e "\e[32m****** Total Runtime is "$runtime" sec's ******\e[0m"
exit 1
fi
# Is it 32/64 bit?
architecture=$(arch)
# Find out which directory we are working from
working_directory=$PWD
#-----------------------------------------------------------------#
###################################################################
####### Create a working directory & download the source ##########
###################################################################
#-----------------------------------------------------------------#
# Create a temporary working directory and cd into it
mkdir /tmp/gns3/ 2>/dev/null
cd /tmp/gns3
# Download the required files
echo -e "\e[31mDownloading Files!\e[0m "
wget http://downloads.gns3.com/GNS3-1.2.3.source.zip -O gns.zip
echo
echo -e "\e[31mInitial download complete\e[0m"
echo
# Extract the main archive
unzip gns.zip
# Once extracted there is no need for the original zipfile, move to trash
rm gns.zip
# Change directory to the newly created and extract all the zipfiles
cd GNS3*.source
unzip "*.zip"
rm *.zip
#-----------------------------------------------------------------#
###################################################################
###################### Install Dependencies #######################
###################################################################
#-----------------------------------------------------------------#
# Request permission to continue installing packages
echo -e "\e[31mThe script needs to install dependencies\e[0m "
echo
# While loop to input and validate the response
while true; do
# Ask to install dependencies
echo -en "\e[31mEnter\e[0m \e[32myes\e[0m \e[31mto\e[0m \e[32mcontinue\e[0m \e[31mor\e[0m \e[93mno\e[0m \e[31mto\e[0m \e[93mquit : \e[0m "
read response
# Match the response through case
case $response in
[yY] | [yY][Ee][Ss]) # If YES/yes
echo "Continuing"
echo -e "\e[31mInstalling Packages, please be patient!\e[0m "
# Make sure to run apt-get update !
sudo apt-get update
# Install requirements, use Y switch to default to yes at prompt!
sudo apt-get install -y python3 libpcap-dev uuid-dev libelf-dev cmake python3-setuptools python3-pyqt4 python3-ws4py python3-zmq python3-tornado
sudo apt-get install -y python3-netifaces
echo
echo -e "\e[32m****** All done installing packages ******\e[0m "
echo
break
;;
# If NO/no
[nN] | [nN][Oo])
echo "Exiting Script"
cd
rm -R /tmp/gns3/GNS3-1.2.3.source
echo -e "\e[31mFolder removed\e[0m "
echo
end=$(date +%s)
runtime=$(($end-$start))
echo -e "\e[32m****** Total Runtime is "$runtime" sec's ******\e[0m"
exit 0
;;
# Anything else is invalid, repeat menu.
*)
echo "Invalid Input"
;;
# Close the case statement
esac
# Close the while loop
done
#-----------------------------------------------------------------#
###################################################################
#################### Call the Installer Functions #################
###################################################################
#-----------------------------------------------------------------#
# Array to hold the function calls
declare -a progs=( 'dynamips_install' 'vpcs_install' 'gns3_srv_install' 'gns3_gui_install' 'create_icon' 'clean_up' 'sw_check' 'script_exit')
# For loop to process the functions
for i in "${progs[@]}"; do
$i
done
#-----------------------------------------------------------------#
#------------------------################-------------------------#
#---#####################----------------######################---#
#---##################### End Main ######################---#
#---#####################----------------######################---#
#------------------------################-------------------------#
#-----------------------------------------------------------------#