This commit is contained in:
Bob Mottram 2018-03-08 12:11:41 +00:00
commit fcff148f07
8 changed files with 161 additions and 77 deletions

View File

@ -373,19 +373,49 @@ function mesh_install_dat {
#!/bin/bash
npm install --arch=$NPM_ARCH -g dat
npm install --arch=$NPM_ARCH -g @garbados/dat-boi
npm install --arch=$NPM_ARCH -g add-to-systemd
add-to-systemd dat-boi --user "$(whoami)" "$(which dat-boi)"
EOF
chroot "$rootdir" /bin/chmod +x /usr/bin/install_dat
chroot "$rootdir" /usr/bin/install_dat
rm "$rootdir/usr/bin/install_dat"
{ echo '[Unit]';
echo 'Description=DAT-boi';
echo 'After=syslog.target';
echo 'After=network.target';
echo '';
echo '[Service]';
echo 'Type=simple';
echo 'User=root';
echo 'Group=root';
echo 'ExecStart=/usr/local/bin/dat-boi';
echo 'Restart=always';
echo '';
echo '[Install]';
echo 'WantedBy=multi-user.target'; } > "$rootdir/etc/systemd/system/dat-boi.service"
chmod +x "$rootdir/etc/systemd/system/dat-boi.service"
chroot "$rootdir" systemctl enable dat-boi
}
function install_dat {
npm install -g dat
npm install -g @garbados/dat-boi
npm install -g add-to-systemd
add-to-systemd dat-boi --user "$(whoami)" "$(which dat-boi)"
{ echo '[Unit]';
echo 'Description=DAT-boi';
echo 'After=syslog.target';
echo 'After=network.target';
echo '';
echo '[Service]';
echo 'Type=simple';
echo 'User=root';
echo 'Group=root';
echo 'ExecStart=/usr/local/bin/dat-boi';
echo 'Restart=always';
echo '';
echo '[Install]';
echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/dat-boi.service
chmod +x /etc/systemd/system/dat-boi.service
systemctl enable dat-boi
}
function mesh_install_scuttlebot {

View File

@ -143,11 +143,11 @@ BMX7_COMMIT='0a82c7c10fef44b259b35e77ab33632aa132d219'
PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
function configure_backports {
configure_backports() {
echo "deb http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-backports main" >> "$rootdir/etc/apt/sources.list"
}
function configure_contrib_repo {
configure_contrib_repo() {
if ! grep -q "contrib" "$rootdir/etc/apt/sources.list"; then
chroot "$rootdir" /bin/sed -i "s| main| main contrib|g" /etc/apt/sources.list
fi
@ -973,6 +973,18 @@ initialise_mesh() {
MESH_STARTUP_PARAMS="${MY_USERNAME} amnesic"
fi
# command to switch to wired mesh
{ echo '#!/bin/bash';
echo 'echo -n "eth" > /root/.mesh_interface_type';
echo 'systemctl reboot -i'; } > "$rootdir/usr/bin/wired"
chmod +x "$rootdir/usr/bin/wired"
# command to switch to wireless mesh
{ echo '#!/bin/bash';
echo 'echo -n "wlan" > /root/.mesh_interface_type';
echo 'systemctl reboot -i'; } > "$rootdir/usr/bin/wireless"
chmod +x "$rootdir/usr/bin/wireless"
{ echo '[Unit]';
echo 'Description=Initial mesh router configuration';
echo 'After=syslog.target';
@ -995,7 +1007,7 @@ initialise_mesh() {
# User interface for USB drive installs ######################################
function mesh_client_startup_applications {
mesh_client_startup_applications() {
if [ ! -d "$rootdir/home/$MY_USERNAME/Desktop" ]; then
mkdir -p "$rootdir/home/$MY_USERNAME/Desktop"
fi
@ -1074,7 +1086,7 @@ function mesh_client_startup_applications {
chmod +x "$START_DESKTOP2"
}
function mesh_desktop_icons {
mesh_desktop_icons() {
if [ ! -d "$rootdir/home/$MY_USERNAME/Desktop" ]; then
mkdir -p "$rootdir/home/$MY_USERNAME/Desktop"
fi
@ -1092,7 +1104,7 @@ function mesh_desktop_icons {
chroot "$rootdir" /bin/chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/Desktop"
}
function configure_user_interface {
configure_user_interface() {
if [[ "$VARIANT" != "meshclient" && "$VARIANT" != "meshusb" && "$VARIANT" != "usb" ]]; then
return
fi
@ -1630,7 +1642,7 @@ EOF
# setup_utils
##############################################################################
function image_install_inadyn {
image_install_inadyn() {
if [ "$INSTALLING_MESH" ]; then
return
fi
@ -1693,7 +1705,7 @@ function image_install_inadyn {
echo "inadyn commit:$INADYN_COMMIT" >> "$rootdir/root/freedombone-completed.txt"
}
function image_setup_utils {
image_setup_utils() {
if [ "$INSTALLING_MESH" ]; then
return
fi
@ -1881,12 +1893,12 @@ function image_setup_utils {
#sed -i 's|btrfs subvol=@|btrfs defaults,subvol=@,compress=lzo,ssd|g' $rootdir/etc/fstab
}
function image_install_nodejs {
image_install_nodejs() {
mesh_install_nodejs
#echo 'install_nodejs' >> ${rootdir}/root/${PROJECT_NAME}-completed.txt
}
function image_preinstall_repos {
image_preinstall_repos() {
if [[ "$VARIANT" == "mesh"* ]]; then
return
fi

View File

@ -193,7 +193,7 @@ fi
echo $'Changing values within customised customisation script'
cp "$PROJECT_INSTALL_DIR/${PROJECT_NAME}-image-customise" "$TEMP_CUSTOMISE3"
if [ "$MYUSERNAME" ]; then
sed -i "s|MY_USERNAME=.*|MY_USERNAME=${MYUSERNAME}|g" "$TEMP_CUSTOMISE3"
sed -i "0,/MY_USERNAME=.*/s//MY_USERNAME=${MYUSERNAME}/" "$TEMP_CUSTOMISE3"
fi
if [ "$MYPASSWORD" ]; then
sed -i "s|MY_PASSWORD=.*|MY_PASSWORD=${MYPASSWORD}|g" "$TEMP_CUSTOMISE3"
@ -211,7 +211,7 @@ sed -i "s|CONFIG_FILENAME=.*|CONFIG_FILENAME=${CONFIG_FILENAME}|g" "$TEMP_CUSTOM
sed -i "s|SSH_PUBKEY=.*|SSH_PUBKEY=${SSH_PUBKEY}|g" "$TEMP_CUSTOMISE3"
sed -i "s|GENERIC_IMAGE=.*|GENERIC_IMAGE=${GENERIC_IMAGE}|g" "$TEMP_CUSTOMISE3"
sed -i "s|MINIMAL_INSTALL=.*|MINIMAL_INSTALL=\"${MINIMAL_INSTALL}\"|g" "$TEMP_CUSTOMISE3"
sed -i "s|SSH_PORT=.*|SSH_PORT=\"${SSH_PORT}\"|g" "$TEMP_CUSTOMISE3"
sed -i "0,/SSH_PORT=.*/s//SSH_PORT=\"${SSH_PORT}\"/" "$TEMP_CUSTOMISE3"
sed -i "s|ONION_ONLY=.*|ONION_ONLY=\"${ONION_ONLY}\"|g" "$TEMP_CUSTOMISE3"
sed -i "s|PROJECT_REPO=.*|PROJECT_REPO=\"${PROJECT_REPO}\"|g" "$TEMP_CUSTOMISE3"
sed -i "s|DEBIAN_INSTALL_ONLY=.*|DEBIAN_INSTALL_ONLY=\"${DEBIAN_INSTALL_ONLY}\"|g" "$TEMP_CUSTOMISE3"

View File

@ -8,7 +8,7 @@
#
# Freedom in the Cloud
#
# Used to enable or disable batman mesh protocol on wlanX
# Used to enable or disable batman mesh protocol on a given interface
#
# License
# =======
@ -34,22 +34,12 @@ COMPLETION_FILE="/root/${PROJECT_NAME}-completed.txt"
# hotspot passphrase must be 5 characters or longer
HOTSPOT_PASSPHRASE="${PROJECT_NAME}"
# The type of interface which the mesh will run on
MESH_INTERFACE_TYPE='wlan'
source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-wifi
source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-mesh
mesh_protocol_init
update_wifi_adaptors
if [ ! "$IFACE" ]; then
echo $'No wlan adaptor'
exit 0
fi
if [ -e /etc/default/batctl ]; then
# shellcheck disable=SC1091
. /etc/default/batctl
fi
function status {
batctl o
@ -84,15 +74,17 @@ function stop {
# shellcheck disable=SC2153
if [ "$EIFACE" ]; then
brctl delif "$BRIDGE" bat0
ifconfig "$BRIDGE" down || true
ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier")
if [[ "$ethernet_connected" != "0" ]]; then
systemctl stop hostapd
brctl delif "$BRIDGE" "$EIFACE"
ifconfig "$EIFACE" down -promisc
if [[ "$EIFACE" != "$IFACE" ]] ; then
brctl delif "$BRIDGE" bat0
ifconfig "$BRIDGE" down || true
ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier")
if [[ "$ethernet_connected" != "0" ]]; then
systemctl stop hostapd
brctl delif "$BRIDGE" "$EIFACE"
ifconfig "$EIFACE" down -promisc
fi
brctl delbr "$BRIDGE"
fi
brctl delbr "$BRIDGE"
fi
ifconfig bat0 down -promisc
@ -100,7 +92,9 @@ function stop {
batctl if del "$IFACE"
ifconfig "$IFACE" mtu 1500
ifconfig "$IFACE" down
iwconfig "$IFACE" mode managed
if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
iwconfig "$IFACE" mode managed
fi
if [ "$IFACE_SECONDARY" ]; then
systemctl stop hostapd
@ -108,7 +102,9 @@ function stop {
batctl if del "$IFACE_SECONDARY"
ifconfig "$IFACE_SECONDARY" mtu 1500
ifconfig "$IFACE_SECONDARY" down
iwconfig "$IFACE_SECONDARY" mode managed
if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
iwconfig "$IFACE_SECONDARY" mode managed
fi
fi
rmmod batman-adv
@ -159,8 +155,10 @@ function add_wifi_interface {
fi
ifconfig "$ifname" hw ether "$peermac"
echo $"$ifname assigned MAC address $peermac"
iwconfig "$ifname" enc off
iwconfig "$ifname" mode "$ifmode" essid "$ifssid" channel "$ifchannel"
if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
iwconfig "$ifname" enc off
iwconfig "$ifname" mode "$ifmode" essid "$ifssid" channel "$ifchannel"
fi
batctl if add "$ifname"
ifconfig "$ifname" up
@ -168,7 +166,7 @@ function add_wifi_interface {
# shellcheck disable=SC2120
function start {
update_wifi_adaptors
update_wifi_adaptors "${MESH_INTERFACE_TYPE}"
if [ -z "$IFACE" ] ; then
echo 'error: unable to find wifi interface, not enabling batman-adv mesh'
@ -194,13 +192,15 @@ function start {
rfkill unblock "$(rfkill list|awk -F: "/phy/ {print $1}")" || true
secondary_wifi_available=
if [ "$IFACE_SECONDARY" ]; then
if [[ "$IFACE" != "$IFACE_SECONDARY" ]]; then
if [ -d /etc/hostapd ]; then
if [ ${#HOTSPOT_PASSPHRASE} -gt 4 ]; then
secondary_wifi_available=1
else
echo $'Hotspot passphrase is too short'
if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
if [ "$IFACE_SECONDARY" ]; then
if [[ "$IFACE" != "$IFACE_SECONDARY" ]]; then
if [ -d /etc/hostapd ]; then
if [ ${#HOTSPOT_PASSPHRASE} -gt 4 ]; then
secondary_wifi_available=1
else
echo $'Hotspot passphrase is too short'
fi
fi
fi
fi
@ -229,21 +229,23 @@ function start {
ifconfig bat0 0.0.0.0
ethernet_connected='0'
if [ "$EIFACE" ] ; then
ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier")
if [[ "$ethernet_connected" != "0" ]]; then
echo $'Trying ethernet bridge to the internet'
brctl addif "$BRIDGE" "$EIFACE"
ifconfig "$EIFACE" 0.0.0.0
ifconfig "$EIFACE" up promisc
echo $'End of ethernet bridge'
if [[ "$EIFACE" != "$IFACE" ]] ; then
ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier")
if [[ "$ethernet_connected" != "0" ]]; then
echo $'Trying ethernet bridge to the internet'
brctl addif "$BRIDGE" "$EIFACE"
ifconfig "$EIFACE" 0.0.0.0
ifconfig "$EIFACE" up promisc
echo $'End of internet bridge'
sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service
sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx7 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx7.service
sed -i "s|ExecStart=.*|ExecStart=/usr/local/sbin/olsrd2_static ${IFACE} ${EIFACE}|g" /etc/systemd/system/olsr2.service
sed -i "s|ExecStart=.*|ExecStart=/usr/local/bin/babeld ${IFACE} ${EIFACE}|g" /etc/systemd/system/babel.service
systemctl daemon-reload
else
echo $"$EIFACE is not connected"
sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service
sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx7 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx7.service
sed -i "s|ExecStart=.*|ExecStart=/usr/local/sbin/olsrd2_static ${IFACE} ${EIFACE}|g" /etc/systemd/system/olsr2.service
sed -i "s|ExecStart=.*|ExecStart=/usr/local/bin/babeld ${IFACE} ${EIFACE}|g" /etc/systemd/system/babel.service
systemctl daemon-reload
else
echo $"$EIFACE is not connected"
fi
fi
fi
ifconfig "$BRIDGE" up
@ -302,6 +304,9 @@ function start {
}
function monitor {
if [[ "$MESH_INTERFACE_TYPE" != 'wlan'* ]]; then
return
fi
if [ -z "$IFACE" ] ; then
echo 'error: unable to find wifi interface, not enabling batman-adv mesh'
exit 723657
@ -357,6 +362,36 @@ function monitor {
start
}
# optionally a file can contain the mesh interface type
mesh_interface_type_file=/root/.mesh_interface_type
if [ -f "$mesh_interface_type_file" ]; then
MESH_INTERFACE_TYPE=$(head -n 1 < "$mesh_interface_type_file")
if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
MESH_INTERFACE_TYPE='wlan'
fi
if [[ "$MESH_INTERFACE_TYPE" == 'eth'* ]]; then
MESH_INTERFACE_TYPE='eth'
fi
fi
mesh_protocol_init
if [[ "$MESH_INTERFACE_TYPE" == 'eth'* ]]; then
MESH_INTERFACE_TYPE='eth'
fi
update_wifi_adaptors "${MESH_INTERFACE_TYPE}"
if [ ! "$IFACE" ]; then
echo $'No wlan adaptor'
exit 0
fi
if [ -e /etc/default/batctl ]; then
# shellcheck disable=SC1091
. /etc/default/batctl
fi
if ! grep -q "$IFACE" /proc/net/dev; then
echo "Interface \$IFACE was not found"
stop

View File

@ -65,10 +65,10 @@ function mesh_avahi {
sed -i "s|#host-name=.*|host-name=P$PEER_ID|g" "$rootdir/etc/avahi/avahi-daemon.conf"
sed -i "s|use-ipv4=.*|use-ipv4=no|g" "$rootdir/etc/avahi/avahi-daemon.conf"
sed -i "s|use-ipv6=.*|use-ipv6=yes|g" "$rootdir/etc/avahi/avahi-daemon.conf"
sed -i "s|#allow-interfaces=.*|allow-interfaces=wlan0, wlan1, wlan2, wlan3, wlan4, wlan5|g" "$rootdir/etc/avahi/avahi-daemon.conf"
sed -i "s|allow-interfaces=.*|allow-interfaces=wlan0, wlan1, wlan2, wlan3, wlan4, wlan5|g" "$rootdir/etc/avahi/avahi-daemon.conf"
sed -i "s|#deny-interfaces=.*|deny-interfaces=eth0, eth1, eth2, eth3, eth4, eth5|g" "$rootdir/etc/avahi/avahi-daemon.conf"
sed -i "s|deny-interfaces=.*|deny-interfaces=eth0, eth1, eth2, eth3, eth4, eth5|g" "$rootdir/etc/avahi/avahi-daemon.conf"
#sed -i "s|#allow-interfaces=.*|allow-interfaces=wlan0, wlan1, wlan2, wlan3, wlan4, wlan5|g" "$rootdir/etc/avahi/avahi-daemon.conf"
#sed -i "s|allow-interfaces=.*|allow-interfaces=wlan0, wlan1, wlan2, wlan3, wlan4, wlan5|g" "$rootdir/etc/avahi/avahi-daemon.conf"
#sed -i "s|#deny-interfaces=.*|deny-interfaces=eth0, eth1, eth2, eth3, eth4, eth5|g" "$rootdir/etc/avahi/avahi-daemon.conf"
#sed -i "s|deny-interfaces=.*|deny-interfaces=eth0, eth1, eth2, eth3, eth4, eth5|g" "$rootdir/etc/avahi/avahi-daemon.conf"
sed -i "s|#disallow-other-stacks=.*|disallow-other-stacks=yes|g" "$rootdir/etc/avahi/avahi-daemon.conf"
sed -i "s|disallow-other-stacks=.*|disallow-other-stacks=yes|g" "$rootdir/etc/avahi/avahi-daemon.conf"
sed -i "s|#publish_addresses=.*|publish_addresses=yes|g" "$rootdir/etc/avahi/avahi-daemon.conf"

View File

@ -99,11 +99,13 @@ function mesh_protocol_init {
IFACE=
IFACE_SECONDARY=
EIFACE=eth0
WLAN_ADAPTORS=$(count_wlan)
if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
WLAN_ADAPTORS=$(count_wlan)
if [ "$WLAN_ADAPTORS" -eq 0 ]; then
echo $'No wlan adaptors found'
exit 0
if [ "$WLAN_ADAPTORS" -eq 0 ]; then
echo $'No wlan adaptors found'
exit 0
fi
fi
}

View File

@ -100,7 +100,7 @@ function setup_wifi_atheros {
fi
dpkg -i "$atheros_drivers_file"
reset_usb_devices
update_wifi_adaptors
update_wifi_adaptors 'wlan'
if [ "$IFACE" ]; then
wpa_action "${IFACE}" stop
wpa_cli -i "${IFACE}" terminate
@ -198,19 +198,24 @@ function install_atheros_wifi {
}
function update_wifi_adaptors {
interface_type="$1"
IFACE=
IFACE_SECONDARY=
if [ ! "$interface_type" ]; then
interface_type='wlan'
fi
for i in $(seq 10 -1 0); do
ifdown --force "wlan${i}" 2> /dev/null
ifdown --force "${interface_type}${i}" 2> /dev/null
done
for i in $(seq 10 -1 0); do
if grep -q "wlan${i}" /proc/net/dev; then
if grep -q "${interface_type}${i}" /proc/net/dev; then
if [ ! $IFACE ]; then
IFACE="wlan${i}"
else
IFACE_SECONDARY="wlan${i}"
IFACE_SECONDARY="${interface_type}${i}"
return
fi
fi
@ -479,7 +484,7 @@ function wifi_networks_file_header {
function create_networks_interactive {
remove_config_param "WIFI_INTERFACE"
update_wifi_adaptors
update_wifi_adaptors 'wlan'
if [ ! "$IFACE" ]; then
# Don't try to configure wifi if there are no adaptors
return

View File

@ -150,7 +150,7 @@ if [ ! ${wifi_interface_specified} ]; then
else
sleep "${WAIT_SEC}"
fi
update_wifi_adaptors
update_wifi_adaptors 'wlan'
if [ ! $IFACE ]; then
echo $'No wifi adaptors were found'
exit 872356