Skip to content

Instantly share code, notes, and snippets.

@morfikov
Forked from telenieko/a_enable_wireless.sh
Last active February 26, 2024 01:49
Show Gist options
  • Save morfikov/15c92d5ea1fd8e831bef0d0fd88f38c7 to your computer and use it in GitHub Desktop.
Save morfikov/15c92d5ea1fd8e831bef0d0fd88f38c7 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=30
INTERFACE="wlan0"
alias WPACLI="/sbin/wpa_cli -p/tmp/wpa_supplicant -i$INTERFACE "
log_begin_msg "Setting WLAN regdomain"
# Set this to your region
/sbin/iw reg set PL
log_begin_msg "Starting WLAN connection"
sleep 1 && /sbin/wpa_supplicant -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
else
ONLINE=1
log_success_msg "WLAN online"
fi
configure_networking
# !/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 brcmfmac
copy_exec /sbin/wpa_supplicant
copy_exec /sbin/wpa_cli
copy_exec /sbin/iw
copy_file config /etc/initramfs-tools/wpa_supplicant.conf /etc/wpa_supplicant.conf
#copy_file firmware /lib/firmware/brcm/brcmfmac43455-sdio.bin
copy_file firmware /lib/firmware/brcm/brcmfmac43455-sdio.clm_blob
copy_file firmware /lib/firmware/brcm/brcmfmac43455-sdio.txt
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 on the shell
chmod +x /etc/initramfs-tools/scripts/local-bottom/kill_wireless
chmod +x /etc/initramfs-tools/scripts/init-premount/a_enable_wireless
chmod +x /etc/initramfs-tools/hooks/enable-wireless
update-initramfs -k all -u
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
echo "Killing wpa_supplicant so the system takes over later."
kill `cat /run/initram-wpa_supplicant.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
country=PL
network={
ssid="Ever_Vigilant"
scan_ssid=1
psk="DontLookAtMe"
key_mgmt=WPA-PSK
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment