84 |
eecho "DEBUG: ${@}" |
eecho "DEBUG: ${@}" |
85 |
} |
} |
86 |
|
|
87 |
|
# source a file with debug information |
88 |
|
include() |
89 |
|
{ |
90 |
|
local retval |
91 |
|
|
92 |
|
if [ -f $@ ] |
93 |
|
then |
94 |
|
decho "including '$@'" |
95 |
|
source $@ |
96 |
|
retval=$? |
97 |
|
else |
98 |
|
decho "include: '$@' not found" |
99 |
|
retval=1 |
100 |
|
fi |
101 |
|
|
102 |
|
return ${retval} |
103 |
|
} |
104 |
|
|
105 |
# adds a line to a configuration file defined by the $CONFIG variable |
# adds a line to a configuration file defined by the $CONFIG variable |
106 |
# $CONFIG="/etc/conf.d/mcore" addconfig 'LIBDIR="/usr/lib"' |
# $CONFIG="/etc/conf.d/mcore" addconfig 'LIBDIR="/usr/lib"' |
107 |
addconfig() |
addconfig() |
149 |
# this wrapper runs a command in the xsession of the unpriv_user |
# this wrapper runs a command in the xsession of the unpriv_user |
150 |
x11runas() |
x11runas() |
151 |
{ |
{ |
152 |
if [[ -n $(pidof X) ]] |
if [[ -n $(pidof X) ]] || [[ -n $(pidof Xorg) ]] |
153 |
then |
then |
154 |
su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" |
su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" |
155 |
fi |
fi |
253 |
|
|
254 |
chroot ${MROOT} ${cmd} |
chroot ${MROOT} ${cmd} |
255 |
} |
} |
256 |
|
|
257 |
|
# gets interface used to reach given ip |
258 |
|
iface_for_remote_addr() |
259 |
|
{ |
260 |
|
set -- $(ip -o route get to $1) |
261 |
|
echo $5 |
262 |
|
} |
263 |
|
|
264 |
|
# get ip from dns name |
265 |
|
dns_to_ip() |
266 |
|
{ |
267 |
|
set -- $(getent hosts $1) |
268 |
|
echo $1 |
269 |
|
} |
270 |
|
|
271 |
|
iface_for_ip() |
272 |
|
{ |
273 |
|
set -- $(ip -o addr show to $1) |
274 |
|
echo $2 |
275 |
|
} |
276 |
|
|
277 |
|
iface_for_mac() |
278 |
|
{ |
279 |
|
local interface="" mac="$(echo $1 | sed 'y/ABCDEF/abcdef/')" |
280 |
|
for interface in /sys/class/net/*; do |
281 |
|
if [ $(cat $interface/address) = "$mac" ]; then |
282 |
|
echo ${interface##*/} |
283 |
|
fi |
284 |
|
done |
285 |
|
} |
286 |
|
|
287 |
|
mac_for_iface() |
288 |
|
{ |
289 |
|
local iface="$1" |
290 |
|
if [ -f /sys/class/net/${iface}/address ] |
291 |
|
then |
292 |
|
cat /sys/class/net/${iface}/address |
293 |
|
fi |
294 |
|
} |