Created
July 29, 2020 11:25
-
-
Save lemmi/7839e6d5b6b0cffd41da4edef20996d7 to your computer and use it in GitHub Desktop.
connect to any freifunk franken hood
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| KEYSRV_URL="https://keyserver.freifunk-franken.de/v2" | |
| KEYSRV_URL_HOODS="${KEYSRV_URL}/hoods.php" | |
| KEYSRV_URL_HOODFILE="${KEYSRV_URL}/index.php?hoodid=" | |
| TMP_DIR=$(mktemp -d) | |
| cleanup() { | |
| rm -R "${TMP_DIR}" | |
| } | |
| trap cleanup EXIT | |
| select_hood() { | |
| local -A hoods | |
| while read id name; do | |
| hoods[$name]=$id | |
| done < <(curl -s $KEYSRV_URL_HOODS | jq -r '.[] | @text "\(.id) \(.name)"') | |
| PS3="Select hood: " | |
| select hood in $(for h in ${!hoods[@]}; do echo $h; done | sort); do | |
| echo ${hoods[$hood]} | |
| break | |
| done | |
| } | |
| get_peers() { | |
| local hoodId=$1 | |
| mkdir "${TMP_DIR}/peers" | |
| curl -s "${KEYSRV_URL_HOODFILE}${hoodId}" \ | |
| | jq -r '.vpn[]|(@text "\(.name) \(.key) \(.address) \(.port)")' \ | |
| | while read name key address port; do | |
| cat <<- EOF > "${TMP_DIR}/peers/$name" | |
| key "${key}"; | |
| remote "${address}" port ${port}; | |
| EOF | |
| cat "${TMP_DIR}/peers/$name" | |
| done | |
| } | |
| run_fastd() { | |
| local fastdconf="${TMP_DIR}/fastd-$1.conf" | |
| cat <<- EOF > "${fastdconf}" | |
| interface "fastd-$1"; | |
| method "null"; | |
| secret "$(fastd --generate-key --machine-readable)"; | |
| mtu 1426; | |
| secure handshakes no; | |
| on establish "ip link set fastd-$1 up"; | |
| on up "batctl meshif bat0 if add fastd-$1; ip link set bat0 up"; | |
| on post-down "ip link del dev bat0"; | |
| EOF | |
| fastd --config "${fastdconf}" --config-peer-dir "${TMP_DIR}/peers" | |
| } | |
| main() { | |
| local hoodId | |
| hoodId=$(select_hood) | |
| get_peers $hoodId | |
| run_fastd $hoodId | |
| } | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment