-
Notifications
You must be signed in to change notification settings - Fork 1
/
bashrc
293 lines (277 loc) · 9.02 KB
/
bashrc
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
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
if [ "$TERM" = "vt102" ]; then
export TERM=vte-256color
eval `dircolors -b .dir_colors`
alias ls="ls --color=auto"
fi
alias grep='/bin/grep --color=tty '
alias vi=vim
export EDITOR=vim
RDMA_LOOKASIDE="http://beaker.ofa.iol.unh.edu/fsdp_setup"
get_file() {
rm -f `basename "$1"`
wget -q "${RDMA_LOOKASIDE}/$1"
}
get_dir() {
EXT=""
[ -n $2 ] && EXT="-A$2"
wget -qr -l1 -np -nd -nH $EXT "${RDMA_LOOKASIDE}/$1"
}
__show_link_state='
BEGIN {
printf "%s:", dev;
if (length(dev) < 23) printf "\t";
if (length(dev) < 15) printf "\t";
if (length(dev) < 7) printf "\t";
}
/NO-CARRIER/ && /[\<,]UP[\>,]/ { printf "No Link, Interface UP\t" };
/LOWER_UP/ && /[\<,]UP[\>,]/ { printf "Link UP, Interface UP\t" };
/NO-CARRIER/ && !/[\<,]UP[\>,]/ { printf "No Link, Interface Down\t" };
/LOWER_UP/ && !/[\<,]UP[\>,]/ { printf "Link UP, Interface Down\t" };
!/LOWER_UP|NO-CARRIER/ { printf "%s\tInterface off\t", $2 };
'
__show_ip_addr='
BEGIN { once = 0 }
/ inet / { if (once == 0) { once = 1; printf "%s", $2 }
else printf ", %s", $2 }
END { printf "\n" }
'
_show_ib_dev_state() {
ip -o link show $1 | awk -v dev=$1 "$__show_link_state"
ip addr show $1 | awk "$__show_ip_addr"
}
_ib_dev() {
i=`ip -o link show $1 2>/dev/null | awk -F ': ' '{ print $2 }' | cut -f 1 -d '@'`
[ -n "$i" ] && _show_ib_dev_state $i
}
ib() {
local prefix=`ip -o link show | grep -v "\@.*ib0:" | grep -w ".*_ib0:" | awk -F ': ' '{ print $2 }' | cut -f 1 -d '_'`
for dev in ib0 ib0.800{2,4,6} ib0_1 ib0_1.800{2,4,6} ib0_2 ib0_2.800{2,4,6} ib0_3 ib0_3.800{2,4,6} ib0_4 ib0_4.800{2,4,6}; do
_ib_dev ${prefix}_${dev}
done
}
opa() {
local prefix=`ip -o link show | grep -v "\@.*opa0:" | grep -w ".*_opa0:" | awk -F ': ' '{ print $2 }' | cut -f 1 -d '_'`
for dev in opa0 opa0.8022 opa0.8024; do
_ib_dev ${prefix}_${dev}
done
}
_show_en_dev_state() {
ip -o link show $1 | head -n 1 | awk -v dev=$1 "$__show_link_state"
ip addr show $1 | awk "$__show_ip_addr"
if [ `ip -o link show $1 | tail -n +2 | wc -l` -gt 0 ]; then
ip -o link show $1 | tail -n +2
fi
}
en() {
local prefix
for dev in lab-bridge0 lom_1; do
i=`ip -o link show $dev 2>/dev/null | awk -F ': ' '{ print $2 }'`
[ -n "$i" ] && _show_en_dev_state $i && break
done
prefix=`ip -o link show | grep -v "\@.*roce:" | grep -w ".*_roce:" | awk -F ': ' '{ print $2 }' | cut -f 1 -d '_'`
if [ -n "$prefix" ]; then
for dev in roce roce.4{3,5} roce.{50..52}; do
i=`ip -o link show ${prefix}_${dev} 2>/dev/null | awk -F ': ' '{ print $2 }' | cut -f 1 -d '@'`
[ -n "$i" ] && _show_en_dev_state $i
done
fi
prefix=`ip -o link show | grep -v "\@.*roce_1:" | grep -w ".*_roce_1:" | awk -F ': ' '{ print $2 }' | cut -f 1 -d '_'`
if [ -n "$prefix" ]; then
for dev in roce_1 roce_1.4{3,5}; do
i=`ip -o link show ${prefix}_${dev} 2>/dev/null | awk -F ': ' '{ print $2 }' | cut -f 1 -d '@'`
[ -n "$i" ] && _show_en_dev_state $i
done
fi
prefix=`ip -o link show | grep -v "\@.*roce_2:" | grep -w ".*_roce_2:" | awk -F ': ' '{ print $2 }' | cut -f 1 -d '_'`
if [ -n "$prefix" ]; then
for dev in roce_2 roce_2.4{3,5}; do
i=`ip -o link show ${prefix}_${dev} 2>/dev/null | awk -F ': ' '{ print $2 }' | cut -f 1 -d '@'`
[ -n "$i" ] && _show_en_dev_state $i
done
fi
prefix=`ip -o link show | grep -v "\@.*roce_3:" | grep -w ".*_roce_3:" | awk -F ': ' '{ print $2 }' | cut -f 1 -d '_'`
if [ -n "$prefix" ]; then
for dev in roce_3 roce_3.4{3,5}; do
i=`ip -o link show ${prefix}_${dev} 2>/dev/null | awk -F ': ' '{ print $2 }' | cut -f 1 -d '@'`
[ -n "$i" ] && _show_en_dev_state $i
done
fi
prefix=`ip -o link show | grep -v "\@.*roce_4:" | grep -w ".*_roce_4:" | awk -F ': ' '{ print $2 }' | cut -f 1 -d '_'`
if [ -n "$prefix" ]; then
for dev in roce_4 roce_4.4{3,5}; do
i=`ip -o link show ${prefix}_${dev} 2>/dev/null | awk -F ': ' '{ print $2 }' | cut -f 1 -d '@'`
[ -n "$i" ] && _show_en_dev_state $i
done
fi
prefix=`ip -o link show | grep -v "\@.*iw:" | grep -w ".*_iw:" | awk -F ': ' '{ print $2 }' | cut -f 1 -d '_'`
if [ -n "$prefix" ]; then
for dev in iw iw.5{1,2}; do
i=`ip -o link show ${prefix}_${dev} 2>/dev/null | awk -F ': ' '{ print $2 }' | cut -f 1 -d '@'`
[ -n "$i" ] && _show_en_dev_state $i
done
fi
for dev in slave1 slave2 slave3 slave4; do
i=`ip -o link show | grep -w ".*$dev" | grep -v "@.*$dev" | awk -F ': ' '{ print $2 }' | cut -f 1 -d '@'`
[ -n "$i" ] && _show_en_dev_state $i
done
}
clean_kernels() {
VERSIONS=`rpm -q --queryformat="%{version}-%{release}.%{arch}\n" kernel | sort -V --reverse`
RUNNING_VER=`uname -r`
# We want to leave these kernels:
# 1) The running kernel
# 2) The most recent RPM kernel
# 3) The most recent devel kernel (if any installed)
# 4) One backup RPM kernel
rpm_running=0
latest_rpm_ver=""
backup_rpm_ver=""
latest_devel_ver=""
i=0
for ver in $VERSIONS; do
let i++
[ $ver = $RUNNING_VER ] && rpm_running=$i
done
i=0
for ver in $VERSIONS; do
let i++
if [ $i -eq 1 ]; then
echo "Keeping latest RPM kernel $ver"
latest_rpm_ver=$ver
elif [ $i -eq 2 -a $rpm_running -le 1 ]; then
echo "Keeping backup RPM kernel $ver"
backup_rpm_ver=$ver
elif [ $i -eq $rpm_running ]; then
echo "Keeping running RPM kernel $ver"
backup_rpm_ver=$ver
else
echo -n "Removing kernel RPM $ver..."
# This will remove *all* kernel* packages with this
# release string, including things like kernel-tools
# which are not usually installed multiple times.
# This is OK because we always keep the most recent
# RPM, which is the only version of things like
# kernel-tools that is supposed to be installed
rpm -qa | grep $ver | xargs rpm -e
echo "done."
fi
done
pushd /boot
# Remove all of the kdump images and rescue images, this needs to
# be before the next step or it pollutes our version list
rm -f *kdump.img *-rescue-*
# We should only have two rpm versions still installed, so all of
# the vmlinuz- files in /boot should belong to either one of those
# two rpms, or devel kernels. We assume that the total list of
# kernels minus the two saved rpm versions is our list of devel
# kernels, then we sort those to get the two most recent ones
VERSIONS=""
for i in vmlinuz-*; do
ver=`echo $i | cut -f 2- -d '-'`
[ -z "$ver" ] && continue
if [ $ver = "$latest_rpm_ver" ]; then
echo "Skipping $ver, not a devel kernel"
continue
elif [ $ver = "$backup_rpm_ver" ]; then
echo "Skipping $ver, not a devel kernel"
continue
fi
echo "Adding devel kernel $ver"
if [ -z "$VERSIONS" ]; then
VERSIONS="$ver"
else
VERSIONS="$VERSIONS $ver"
fi
done
VERSIONS=`echo $VERSIONS | tr '[:blank:]' '\n' | sort -V --reverse`
i=0
for ver in $VERSIONS; do
let i++
if [ $i -eq 1 -a $ver = "$RUNNING_VER" ]; then
echo "Keeping latest/running devel kernel $ver"
latest_devel_ver=$ver
elif [ $i -eq 1 ]; then
echo "Keeping latest devel kernel $ver"
latest_devel_ver=$ver
elif [ $ver = "$RUNNING_VER" ]; then
echo "Keeping running devel kernel $ver"
elif [ $ver = "$latest_rpm_ver" ]; then
echo "Keeping latest RPM kernel $ver"
elif [ $ver = "$backup_rpm_ver" ]; then
echo "Keeping backup RPM kernel $ver"
else
echo "Removing devel kernel $ver"
rm -f /boot/*${ver}*
rm -fr /lib/modules/${ver}
fi
done
# Now remove the possible stale symlinks
find . -maxdepth 1 -type l -delete
popd
pushd /lib/modules
shopt -s nullglob
for i in *; do
if [ $i = "$latest_rpm_ver" ]; then
echo "Keeping latest RPM kernel $i module dir"
elif [ $i = "$backup_rpm_ver" ]; then
echo "Keeping backup RPM kernel $i module dir"
elif [ $i = "$latest_devel_ver" ]; then
echo "Keeping latest devel kernel $i module dir"
elif [ $i = $RUNNING_VER ]; then
echo "Keeping running devel kernel $i module dir"
else
echo "Removing unknown/stale module dir $i"
rm -fr $i
fi
done
shopt -u nullglob
popd
[ -d /boot/grub2 ] && grub2-mkconfig -o /boot/grub2/grub.cfg
}
grub2_set_boot() {
grep ^menuentry /boot/grub2/grub.cfg | awk -v version=$1 \
'BEGIN {
i = 0
}
{
if (index($0, version)) {
printf "Found "version" at index "i" in ";
printf "grub2.cfg; setting default boot\n";
exit(system("grub2-set-default "i));
}
i++
}'
}
# idk - Install Development Kernel
# Install a development kernel from a git repo. Check for space first,
# run clean_kernels above if less than 100MB is available on /boot.
idk() {
avail=$(df --output=avail /boot | tail -1)
[ "$avail" -lt 102400 ] && clean_kernels
make -j64 modules_install
restorecon -v -R /lib/firmware /lib/modules
make install
ins_ver=$(eval echo $(cat include/generated/utsrelease.h | \
awk '{ print $3 }'))
# Grub2 support is here...need to add support for more boot
# loaders
[ -f /boot/grub2/grub.cfg ] && grub2_set_boot $ins_ver
}
if [ ! -x "`which rhts-reboot`" ]; then
function rhts-reboot()
{
if [ "$1" = "-r" ]; then
if [ -f /root/EFI_BOOT_ENTRY.TXT ]; then
efibootmgr -n `cat /root/EFI_BOOT_ENTRY.TXT`
else
efibootmgr -n `efibootmgr | grep BootCurrent | cut -f 2`
fi
fi
/sbin/shutdown $*
}
fi