Skip to content

Instantly share code, notes, and snippets.

@satmandu
Forked from telenieko/a_enable_wireless.sh
Last active March 31, 2024 00:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satmandu/5a5efd2c6f7922d670acddb9fe3ef9bd to your computer and use it in GitHub Desktop.
Save satmandu/5a5efd2c6f7922d670acddb9fe3ef9bd to your computer and use it in GitHub Desktop.
Sample files to enable wireless on Debian initramfs
#!/bin/sh
# this goes into /etc/initramfs-tools/scripts/init-premount/a_enable_wireless
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
. /scripts/functions
AUTH_LIMIT=15
INTERFACE="wlp3s0"
alias WPACLI="/sbin/wpa_cli -p/tmp/wpa_supplicant -i$INTERFACE "
log_begin_msg "Starting haveged rng"
/usr/sbin/haveged -r 0 -p /run/initram-haveged.pid
log_begin_msg "Setting WLAN regdomain"
# Set this to your region
/sbin/iw reg set US
log_begin_msg "Starting WLAN connection"
/sbin/wpa_supplicant -Dnl80211,wext -i$INTERFACE -c/etc/wpa_supplicant.conf -P/run/initram-wpa_supplicant.pid -B -f/tmp/wpa_supplicant.log
# Wait for AUTH_LIMIT seconds, then check the status
limit=${AUTH_LIMIT}
echo -n "Waiting for connection (max ${AUTH_LIMIT} seconds)"
while [ $limit -ge 0 -a `WPACLI status | grep wpa_state` != "wpa_state=COMPLETED" ]
do
sleep 1
echo -n "."
limit=`expr $limit - 1`
done
echo ""
if [ `WPACLI status | grep wpa_state` != "wpa_state=COMPLETED" ]; then
ONLINE=0
log_failure_msg "WLAN offline after timeout"
#panic
/sbin/iwconfig $INTERFACE power off
else
ONLINE=1
log_success_msg "WLAN online"
/sbin/iwconfig $INTERFACE power off
configure_networking
fi
# !/bin/sh
# This goes into /etc/initramfs-tools/hooks/enable-wireless
set -e
PREREQ=""
prereqs()
{
echo "${PREREQ}"
}
case "${1}" in
prereqs)
prereqs
exit 0
;;
esac
. /usr/share/initramfs-tools/hook-functions
# CHANGE HERE for your correct modules.
manual_add_modules wl
copy_exec /sbin/wpa_supplicant
copy_exec /sbin/wpa_cli
copy_exec /sbin/iw
copy_exec /sbin/iwconfig
copy_exec /usr/sbin/haveged
copy_file config /etc/initramfs-tools/wpa_supplicant.conf /etc/wpa_supplicant.conf
copy_file config /lib/crda/regulatory.bin
copy_file config /lib/firmware/regulatory.db
copy_file config /lib/firmware/regulatory.db.p7s
# This is run in the shell
sudo chmod +x /etc/initramfs-tools/scripts/local-bottom/kill_wireless.sh
sudo chmod +x /etc/initramfs-tools/scripts/init-premount/a_enable_wireless.sh
sudo chmod +x /etc/initramfs-tools/hooks/enable-wireless.sh
sudo apt install haveged wireless-regdb -y
sudo update-initramfs -k all -c
sudo update-grub
#!/bin/sh
# this goes into /etc/initramfs-tools/scripts/local-bottom/kill_wireless
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
. /scripts/functions
log_begin_msg "Killing wpa_supplicant so the system takes over later."
kill `cat /run/initram-wpa_supplicant.pid`
log_begin_msg "Killing haveged rngd so the system takes over later."
kill `cat /run/initram-haveged.pid`
# sample /etc/initramfs-tools/wpa_supplicant.conf
# note that this is independent of the system /etc/wpa_supplicant.conf (if any)
# only add the network you need at boot time. **And keep the ctrl_interface** !!
ctrl_interface=/tmp/wpa_supplicant
# Your region should be here
country=US
network={
ssid="Network 1"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
psk="secret password 1"
priority=1
}
network={
ssid="Network 2"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
psk="secret password 2"
priority=2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment