From ce9d50ab0cace82595fa47190d3eb973e6a1876f Mon Sep 17 00:00:00 2001 From: DarkFeather Date: Wed, 25 Oct 2017 23:50:52 -0500 Subject: [PATCH] Adding wifi scripts; general cleanup --- Admin/Makefile | 10 +++++++--- Admin/wifi | 16 ++++++++++++++++ Admin/wifi.service | 12 ++++++++++++ Admin/wifiboot | 13 +++++++++++++ ShadowArch/Makefile | 8 ++++---- ShadowArch/bashrc | 8 ++++++-- ShadowArch/skel/.bashrc | 5 ----- 7 files changed, 58 insertions(+), 14 deletions(-) create mode 100755 Admin/wifi create mode 100644 Admin/wifi.service create mode 100755 Admin/wifiboot diff --git a/Admin/Makefile b/Admin/Makefile index a1ff94e..f45187e 100644 --- a/Admin/Makefile +++ b/Admin/Makefile @@ -1,25 +1,29 @@ -LIST=arch-update close-guest fix-sound log-guest open-guest restart-service silent-guardian revproxy simple-web +LIST=arch-update close-guest fix-sound log-guest open-guest restart-service silent-guardian revproxy simple-web wifi wifiboot LOCATION=/root/bin INSTALLER != curl -s https://aninix.net/foundation/installer-test.bash | /bin/bash PERMISSION=0700 -compile: +compile: ${LIST} ./wifi.service @echo Nothing to compile. -install: compile +install: compile mkdir -p ${LOCATION}; mkdir -p /var/log/aninix/ for i in ${LIST}; do cp ./$$i ${LOCATION}; done + cp ./wifi.service /usr/lib/systemd/system/wifi.service make checkperm reverse: for i in ${LIST}; do cp ${LOCATION}/$$i .; done + cp /usr/lib/systemd/system/wifi.service . test: ${LIST} for i in ${LIST}; do [ "$$(grep -c '#/bin/bash' $$i)" -ne 1 ]; done checkperm: for i in ${LIST}; do chown root:root ${LOCATION}/$$i; chmod ${PERMISSION} ${LOCATION}/$$i; done + chown root: /usr/lib/systemd/system/wifi.service; + chmod 0644 /usr/lib/systemd/system/wifi.service clean: @echo Nothing to do. diff --git a/Admin/wifi b/Admin/wifi new file mode 100755 index 0000000..9dbb2d0 --- /dev/null +++ b/Admin/wifi @@ -0,0 +1,16 @@ +#!/bin/bash +if [ -z "$1" ]; then + echo Usage: $0 conf_name '[ interface ]' + exit 1; +else + conf="$1" +fi +if [ -z "$2" ]; then + interface="wlp4s0" +else + interface="$2" +fi +wpa_supplicant -i "$interface" -c /etc/wpa_supplicant/"${conf}".conf -B +sleep 3 +dhcpcd "$interface" +exit $? diff --git a/Admin/wifi.service b/Admin/wifi.service new file mode 100644 index 0000000..db4aad7 --- /dev/null +++ b/Admin/wifi.service @@ -0,0 +1,12 @@ +[Unit] +Description=Wifi Connectivity Service +Wants=network-online.target +After=network-online.target + +[Service] +ExecStart=/root/bin/wifiboot +Type=oneshot +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/Admin/wifiboot b/Admin/wifiboot new file mode 100755 index 0000000..f5e03bd --- /dev/null +++ b/Admin/wifiboot @@ -0,0 +1,13 @@ +#!/bin/bash + +MAC="34:f6:4b:36:12:8f" +interface=`ip link list | grep -B 1 "$MAC" | head -n 1 | cut -f 2 -d ':' | cut -f 2 -d ' '` +ip link set "$interface" up +for i in `iwlist "$interface" scanning | grep ESSID | cut -f 2 -d \" | tr '[:upper:]' '[:lower:]'`; do + if [ -f /etc/wpa_supplicant/"$i".conf ]; then + /root/bin/wifi "$i" "$interface" + if [ $? -eq 0 ]; then + exit 0; + fi + fi + done diff --git a/ShadowArch/Makefile b/ShadowArch/Makefile index fc3bb56..3747b9a 100644 --- a/ShadowArch/Makefile +++ b/ShadowArch/Makefile @@ -9,7 +9,7 @@ compile: ./shadowarch install: compile for i in ${SYNCLIST}; do rsync -avz -r `echo $$i | sed 's#^/etc/##'` $$i; done # This is a nicety. - if [ -f /root/shadowarch* ]; then sed -i 's/`uname -o`/ShadowArch/g' /etc/bash.bashrc; fi + if [ -f /root/shadowarch* ]; then sed -i 's/`uname -o`/ShadowArch/g' /etc/bashrc; fi repository: shadowarch ${HTTPROOT} cp ./shadowarch ${HTTPROOT} @@ -33,9 +33,9 @@ reverse: ${HTTPROOT}/shadowarch ${SYNCLIST} clean: if [ -f /etc/bash.bashrc ]; then printf "Remove /etc/bash.bashrc? [y/n] "; read answer; if [ "$$answer" == "y" ]; then rm /etc/bash.bashrc; fi; fi -diff: ${HTTPROOT}/shadowarch ${SYNCLIST} - diff ./shadowarch ${HTTPROOT}/shadowarch - for i in ${SYNCLIST}; do diff "$$i" ./`echo $$i | rev | cut -f 1 -d '/' | rev` || [ 1 -eq 1 ]; done +diff: ${SYNCLIST} + if [ -f ${HTTPROOT}/shadowarch ]; then diff ./shadowarch ${HTTPROOT}/shadowarch; echo; fi + for i in ${SYNCLIST}; do diff -rc "$$i" ./`echo $$i | rev | cut -f 1 -d '/' | rev`; echo; done find-missing-hooks-in-src: @for i in `wget -q -O - https://aninix.net/foundation/ | grep toplevel-repo | cut -f 4 -d \'`; do if [ -z $$i ]; then continue; fi; for file in `find ../.. -type f -name Makefile | grep $$i`; do if [ -z "$$file" ]; then echo NO MAKEFILE FOR $$i; elif [ `grep -c -i 'hook for systemd' $$file` -eq 0 ]; then echo HOOK MISSING IN: $$file; else echo HOOK FOUND IN: $$file; fi; done; done diff --git a/ShadowArch/bashrc b/ShadowArch/bashrc index 45bb610..8d2c8c9 100644 --- a/ShadowArch/bashrc +++ b/ShadowArch/bashrc @@ -27,7 +27,6 @@ esac [ -f /etc/bash.motd ] && cat /etc/bash.motd ### AniNIX Customizations ### - alias get-commands='for i in $( echo $PATH | sed "s/:/\n/g"); do ls $i; done | sort | less' alias whoison='who | grep -v tmux' alias startvnc="vncserver -xstartup startxfce4; echo Use \"ssh -L 5901:localhost:5901 $(whoami)@$(hostname)\" to tunnel connections." @@ -35,7 +34,9 @@ alias vi=vim alias view="vim -R" alias top="top -o %CPU" alias make-entrypoints="egrep '^[a-zA-Z0-9\-]*:' Makefile" -if [ -x `which torsocks 2>/dev/null` ] && [ `systemctl status tor 2>/dev/null| grep -c running` -eq 1 ]; then alias tor-lynx="torsocks lynx https://check.torproject.org/"; fi +if [ -x `which torsocks 2>/dev/null` ] && [ `systemctl status tor 2>/dev/null| grep -c running` -eq 1 ]; then + alias tor-lynx="torsocks lynx https://check.torproject.org/"; +fi IFS=" " @@ -71,4 +72,7 @@ if [ ! -z "$SSH_CLIENT" ]; then fi alias sdr="screen -d -r" fi; +elif [ `who -m | egrep "^$(whoami)" | awk '{ print $2; }' | egrep -c "^tty"` -eq 1 ] && [ -x /usr/sbin/startxfce4 ]; then + exec startxfce4 fi + diff --git a/ShadowArch/skel/.bashrc b/ShadowArch/skel/.bashrc index 3f04226..032b24b 100644 --- a/ShadowArch/skel/.bashrc +++ b/ShadowArch/skel/.bashrc @@ -5,11 +5,6 @@ # If not running interactively, don't do anything [[ $- != *i* ]] && return -# Source global definitions -if [ -f /etc/bashrc ]; then - . /etc/bashrc -fi - # Allow separation so that /usr/local/bin/replicate-ssh-profiles doesn't carry local-only customizations downstream. if [ -f ~/.bashrc-local ]; then . ~/.bashrc-local