-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiwconfer.sh
executable file
·90 lines (74 loc) · 2.24 KB
/
iwconfer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/bash
# my preferred options
params=("bt_coex_active=" "11n_disable=" "swcrypto=" "power_save=" "power_scheme=" "d0i3_disable=" "uapsd_disable=")
options=("0" "8" "1" "0" "1" "1" "1")
# check if running as root
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
echo "Please run with root privileges!"
exit
fi
# location of the conf file.
FILE=/etc/modprobe.d/iwlwifi.conf
# argument options
OPTSTRING=":dc"
# find pre-existing config and create a backup in home directory
if [ -f "$FILE" ]; then
echo "$FILE exists, Creating backup in dir; ~/iwlwifi-config"
mkdir -p ~/iwlwifi-config
cp $FILE ~/iwlwifi-config/iwlwifi.conf.bak
echo " Backup created!"
else
echo "$FILE does not exist, continuing..."
fi
# functions - - -
# change the file to the new options
write_ops(){
echo "To undo any changes you may either delete the file $FILE or restore the backup file located in ~/iwlwifi-config/iwlwifi.conf.bak, if it exists!"
echo "# conf generated by iwlwifi-configurer." > $FILE
i=0
printf "\n Writing... \n"
for str in "${params[@]}"
do
echo "Setting $str${options[$i]}"
echo "options iwlwifi $str${options[$i]}" >> $FILE
i=$((i+1))
done
printf "\nDone! \n"
}
# function for users who want to do a custom configuration
set_ops()
{
printf "\nBe careful with this, if you do not know what you are doing please quit (CTRL-C). This may brick your wifi if misconfigured."
echo "To undo any changes you may either delete; $FILE or restore the backup located in; ~/iwlwifi-config/iwlwifi.conf.bak, if this was created!"
i=0
for str in "${params[@]}"
do
read -r -p "Enter your option for $str: " option
options[$i]=$option
i=$((i+1))
done
echo "Writing with custom configuration..."
write_ops
}
# functions - - -
# Default to -d if no argument provided
if [ $# -eq 0 ]; then
set -- -d
fi
# get args
while getopts ${OPTSTRING} opt; do
case ${opt} in
d)
echo "Default configuration will be used."
write_ops
;;
c)
echo "Custom configuration will be used."
set_ops
;;
?)
echo "Invalid -${OPTARG}, please use -d for default or -c for custom configuration."
exit 1
;;
esac
done