XPost: comp.sys.laptops.thinkpad, comp.sys.laptops, comp.os.linux.admin
Got annoyed with ARP flux on home LAN, and too much xrandr, and wrote
the following for my ThinkPad 25 "fistula" running Gentoo.
I have a proper hardware dock on my office desk, a Thunderbolt wharf
in the living room, and various roaming scenarios sometimes with HDMI.
So far it seems reliable though much less declarative than my dream
scenario. Next, goal-seeking; or, NDP!
#!/bin/zsh -x
if [[ $ARGC -ne 1 ]]
then
>&2 echo usage: $0 '<scene>'
exit 64 # EX_USAGE
fi
scene=$1
ifup() {
[[ $ARGC -eq 1 ]] || exit 70 # EX_SOFTWARE
sudo ifconfig $1 up
until sudo ifconfig $1 | grep inet
do
sleep 12
done
}
ifdown() {
sudo ifconfig $1 down
}
ifas() {
[[ $ARGC -eq 3 ]] || exit 70 # EX_SOFTWARE
[[ -z $1 || $1 == $2 ]] || sudo ifconfig $1 $3
sudo arping -U -c 2 -I $2 $3
}
case $scene in
desk*|bolt*)
xrandr --output HDMI2 --off
;|
desk*)
ifup enp0s31f6
ifdown enp12s0u1
;|
bolt*)
ifup enp12s0u1
ifdown enp0s31f6
;|
desk|bolt)
sudo rfkill block wlan
;|
desk)
ifas enp0s31f6:0 enp0s31f6 fistula-wlan
;;
bolt)
ifas enp12s0u1:0 enp12s0u1 fistula-wlan
;;
free*)
xrandr --output HDMI2 --auto --output DP1-1 --off --output DP2-3 --off
;|
*ish|free*)
sudo rfkill unblock wlan
ifup wlp4s0
;|
*ish|free)
for if (enp12s0u1 enp0s31f6)
ifas '' $if fistula-wlan
;;
freer)
for if (enp0s31f6 enp12s0u1)
ifdown $if
ifas wlp4s0 wlp4s0 fistula-wlan
;;
turtle)
sudo rfkill block wlan
for if (enp0s31f6{,:0} enp12s0u1{,:0})
ifdown $if
xrandr --output HDMI2 --off --output DP1-1 --off --output DP2-3 --off
;;
*)
>&2 echo $0: unscene $scene
exit 65
esac
--
Tim Howe
http://quadium.net/~vsync/
To be nobody-but-yourself -- in a world which is doing its best,
night and day, to make you everybody else -- means to fight the
hardest battle which any human being can fight; and never stop
fighting.
-- E. E. Cummings
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)