}
-# sk on all the files in current git repo (except those excluded)
+# sk on all the files in current git repo
skgit() {
- local f toplevel orig_dir tmp skip pattern
- local -a ls_files excludes sk_files
+ local f toplevel orig_dir tmp
+ local -a ls_files sk_files
toplevel=$(git rev-parse --show-toplevel)
if [[ $PWD != "$toplevel" ]]; then
orig_dir=$PWD
cd $toplevel
fi
- excludes=(
- 'disabled/*'
- )
- tmp=$(git ls-files | shuf)
+ # tracked & untracked files
+ tmp=$(git ls-files && git ls-files --others --exclude-standard)
mapfile -t ls_files <<<"$tmp"
for f in "${ls_files[@]}"; do
- skip=false
- for pattern in "${excludes[@]}"; do
- if [[ $f == $pattern ]]; then
- skip=true
- break
- fi
- done
- if $skip; then continue; fi
if sk-p "$f"; then
sk_files+=("$f")
fi
sle() { # sl emacs
local f=/home/iank/.emacs.d/init.el
- sl --sl-test-cmd ". /etc/os-release ; printf %s \${VERSION//[^a-zA-Z0-9]/}; test -e $f && stat -c%Y $f" --sl-test-hook slemacs "$@"
+ sl --sl-test-cmd "sed -rn '/^VERSION=/{s/^.*=//;s/[^[:alnum:]]//gp}' /etc/os-release; test -e $f && stat -c%Y $f" --sl-test-hook slemacs "$@"
}
ccomp ssh sle
host-info-all() {
host-info-update
bindpushb8
- ssh li.b8.nz conflink
+ ssh iank@li.b8.nz conflink
wrt-setup
}
host-info-update() {
local -A vpn_ips host_ips host_macs nonvpn_ips all_ips
- local -a root_hosts nonroot_hosts
+ local -a root_hosts nonroot_hosts host_usbs
# the hosts with no mac
root_hosts=( bk je li b8.nz )
else
nonroot_hosts+=($host ${host}i)
fi
-
host_ips[$host]=$ip
- host_macs[$host]=$mac
+ if [[ $mac ]]; then
+ host_macs[$host]=$mac
+ fi
+
done </p/c/host-info
{
ipsuf=${vpn_ips[$host]}
i_port=$(( 2200 + ipsuf ))
cat <<EOF
- config redirect
- option name ssh$host
- option src wan
- option src_dport $i_port
- option dest_port 22
- option dest_ip \$l.$ipsuf
- option dest lan
- config rule
- option src wan
- option target ACCEPT
- option dest_port $i_port
+config redirect
+option name ssh$host
+option src wan
+option src_dport $i_port
+option dest_port 22
+option dest_ip \$l.$ipsuf
+option dest lan
+config rule
+option src wan
+option target ACCEPT
+option dest_port $i_port
EOF
done
echo "EOF"
echo "EOF"
} | u /p/c/dnsmasq-data
+
b8_ip=$(dig +short b8.nz @iankelling.org | tail -1)
if [[ ! $b8_ip ]]; then
echo "$0: error: got empty b8.nz ip. returning 1"
x2|x3|sy|so)
if [[ $(dig +short @10.2.0.1 -x 10.2.0.2 2>&1 ||:) == kd.b8.nz. ]] \
&& ip n show 10.2.0.1 | grep . &>/dev/null; then
+ # note: logic duplicated in 11-iank
at_home=true
elif ping -q -c1 -w1 hal.office.fsf.org &>/dev/null \
&& ip n show 192.168.0.26 | grep . &>/dev/null; then
client-to-client
EOF
-
- ngset
- files=(/etc/openvpn/client-config-hole/*)
- if (( ${#files[@]} >= 1 )); then
- rm -f ${files[@]}
- fi
- ngreset
- for host in ${!vpn_ips[@]}; do
- sd /etc/openvpn/client-config-hole/$host <<EOF
-ifconfig-push 10.5.5.${vpn_ips[$host]} 255.255.255.0
-EOF
- done
+ # note client-config files are setup in brc2 update-host-info
# for adding cert to system with /p
# See the License for the specific language governing permissions and
# limitations under the License.
-source ~/.bashrc
-
if [[ ! -e /dev/shm/iank-status ]]; then
exit 0
fi
--- /dev/null
+#!/bin/bash
+# I, Ian Kelling, follow the GNU license recommendations at
+# https://www.gnu.org/licenses/license-recommendations.en.html. They
+# recommend that small programs, < 300 lines, be licensed under the
+# Apache License 2.0. This file contains or is part of one or more small
+# programs. If a small program grows beyond 300 lines, I plan to switch
+# its license to GPL.
+
+# Copyright 2024 Ian Kelling
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
+shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+
+[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
+
+
+sed -i --follow-symlinks '/^[^#/]/s/^/#/' /etc/network/interfaces.d/ethusb
--- /dev/null
+#!/bin/bash
+# I, Ian Kelling, follow the GNU license recommendations at
+# https://www.gnu.org/licenses/license-recommendations.en.html. They
+# recommend that small programs, < 300 lines, be licensed under the
+# Apache License 2.0. This file contains or is part of one or more small
+# programs. If a small program grows beyond 300 lines, I plan to switch
+# its license to GPL.
+
+# Copyright 2024 Ian Kelling
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
+shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+
+[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
+
+
+shopt -s nullglob
+
+# we already configured the interface once, afterwards, comment and
+# uncomment to enable/disable. This makes it so we don't depend on /p
+# being mounted.
+
+if [[ -s /etc/network/interfaces.d/ethusb ]]; then
+ sed -i --follow-symlinks 's/^#//' /etc/network/interfaces.d/ethusb
+ exit 0
+fi
+
+
+while read -r ip host mac; do
+ if [[ $mac != usb ]]; then
+ continue
+ fi
+ if [[ $host = ${HOSTNAME}c ]]; then
+ usbip=$ip
+ break
+ fi
+done </p/c/host-info
+
+if [[ ! $usbip ]]; then
+ exit 0
+fi
+
+ethx=0
+
+# device that has an eth0, but we aren't using it because it is
+# broken. We could just hardcode a mac comparison with `cat
+# /sys/class/net/eth0/address` but this is cooler.
+if [[ -e /sys/class/net/eth0 ]]; then
+ bus_info=$(ethtool -i eth0 | awk '$1 == "bus-info:" { print $2 }')
+ if [[ $bus_info != usb* ]]; then
+ ethx=1
+ fi
+fi
+
+cat >/etc/network/interfaces.d/ethusb <<EOF
+auto eth$ethx
+iface eth$ethx inet static
+ address 10.2.0.$ip/16
+ gateway 10.2.0.1
+EOF
--- /dev/null
+ifconfig-push 10.5.5.32 255.255.255.0
--- /dev/null
+ifconfig-push 10.5.5.29 255.255.255.0
--- /dev/null
+ifconfig-push 10.5.5.34 255.255.255.0
--- /dev/null
+ifconfig-push 10.5.5.2 255.255.255.0
--- /dev/null
+ifconfig-push 10.5.5.3 255.255.255.0
--- /dev/null
+ifconfig-push 10.5.5.7 255.255.255.0
--- /dev/null
+ifconfig-push 10.5.5.23 255.255.255.0
--- /dev/null
+ifconfig-push 10.5.5.8 255.255.255.0
# note: turn this into an array if we ever add more
my_lib_files=/a/bin/bash-bear-trap/bash-bear
-all_my_scripts=("${my_service_scripts[@]}" "${my_bin_files[@]}" $my_lib_files)
--- /dev/null
+#!/bin/bash
+
+this_file="$(readlink -f -- "${BASH_SOURCE[0]}")"
+readonly this_file this_dir="${this_file%/*}"
+cd "$this_dir"
+
+. .bashrc
+
+# "a", as in, pass to sk -a
+a_files=(
+ brc2
+ install-my-scripts
+)
+
+a_sourced_files=(
+ script-files
+ beet-data
+)
+
+declare -a ls_files standard_files
+
+# so, shellcheck doesn't like files that declare variables that are just
+# used in other files that source them. Using -a like this is the only
+# way to solve it. We can't just -a on everything because then we would
+# get various files I didn't write and that don't pass shellcheck.
+sk -a ${a_files[@]}
+
+
+tmp=$(git ls-files && git ls-files --others --exclude-standard)
+mapfile -t ls_files <<<"$tmp"
+for f in "${ls_files[@]}"; do
+ skip=false
+ for fignore in ${a_files[@]} ${a_sourced_files[@]}; do
+ if [[ $f == "$fignore" ]]; then
+ skip=true
+ break
+ fi
+ done
+ if $skip; then continue; fi
+ if sk-p "$f"; then
+ standard_files+=("$f")
+ fi
+done
+
+sk "${standard_files[@]}"
if grep -qxF $HOSTNAME $x; then all_dirs+=( ${x%.hosts} ); fi
done
+ script_files=("${my_service_scripts[@]}" "${my_bin_files[@]}" $my_lib_files)
+
# Just because i forget a lot, -mmin -NUM means files modified <= NUM minutes ago
- if (( fmin < 0 )) && [[ $(find ${all_my_scripts[@]} ${all_dirs[@]} -mmin $fmin -type f -print -quit 2>/dev/null) ]]; then
+ if (( fmin < 0 )) && [[ $(find "${script_files[@]}" ${all_dirs[@]} -mmin $fmin -type f -print -quit 2>/dev/null) ]]; then
v conflink newer filesystem files
chars+=(CONFLINK)
break