forked from atheurer/trafficgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-trex.sh
executable file
·93 lines (87 loc) · 1.99 KB
/
install-trex.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
#!/bin/bash
base_dir="/opt/trex"
tmp_dir="/tmp"
trex_ver="v2.46"
opts=$(getopt -q -o c: --longoptions "tmp-dir:,base-dir:,version:" -n "getopt.sh" -- "$@")
if [ $? -ne 0 ]; then
printf -- "$*\n"
printf -- "\n"
printf -- "\tThe following options are available:\n\n"
printf -- "\n"
printf -- "--tmp-dir=str\n"
printf -- " Directory where temporary files should be stored.\n"
printf -- " Default is ${tmp_dir}\n"
printf -- "\n"
printf -- "--base-dir=str\n"
printf -- " Directory where TRex will be installed.\n"
printf -- " Default is ${base_dir}\n"
printf -- "\n"
printf -- "--version=str\n"
printf -- " Version of TRex to install\n"
printf -- " Default is ${trex_ver}\n"
exit 1
fi
eval set -- "$opts"
while true; do
case "${1}" in
--tmp-dir)
shift
if [ -n "${1}" ]; then
tmp_dir=${1}
shift
fi
;;
--base-dir)
shift
if [ -n "${1}" ]; then
base_dir=${1}
shift
fi
;;
--version)
shift
if [ -n "${1}" ]; then
trex_ver=${1}
shift
fi
;;
--)
break
;;
*)
if [ -n "${1}" ]; then
echo "ERROR: Unrecognized option ${1}"
fi
exit 1
;;
esac
done
trex_url=http://trex-tgn.cisco.com/trex/release/${trex_ver}.tar.gz
trex_dir="${base_dir}/${trex_ver}"
if [ -d ${trex_dir} ]; then
echo "TRex ${trex_ver} already installed"
else
mkdir -p ${base_dir}
if pushd ${base_dir} >/dev/null; then
tarfile="${tmp_dir}/${trex_ver}.tar.gz"
/bin/rm -f ${tarfile}
if wget -O ${tarfile} ${trex_url} && tar zxf ${tarfile}; then
/bin/rm ${tarfile}
echo "installed TRex from ${trex_url}"
else
echo "ERROR: could not install TRex ${trex_ver}"
exit 1
fi
popd >/dev/null
else
echo "ERROR: Could not use ${base_dir}"
exit 1
fi
fi
# we need a symlink so our trex scripts can always point to
# same location for trex
if pushd ${base_dir} >/dev/null; then
/bin/rm -f current 2>/dev/null
ln -sf ${trex_ver} current
popd >/dev/null
fi