Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
This and that
Browse files Browse the repository at this point in the history
  • Loading branch information
ozfox committed Oct 21, 2024
1 parent 262c90d commit d02f070
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
123 changes: 123 additions & 0 deletions node/code/dev/border_router/start_network.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env bash

USB_CDC_ECM_DIR="$(dirname "$(readlink -f "$0")")"

INTERFACE_CHECK_COUNTER=5 # 5 attempts to find usb interface

find_interface() {
INTERFACE=$(ls -A /sys/bus/usb/drivers/cdc_ether/*/net/ 2>/dev/null)
INTERFACE_CHECK=$(echo -n "${INTERFACE}" | head -c1 | wc -c)
if [ "${INTERFACE_CHECK}" -eq 0 ] && [ ${INTERFACE_CHECK_COUNTER} != 0 ]; then
# We want to have multiple opportunities to find the USB interface
# as sometimes it can take a few seconds for it to enumerate after
# the device has been flashed.
sleep 1
((INTERFACE_CHECK_COUNTER=INTERFACE_CHECK_COUNTER-1))
find_interface
fi
INTERFACE=${INTERFACE%/}
}

echo "Waiting for network interface."
find_interface

if [ "${INTERFACE_CHECK}" -eq 0 ]; then
echo "Unable to find network interface"
exit 1
else
echo "Found interface: ${INTERFACE}"
fi

setup_interface() {
sysctl -w net.ipv6.conf."${INTERFACE}".forwarding=1
sysctl -w net.ipv6.conf."${INTERFACE}".accept_ra=0
ip link set "${INTERFACE}" up
ip a a fe80::1/64 dev "${INTERFACE}"
ip a a fd00:dead:beef::1/128 dev lo
}

cleanup_interface() {
ip a d fe80::1/64 dev "${INTERFACE}"
ip a d fd00:dead:beef::1/128 dev lo
ip route del "${PREFIX}" via fe80::2 dev "${INTERFACE}"
}

cleanup() {
echo "Cleaning up..."
cleanup_interface
if [ -n "${UHCPD_PID}" ]; then
kill "${UHCPD_PID}"
fi
if [ -n "${DHCPD_PIDFILE}" ]; then
kill "$(cat "${DHCPD_PIDFILE}")"
rm "${DHCPD_PIDFILE}"
fi
trap "" INT QUIT TERM EXIT
}

start_uhcpd() {
ip route add "${PREFIX}" via fe80::2 dev "${INTERFACE}"
${UHCPD} "${INTERFACE}" "${PREFIX}" > /dev/null &
UHCPD_PID=$!
}

start_dhcpd() {
ip route add "${PREFIX}" via fe80::2 dev "${INTERFACE}"
DHCPD_PIDFILE=$(mktemp)
${DHCPD} -d -p "${DHCPD_PIDFILE}" "${INTERFACE}" "${PREFIX}" 2> /dev/null
}

start_radvd() {
ADDR=$(echo "${PREFIX}" | sed -e 's/::\//::1\//')
ip a a "${ADDR}" dev "${INTERFACE}"
sysctl net.ipv6.conf."${INTERFACE}".accept_ra=2
sysctl net.ipv6.conf."${INTERFACE}".accept_ra_rt_info_max_plen=64
${RADVD} -c "${INTERFACE}" "${PREFIX}"
}

if [ "$1" = "-d" ] || [ "$1" = "--use-dhcpv6" ]; then
USE_DHCPV6=1
shift 1
else
USE_DHCPV6=0
fi

if [ "$1" = "-r" ] || [ "$1" = "--use-radvd" ]; then
USE_RADVD=1
shift 1
else
USE_RADVD=0
fi

PREFIX=$1
[ -z "${PREFIX}" ] && {
echo "usage: $0 [-d|--use-dhcpv6] [-r|--use-radvd ] <prefix> [<serial-port>]"
exit 1
}

if [ -n "$2" ]; then
PORT=$2
fi

trap "cleanup" INT QUIT TERM EXIT

setup_interface

if [ ${USE_DHCPV6} -eq 1 ]; then
DHCPD="$(readlink -f "${USB_CDC_ECM_DIR}/../dhcpv6-pd_ia/")/dhcpv6-pd_ia.py"
start_dhcpd
elif [ ${USE_RADVD} -eq 1 ]; then
RADVD="$(readlink -f "${USB_CDC_ECM_DIR}/../radvd/")/radvd.sh"
start_radvd
else
UHCPD="$(readlink -f "${USB_CDC_ECM_DIR}/../uhcpd/bin")/uhcpd"
start_uhcpd
fi

if [ -z "${PORT}" ]; then
echo "Network enabled over CDC-ECM"
echo "Press Return to stop"
read -r
else
"${USB_CDC_ECM_DIR}/../pyterm/pyterm" -p "${PORT}"
fi
6 changes: 6 additions & 0 deletions platform/create-certs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
openssl genrsa -out ./data/ssl/certs/server.key 2048
openssl req -new -out ./data/ssl/certs/server.csr -key ./data/ssl/certs/server.key -config ./data/ssl/openssl.cnf
openssl x509 -req -days 3650 -in ./data/ssl/certs/server.csr -signkey ./data/ssl/certs/server.key -out ./data/ssl/certs/server.crt -extensions v3_req -extfile ./data/ssl/openssl.cnf

#openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ./data/nginx.key -out ./data/ssl/nginx.crt
3 changes: 3 additions & 0 deletions web_backend/build-and-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
echo $TEAMAGOCHI_TOKEN | docker login ghcr.io -u ozfox --password-stdin
./mvnw install -Dquarkus.profile=prod,publish

0 comments on commit d02f070

Please sign in to comment.