Created
May 7, 2022 19:18
-
-
Save Lmanangka/ce9a1079fd409662205dcea7267e77dd to your computer and use it in GitHub Desktop.
headless configuration for raspberry pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PI_BOOT="YOUR PI BOOT PARTITION (check with 'lsblk')" | |
TARGET_DIR="YOUR TARGET DIR FOR MOUNTING PI BOOT PARTITION (usually '/media/YOUR_DIR')" | |
#create dir and mounting device | |
create_mount(){ | |
[ ! -b $PI_BOOT ] && echo "$PI_BOOT does not exist." && exit || \ | |
[ -b $PI_BOOT ] && [ ! -d $TARGET_DIR ] && \ | |
sudo mkdir -pv $TARGET_DIR || [ -d $TARGET_DIR ] && \ | |
sudo mount -v $PI_BOOT $TARGET_DIR | |
} | |
#create file for headless configuration | |
headless_conf(){ | |
read -p "username= " USR && read -sp "passwd= " USR_PASSWD && echo && \ | |
ENCRYPT_PASS=$(echo $USR_PASSWD | openssl passwd -6 -stdin) && \ | |
read -p "wifi_name= " SSID && read -sp "passwd= " SSID_PASSWD && \ | |
echo && sudo touch $TARGET_DIR/ssh && \ | |
echo "$USR:$ENCRYPT_PASS" | sudo tee $TARGET_DIR/userconf.txt 1>/dev/null && \ | |
echo "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev | |
update_config=1 | |
country=ID | |
network={ | |
scan_ssid=1 | |
ssid="\"$SSID\"" | |
psk="\"$SSID_PASSWD\"" | |
proto=RSN | |
key_mgmt=WPA-PSK | |
pairwise=CCMP | |
auth_alg=OPEN | |
}" | sudo tee $TARGET_DIR/wpa_supplicant.conf 1>/dev/null || echo "Failed." | |
} | |
#run the script | |
create_mount && echo "Start Configuration..." && headless_conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment