Skip to content

Commit

Permalink
Stable Update - Add silence install function (#32)
Browse files Browse the repository at this point in the history
* Add hook to prevent to be kicked (#31)

* Add hook to prevent to be kicked

* Support for different warning count

* Enable silent install function

* fix some functions

Co-authored-by: Hagb (Guo Junyu 郭俊余) <[email protected]>
  • Loading branch information
weearc and Hagb authored Jul 27, 2021
1 parent e96355b commit a8923ca
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 33 deletions.
9 changes: 9 additions & 0 deletions config.ini.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
campus=
username=
password=
wifi_ssid0=
wifi_ssid1=
client=
wifi_password0=
wifi_password1=
set_cron=
6 changes: 6 additions & 0 deletions latest-wired.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import random
import traceback
import re

keep_alive1_mod = False #If you have trouble at KEEPALIVE1, turn this value to True
nic_name = '' #Indicate your nic, e.g. 'eth0.2'.nic_name
Expand Down Expand Up @@ -61,6 +62,7 @@ def get_ip_address(ifname):
if IS_TEST:
DEBUG = True
LOG_PATH = 'drcom_client.log'
regex = re.compile('bcecb2e2b7a2cfd620((3[0-9])+)20b4ce2c20((3[0-9])+)20b4cebaf3b4a6c0ed')


def log(*args, **kwargs):
Expand All @@ -69,6 +71,10 @@ def log(*args, **kwargs):
if DEBUG:
with open(LOG_PATH,'a') as f:
f.write(s + '\n')
kicking_search = regex.search(s)
if kicking_search and kicking_search.group(1) == kicking_search.group(3):
log('[auto-relogin] Need to relogin now, or will be kicked!')
sys.exit(1)

def challenge(svr,ran):
while True:
Expand Down
95 changes: 62 additions & 33 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/ash
#!/bin/sh
# shellcheck shell=ash
CONFIG=drcom.conf
CONFIG_PATH=/etc
Expand All @@ -9,18 +9,21 @@ CONFIG_PATH=/etc
DRCOMLOG=/var/log/drcom.log
NETLOG=/var/log/networkChecking.log
DRCOM_PID=/var/run/drcom-wrapper.pid
VERSION_CQU_DRCOM='2.2.4.2b'
ERROR_LOG=/var/log/install-error.log
VERSION_CQU_DRCOM='2.3a'

# for cli options
# "-" option is to rewrite long options which getopts do not support.
# ":" behind "-" is to undertake option string value of "-"
# like "--debug" option, "-" is a short option undertaking "-debug",
# and "debug" is the actual option handle by getopts
optspec="-:Vcvh"
optspec="-:Vcvhf"
# - for long flag option
# V for verbose option
# c for config changes option
# h for help option
# v for version option
# f for config file option

if [ ! -f "/etc/os-release" ];then
echo "Recheck your package. You cannot run this script."
Expand All @@ -37,6 +40,7 @@ echo() { printf '%s\n' "$*" ; }

# hello mates
hello() {
clear
echo "======================================"
echo "Welcome to CQU_drcom setup script."
echo "======================================"
Expand Down Expand Up @@ -147,7 +151,7 @@ inform_gather() {
ifSet_cron=no;;
esac


}

client_setting() {
Expand Down Expand Up @@ -254,7 +258,7 @@ recheck() {
echo "Change WIFI password:"
echo $ifChange
echo "DrCOM client:"
echo "the $CLIENT version"
echo "$CLIENT version"

case $ifChange in
Y|y|"")
Expand Down Expand Up @@ -401,17 +405,6 @@ setup_drcom() {
#set up startup service
echo "Setting up startup service..."
case $distro in
"pandorabox")
echo '#!/bin/sh
# /etc/hotplug.d/iface/99-drcom
if [ "$ACTION" = ifup ]; then
if [ "${INTERFACE}" = "wan" ]; then
sleep 10 && /usr/bin/drcom >' "'$DRCOMLOG'" '&
fi
fi' > 99-drcom
chmod a+x 99-drcom
cp -p 99-drcom /etc/hotplug.d/iface/ ;;

"openwrt")
echo '#!/bin/sh /etc/rc.common
START=99
Expand Down Expand Up @@ -567,25 +560,32 @@ setup_done_debug() {
cat /etc/os-release
}

# for end for process bar
spin() {
sp='/-\|'
printf ' '
while true; do
printf '\b%.1s' "$sp"
sp=${sp#?}${sp%???}
sleep 0
done
config_file_check() {
CLIENT=$client
ifSet_cron=$set_cron
if ! [[ $campus = "a" || $campus = "b" || $campus = "d" ]]
then
echo "Error, value campus with $campus is not allowed. Please check ."
echo "Error, value campus with $campus is not allowed. Please check ." >> $ERROR_LOG
exit
fi

if [[ $wifi_ssid0 -eq 0 ]]
then
wifi_ssid0="openwrt"
fi
if [[ $wifi_ssid1 -eq 0 ]]
then
wifi_ssid0="openwrt_5Ghz"
fi
if ! [[ $CLIENT = "python2" || $CLIENT = "micropy" ]]; then
echo "Error, value client with $CLIENT is not allowed. Please check."
echo "Error, value client with $CLIENT is not allowed. Please check." >> $ERROR_LOG
exit
fi

}

# process bar
progressbar()
{
bar="##################################################"
barlength=${#bar}
n=$(($1*barlength/100))
printf "\r[%-${barlength}s (%d%%)] " "${bar:0:n}" "$1"
}

# Handle actions without options
Expand Down Expand Up @@ -647,11 +647,24 @@ else # When running with options
setup_confirm
setup_done_debug
;;
file)
while read line;do
eval "$line"
done < config.ini
hello
clean_up
setup_packages
setup_drcom
setup_crontab
setup_wlan
setup_done
;;
help)
echo ""
echo "USAGE: sh ./setup.sh [options]"
echo ""
echo "-V, --dry-run Verbose. Run the scripts without actually setting up."
echo "-f, --file Use config file to install automatically"
echo "-h, --help Display this message."
;;
esac
Expand All @@ -672,8 +685,24 @@ else # When running with options
h)
echo "USAGE: sh ./setup.sh [options]"
echo "-V, --dry-run Verbose. Run the scripts without actually setting up."
echo "-f, --file Use config file to install automatically"
echo "-h, --help Display this message."
;;
f)
while read line;do
eval "$line"
done < config.ini
hello
config_file_check
clean_up
setup_packages
setup_drcom
setup_crontab
setup_wlan
setup_done
# config_file_check
# setup_done_debug
;;
*)
if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
echo "Non-option argument: '-${OPTARG}'" >&2
Expand Down

0 comments on commit a8923ca

Please sign in to comment.