-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore(): Add editorconfig * chore(): rename scripts to project's names * feat(): Add configfile feat(): Add log file feat(): Make the script idempotent fix(): Adding error for failing download in TUI mode BREAKING CHANGE: script is now uses config file and only runs with root access * fix(): make Dockerfile compatible with new changes * chore(): change .env to best403unlocker.conf BREAKING CHANGE: Add config file to /etc/ and Make the script idempotent .
- Loading branch information
1 parent
d420dec
commit 7426521
Showing
6 changed files
with
159 additions
and
98 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true | ||
|
||
[*.yml] | ||
indent_size = 2 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM alpine:3.19 | ||
run apk update && apk add --no-cache wget bash | ||
ADD bash.sh . | ||
entrypoint ["bash","bash.sh"] | ||
ADD best403unlocker . | ||
entrypoint ["bash","best403unlocker"] |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env bash | ||
DATABASE=best403unlocker_database_$(date +%s) | ||
DATABASE_PATH=/tmp/$DATABASE | ||
# Functions | ||
check_run_with_root_accsses(){ | ||
if [ "$EUID" -ne 0 ]; then | ||
echo "Please run this script as root (sudo)" | ||
exit 1 | ||
fi | ||
} | ||
check_required_packages_is_installed(){ | ||
if ! [ -x "$(command -v wget)" ] | ||
then | ||
echo "wget is not installed" >&2 | ||
exit 1 | ||
fi | ||
} | ||
check_and_source_env() { | ||
if [ ! -f /etc/best403unlocker.conf ]; then | ||
wget -c https://raw.githubusercontent.com/ArmanTaheriGhaleTaki/best403unlocker/main/.env -O /etc/best403unlocker.conf | ||
fi | ||
source /etc/best403unlocker.conf | ||
} | ||
|
||
check_ip() { | ||
local input=$1 | ||
local regex="^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" | ||
|
||
if [[ $input =~ $regex ]]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
function change_dns () { | ||
|
||
echo 'nameserver' $1> /etc/resolv.conf | ||
echo '############################' | ||
cat /etc/resolv.conf | ||
echo '$$$$$$$$$$$$$$$$$$$$$$$$$$$$' | ||
|
||
} | ||
|
||
function download() { | ||
timeout $timeout wget -q -O /tmp/$1 --no-dns-cache $file_url | ||
} | ||
|
||
function download_speed() { | ||
du -s /tmp/$1 >> $DATABASE_PATH | ||
rm /tmp/$1 | ||
} | ||
|
||
loggin(){ | ||
echo "$(date '+%Y-%m-%d %H:%M:%S') " | ||
sed -i s/"\/tmp\/"//g $DATABASE_PATH | ||
} | ||
|
||
|
||
# Execute the functions | ||
check_run_with_root_accsses | ||
check_required_packages_is_installed | ||
check_and_source_env | ||
touch touch $DATABASE_PATH | ||
cp /etc/resolv.conf /etc/resolv.conf.bakup | ||
for i in $dns | ||
do | ||
if check_ip $i; then | ||
change_dns $i | ||
download $i | ||
download_speed $i | ||
fi | ||
done | ||
is_network_working=$( sort -rn $DATABASE_PATH | head -1|cut -d $'\t' -f1) | ||
|
||
if [[ "$is_network_working" -eq 0 ]]; then | ||
echo '*********************' | ||
echo 'Network is not reachable' | ||
echo '*********************' | ||
else | ||
echo '*********************' | ||
echo best dns server is `sort -rn $DATABASE_PATH| head -1| cut -d'/' -f3` | ||
echo '*********************' | ||
fi | ||
loggin >> /var/log/best403unlocker.log | ||
cat /etc/resolv.conf.bakup > /etc/resolv.conf | ||
rm /etc/resolv.conf.bakup |
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