This repository has been archived by the owner on Apr 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
/
configure_connection.sh
170 lines (152 loc) · 6.69 KB
/
configure_connection.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash
###############################################################
### Anarchy Linux Install Script
### configure_connection.sh
###
### Copyright (C) 2017 Dylan Schacht
###
### By: Dylan Schacht (deadhead)
### Email: [email protected]
### Webpage: https://anarchylinux.org
###
### Any questions, comments, or bug reports may be sent to above
### email address. Enjoy, and keep on using Arch.
###
### License: GPL v2.0
###############################################################
update_mirrors() {
op_title="$welcome_op_msg"
if ! (dialog --yes-button "$yes" --no-button "$no" --yesno "\n$intro_msg" 10 60) then
reset ; exit
fi
for interface in $(ls /sys/class/net/ | grep -v "lo\|vir"); do
if [[ $(cat /sys/class/net/$interface/carrier) = 1 ]]; then OnLine=true; fi
done
## Until connected loop
until "$OnLine"
do
if [ -n "$wifi_network" ]; then
if (dialog --yes-button "$yes" --no-button "$no" --yesno "\n$wifi_msg0" 10 60) then
wifi-menu
if [ "$?" -gt "0" ]; then
dialog --ok-button "$ok" --msgbox "\n$wifi_msg1" 10 60
echo "$(date -u "+%F %H:%M") : Failed to connect to wifi: Exit 1" >> "$log"
setterm -background black -store ; reset ; echo "$connect_err1" | sed 's/\\Z1//;s/\\Zn//' ; exit 1
else
echo "$(date -u "+%F %H:%M") : Connected to: $wifi_network" >> "$log"
OnLine=true
fi
else
unset wifi_network
fi
else
dialog --ok-button "$ok" --msgbox "\n$connect_err0" 10 60
echo "$(date -u "+%F %H:%M") : Failed to connect to network: Exit 1" >> "$log"
setterm -background black -store ; reset ; echo -e "$connect_err1" | sed 's/\\Z1//;s/\\Zn//' ; exit 1
fi
done
op_title="$mirror_op_msg"
while (true)
do
edit_mirrors=$(dialog --ok-button "$ok" --menu "\n$mirror_msg0\n" 12 60 3 \
"$update_mirrors_msg" "->" \
"$manual_mirrors" "->" \
"$cancel_mirrors" "->" 3>&1 1>&2 2>&3)
if [ "$?" -gt "0" ] || [ "$edit_mirrors" == "$cancel_mirrors" ]; then
if (dialog --yes-button "$yes" --no-button "$no" --yesno "\n$mirror_cancel_msg" 10 60) then
break
fi
fi
case "$edit_mirrors" in
"$update_mirrors_msg")
code=$(dialog --ok-button "$ok" --menu "$mirror_msg1" 17 60 10 \
"$default" "->" \
$countries 3>&1 1>&2 2>&3)
if [ "$?" -gt "0" ]; then
if (dialog --yes-button "$yes" --no-button "$no" --yesno "\n$mirror_cancel_msg" 10 60) then
break
else
continue
fi
fi
case "$code" in
"$default")
mirror_url="https://www.archlinux.org/mirrorlist/all/"
;;
"AS") ## All https mirrors
mirror_url="https://www.archlinux.org/mirrorlist/all/https/"
;;
*) ## User selected country
mirror_url="https://www.archlinux.org/mirrorlist/?country=$code"
;;
esac
if [ "$code" == "$default" ]; then
curl -k -s "$mirror_url" | sed '10,1000d;s/#//' >/etc/pacman.d/mirrorlist.bak &
else
curl -k -s "$mirror_url" >/etc/pacman.d/mirrorlist.bak &
fi
pid=$! pri=0.1 msg="\n$mirror_load0 \n\n \Z1> \Z2curl $mirror_url\Zn" load
if (grep "Server" /etc/pacman.d/mirrorlist.bak &>/dev/null); then
echo "$(date -u "+%F %H:%M") : Updated Mirrors From: $code" >> "$log"
sed -i 's/#//' /etc/pacman.d/mirrorlist.bak
rankmirrors -n 6 /etc/pacman.d/mirrorlist.bak > /etc/pacman.d/mirrorlist &
pid=$! pri=0.8 msg="\n$mirror_load1 \n\n \Z1> \Z2rankmirrors -n 6 /etc/pacman.d/mirrorlist\Zn" load
else
dialog --ok-button "$ok" --msgbox "\n$connect_err0" 10 60
echo "$(date -u "+%F %H:%M") : Failed to connect to wifi: Exit 1" >> "$log"
setterm -background black -store ; reset ; echo -e "$connect_err1" | sed 's/\\Z1//;s/\\Zn//' ; exit 1
fi
break
;;
"$manual_mirrors")
EDITOR=$(dialog --ok-button "$ok" --menu "$mirror_editor_msg" 10 60 3 \
"nano" "$nano_msg" \
"vim" "$vim_msg" \
"$cancel" "->" 3>&1 1>&2 2>&3)
if [ "$?" -gt "0" ] || [ "$EDITOR" == "$cancel" ]; then
if (dialog --yes-button "$yes" --no-button "$no" --yesno "\n$mirror_cancel_msg" 10 60) then
break
fi
else
$EDITOR /etc/pacman.d/mirrorlist
break
fi
;;
esac
done
}
check_connection() {
op_title="$connection_op_msg"
(test_mirror=$(</etc/pacman.d/mirrorlist grep "^Server" | awk 'NR==1{print $3}' | sed 's/$.*//')
test_pkg=$(curl -s https://www.archlinux.org/packages/extra/x86_64/bluez-utils/ | grep "<title>" | awk '{print $4"-"$5}')
test_link="${test_mirror}extra/os/x86_64/${test_pkg}-x86_64.pkg.tar.xz"
wget -4 --no-check-certificate --append-output=/tmp/wget.log -O /dev/null "${test_link}") &
pid=$! pri=0.3 msg="\n$connection_load \n\n \Z1> \Z2wget -O /dev/null test_link/test1Mb.db\Zn" load
sed -i 's/\,/\./' /tmp/wget.log
connection_speed=$(tail /tmp/wget.log | grep -oP '(?<=\().*(?=\))' | awk '{print $1}')
connection_rate=$(tail /tmp/wget.log | grep -oP '(?<=\().*(?=\))' | awk '{print $2}')
if (lscpu | grep "max MHz" &>/dev/null); then
cpu_mhz=$(lscpu | grep "CPU max MHz" | awk '{print $4}' | sed 's/\..*//')
else
cpu_mhz=$(lscpu | grep "CPU MHz" | awk '{print $3}' | sed 's/\..*//')
fi
case "$cpu_mhz" in
[0-9][0-9][0-9])
cpu_sleep=4.5
;;
[1][0-9][0-9][0-9])
cpu_sleep=4
;;
[2][0-9][0-9][0-9])
cpu_sleep=3.5
;;
*)
cpu_sleep=2.5
;;
esac
export connection_speed connection_rate cpu_sleep
echo "$(date -u "+%F %H:%M") : Ranked connection speed: $connection_speed $connection_rate" >> "$log"
echo "$(date -u "+%F %H:%M") : Clocked CPU MHz: $cpu_mhz" >> "$log"
rm /tmp/wget.log &> /dev/null
}
# vim: ai:ts=4:sw=4:et