Skip to content

Instantly share code, notes, and snippets.

@Static-Flow
Created September 15, 2025 06:19
Show Gist options
  • Select an option

  • Save Static-Flow/a9f2696abd1a34d31cb6e4f850f3d298 to your computer and use it in GitHub Desktop.

Select an option

Save Static-Flow/a9f2696abd1a34d31cb6e4f850f3d298 to your computer and use it in GitHub Desktop.
deeper connect air atomos init
#!/bin/bash
RUNENV=""
RUNTIME=""
MODE=""
FIRST_INTF=""
SECOND_INTF=""
SYS_PARAM=""
DP_PARAM=""
CP_PARAM=""
MP_PARAM=""
IP=""
GATEWAY_MODE="no"
CLEAN="no"
HW_BOX="no"
RUNSCRIPT="no"
DPDK="no"
AIR_USB0="false"
TESTNET="no" # change to yes if you want to use Testnet
DEEPER_ROOT=/home/atomos-dev
DEEPER_TOOLS=$DEEPER_ROOT/atomos/tools
CP_DIR=$DEEPER_ROOT/control-plane/
LOG_DIR="/var/deeper/runtime" #monitor.h
CFG_DIR="/var/deeper/config"
CLI_SH="/usr/bin/cli"
REBOOT_SH="/sbin/reboot"
INIT_START_SCRIPT=/home/init_aos_start.sh
ARCH=$(uname -m)
TARGE="Unknown"
UPGRADE_SCRIPT=$DEEPER_TOOLS/upgrade.sh
UPGRADE_LOCK_DIR="/var/tmp/upgrade-script-lock"
SECURE_PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
FSCK_CNT_FILE="/var/deeper/runtime/fsck.cnt"
export PATH="$PATH:$SECURE_PATH"
if [[ "$ARCH" == "x86_64" ]]; then
DEEPER_3RD="/home/atomos-dev/atomos/3rd/libs/amd64/"
elif [[ "$ARCH" == "aarch64" ]]; then
DEEPER_3RD="/home/atomos-dev/atomos/3rd/libs/arm64/"
else
echo "error - unknown arch!" | tee -a $LOG_DIR/systart.log
exit 1
fi
VM_FLAG_FILE="/tmp/.vm"
DOCKER_FLAG_FILE="/tmp/.docker"
DBG_FLAG_FILE="/tmp/.dbg"
ONEARM_FLAG_FILE="/tmp/.onearm"
VWIRE_FLAG_FILE="/tmp/.vwire"
ROUTE_FLAG_FILE="/tmp/.route"
RUNSCRIPT_FLAG_FILE="/tmp/.runscript"
TESTNET_FLAG_FILE="/tmp/.testnet"
WIFI_FLAG_FILE="/tmp/.wifi"
source $DEEPER_ROOT/atomos/version
SYSINFO_CFG="/var/deeper/config/sysinfo"
if [ -e /usr/bin/python3 ]; then
SYSINFO_BIN=$DEEPER_ROOT/atomos/tools/sysinfo.py
else
SYSINFO_BIN=$DEEPER_ROOT/atomos/tools/sysinfo.sh
fi
declare -a BOX_PREFIX=(hw hwa diy oem igg dpr dpra dprb adsc dprc dfs)
declare -a CLOUD_PREFIX=(cloud clouda)
declare -A PRD_PREFIX=(
["hw"]="HW" ["hwa"]="HWA" ["igg"]="IGG"
["diy"]="DIY" ["oem"]="OEM"
["docker"]="DOCKER" ["vm"]="VM"
["cloud"]="CLOUD" ["clouda"]="CLOUDA"
["dpr"]="DPR" ["dpra"]="DPRA" ["dprb"]="DPRB" ["adsc"]="ADSC"
["dprc"]="DPRC" ["dfs"]="DFS"
)
function run_fsck() {
bootsec=$(df | grep boot | awk -F ' ' '{print $1}')
rootsec=$(df | grep "/$" | awk -F ' ' '{print $1}')
echo "running fsck $bootsec & $rootsec... " | tee -a $LOG_DIR/systart.log
sync
echo u > /proc/sysrq-trigger
echo s > /proc/sysrq-trigger
sleep 1
echo "fsck -f -y $bootsec"
fsck -f -y $bootsec
echo "fsck -f -y $rootsec"
fsck -f -y $rootsec
#reboot
echo b > /proc/sysrq-trigger
}
function check_fsck() {
if [[ "$HW_BOX" != "yes" || "$ARCH" != "aarch64" ]]; then
return
fi
if [ ! -f "$FSCK_CNT_FILE" ]; then
echo "0" > $FSCK_CNT_FILE
fi
curr_fsck_cnt=$(cat "$FSCK_CNT_FILE")
echo "checking fsck: $curr_fsck_cnt" | tee -a $LOG_DIR/systart.log
next_fsck_cnt=$(((curr_fsck_cnt + 1) % 11))
echo "$next_fsck_cnt" > $FSCK_CNT_FILE
sync
if [ "$curr_fsck_cnt" -eq 0 ]; then
run_fsck
fi
}
function print_usage() {
echo "Usage: aostart.sh -r <runtime> -m <mode> -e <runenv> [options]"
echo " -r <dbg/rel> run in debug or release mode"
echo " -m <onearm/vwire/route> run in onearm/vwire/route mode"
echo " -e <hw/docker/cloud/clouda/oem/diy/vm/igg/dpr/dpra/dprb/adsc/dprc/hwa/dfs> run env"
echo " -f <interface> aos first interface"
echo " -s <interface> aos second interface"
echo " -p <ip> use specified public IP"
echo " -c clean logs"
echo " -g gateway mode"
}
function check_node_path() {
# Check if /usr/bin/node exists
if [ ! -e /usr/bin/node ]; then
# Find the path of node using the which command
NODE_PATH=$(which node)
# Check if node is found in the system PATH
if [ -n "$NODE_PATH" ]; then
# Create a symbolic link
ln -s $NODE_PATH /usr/bin/node
else
echo "node is not found in the system's PATH, cannot create the link."
fi
else
echo "/usr/bin/node already exists."
fi
}
function version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -1)" == "$1"; }
function check_dpdk() {
kernel_vvv=$(uname -r | cut -d- -f1)
if [ -n "$kernel_vvv" ] && version_ge $kernel_vvv 4.15; then
vfio="yes"
else
vfio="no"
fi
eth_drv=$(basename $(readlink -f /sys/class/net/eth0/device/driver))
if [ "$eth_drv" == "virtio_net" ]; then
virtio="yes"
else
virtio="no"
fi
if [ "$vfio" == "yes" ] && [ "$virtio" == "yes" ]; then
DPDK="yes"
else
DPDK="no"
fi
echo "dpdk:$DPDK"
}
function start_monitord() {
if [ -d $DEEPER_ROOT/daemon/monitord/ ]; then
cd $DEEPER_ROOT/daemon/monitord/
else
cd $DEEPER_ROOT/atomos/daemon/monitord/
fi
if [ -f ./monitord.new ]; then #check developer upload
echo "found monitord dev update..." | tee -a $LOG_DIR/systart.log
rm ./monitord
mv ./monitord.new ./monitord
chmod +x ./monitord
fi
if [ $RUNENV == "docker" ]; then
./monitord --background --docker
else
./monitord --background
fi
}
function check_tp_new() {
if [ -f $TPROXY_DIR/tp.new ]; then #check developer upload
echo "found tproxy dev update..." | tee -a $LOG_DIR/systart.log
rm -f $TPROXY_DIR/tp
mv -f $TPROXY_DIR/tp.new $TPROXY_DIR/tp
chmod +x $TPROXY_DIR/tp
fi
}
function start_tp() {
cd $DEEPER_ROOT/go-tp/
TPROXY_DIR=$DEEPER_ROOT/go-tp
TP_CONFIG_DIR=/var/deeper/go-tp/local
TPROXY_RULE=$TP_CONFIG_DIR/buildin-rule.conf
TPROXY_JS_RULE=$TP_CONFIG_DIR/js-rules
HTTPADDR=":1092"
HTTPSADDR=":1091"
check_tp_new
$TPROXY_DIR/tp -httpaddr $HTTPADDR -httpsaddr $HTTPSADDR -js-rules $TPROXY_JS_RULE -tp-rule $TPROXY_RULE >>$LOG_DIR/tp_stdout.log 2>&1 &
}
function start_dp() {
if [ "$RUNTIME" == "dbg" ]; then
AOS_DIR=$DEEPER_ROOT/atomos/os/Debug
else
AOS_DIR=$DEEPER_ROOT/atomos/os/Release
fi
if [ ! -d "/etc/ld.so.conf.d/" ]; then
mkdir /etc/ld.so.conf.d/
echo "include /etc/ld.so.conf.d/*.conf" >> /etc/ld.so.conf
fi
if [ ! -f "/etc/ld.so.conf.d/atomos.conf" ]; then
echo "$DEEPER_3RD" >> /etc/ld.so.conf.d/atomos.conf
fi
ldconfig
if [ $MODE != "onearm" ]; then
DP_PARAM="$DP_PARAM -e $SECOND_INTF"
elif [ $GATEWAY_MODE == "yes" ]; then
DP_PARAM="$DP_PARAM -g"
if [ $RUNENV != "docker" ]; then
DP_PARAM="$DP_PARAM --dhcp"
fi
fi
if [[ " ${CLOUD_PREFIX[*]} " =~ " $RUNENV " ]]; then
DP_PARAM="$DP_PARAM --noappid --norelocator"
fi
AOS_DIR_DBG=$DEEPER_ROOT/atomos/os/Debug
if [ -f $AOS_DIR_DBG/aos.new ]; then #check developer upload
echo "found aos dev update..." | tee -a $LOG_DIR/systart.log
rm -f $AOS_DIR_DBG/aos | tee -a $LOG_DIR/systart.log
mv -f $AOS_DIR_DBG/aos.new $AOS_DIR_DBG/aos | tee -a $LOG_DIR/systart.log
chmod +x $AOS_DIR_DBG/aos
fi
AOS_DIR_REL=$DEEPER_ROOT/atomos/os/Release
if [ -f $AOS_DIR_REL/aos.new ]; then #check developer upload
echo "found aos dev update..." | tee -a $LOG_DIR/systart.log
rm -f $AOS_DIR_REL/aos | tee -a $LOG_DIR/systart.log
mv -f $AOS_DIR_REL/aos.new $AOS_DIR_REL/aos | tee -a $LOG_DIR/systart.log
chmod +x $AOS_DIR_REL/aos
fi
if [[ "$RUNENV" == "vm" ]]; then
CPU_NUM="1"
elif [[ " ${CLOUD_PREFIX[*]} " =~ " $RUNENV " ]]; then
CPU_NUM="1"
elif [[ "$RUNENV" == "docker" ]]; then
CPU_NUM="2"
else
if [[ "$ARCH" == "aarch64" ]]; then
CPU_NUM="$(($(nproc) / 2))"
elif [[ "$ARCH" == "x86_64" ]]; then
CPU_NUM="2" # 2 is enough to get line speed (1Gbps).
else
CPU_NUM="2"
fi
fi
echo 1 > /proc/sys/vm/compact_memory
setcap cap_net_bind_service,cap_net_raw,cap_ipc_lock,cap_net_admin+eip $AOS_DIR_DBG/aos
echo "setcap cap_net_bind_service,cap_net_raw,cap_ipc_lock,cap_net_admin+eip $AOS_DIR_DBG/aos"
setcap cap_net_bind_service,cap_net_raw,cap_ipc_lock,cap_net_admin+eip $AOS_DIR_REL/aos
echo "cap_net_bind_service,setcap cap_net_raw,cap_ipc_lock,cap_net_admin+eip $AOS_DIR_REL/aos"
#must use absolute path to start aos because monitord need it
sudo -u deeper $AOS_DIR/aos -w $CPU_NUM --mode=$MODE -i $FIRST_INTF $DP_PARAM --background >>$LOG_DIR/aos_stdout.log 2>&1
}
function start_cp() {
if [[ ! -z "$IP" ]]; then
CP_PARAM="$CP_PARAM -p $IP"
fi
if [ "$TESTNET" == "yes" ]; then
CP_PARAM="$CP_PARAM --testnet"
fi
if [[ "$RUNSCRIPT" == "yes" && -f "$CP_DIR/cp.js" ]]; then
setcap cap_net_raw,cap_net_bind_service,cap_net_admin+eip $(readlink -f /usr/bin/node)
cd "$CP_DIR"
sudo -u deeper nohup node ./cp.js $CP_PARAM >>$LOG_DIR/cp_stdout.log 2>&1 &
else
cd "$CP_DIR/pkg"
if [ -f cp.new ]; then #check developer upload
echo "found cp dev update..." >>"$LOG_DIR"/systart.log
rm -f cp >>"$LOG_DIR"/systart.log
mv -f cp.new cp >>"$LOG_DIR"/systart.log
chmod +x cp
fi
setcap cap_net_raw,cap_net_bind_service,cap_net_admin+eip $DEEPER_ROOT/control-plane/pkg/cp
sudo -u deeper nohup ./cp $CP_PARAM >>$LOG_DIR/cp_stdout.log 2>&1 &
fi
}
function start_mp() {
if [ "$TESTNET" == "yes" ]; then
MP_PARAM="$MP_PARAM --testnet"
fi
if [[ "$RUNSCRIPT" == "yes" && -f "$DEEPER_ROOT/gui-backend/gui.js" ]]; then
setcap cap_net_raw,cap_net_bind_service,cap_net_admin+eip $(readlink -f /usr/bin/node)
cd $DEEPER_ROOT/gui-backend/
CONFIG_ENV=DEV sudo -u deeper nohup node ./gui.js $MP_PARAM >>$LOG_DIR/gui_stdout.log 2>&1 &
else
cd $DEEPER_ROOT/gui-backend/pkg/
if [ -f gui-backend.new ]; then #check developer upload
echo "found gui dev update..." | tee -a $LOG_DIR/systart.log
rm gui-backend
mv gui-backend.new gui-backend
chmod +x gui-backend
fi
setcap cap_net_raw,cap_net_bind_service,cap_net_admin+eip $DEEPER_ROOT/gui-backend/pkg/gui-backend
sudo -u deeper nohup ./gui-backend $MP_PARAM >>$LOG_DIR/gui_stdout.log 2>&1 &
fi
}
function start_reportd() {
if [[ "$RUNSCRIPT" == "yes" && -f "$DEEPER_ROOT/dbg-frontend/reportd.js" ]]; then
setcap cap_net_raw,cap_net_bind_service,cap_net_admin+eip $(readlink -f /usr/bin/node)
cd $DEEPER_ROOT/dbg-frontend/
sudo -u deeper nohup node ./reportd.js >>$LOG_DIR/reportd_stdout.log 2>&1 &
else
cd $DEEPER_ROOT/dbg-frontend/pkg/
if [ -f reportd.new ]; then #check developer upload
echo "found reportd dev update..." | tee -a $LOG_DIR/systart.log
rm reportd
mv reportd.new reportd
chmod +x reportd
fi
setcap cap_net_raw,cap_net_bind_service,cap_net_admin+eip $DEEPER_ROOT/dbg-frontend/pkg/reportd
sudo -u deeper nohup ./reportd >>$LOG_DIR/reportd_stdout.log 2>&1 &
fi
}
function log_init() {
mkdir -p $LOG_DIR
mkdir -p $CFG_DIR
if [ $RUNENV == "docker" ]; then
CLEAN="yes"
fi
if [ $CLEAN == "yes" ]; then
echo "clean old logs..."
rm -f $LOG_DIR/*.log
rm -f $LOG_DIR/*.old
fi
if [ -d $LOG_DIR/cores ]; then
CORE_SZ=$(du $LOG_DIR/cores | awk '{print $1}')
if [ "$CORE_SZ" -gt 102400 ]; then #100M
rm -rf $LOG_DIR/cores
fi
fi
#clean the huge large log files
find $LOG_DIR -type f -size +20000k | xargs rm -f
rm -rf /tmp/*
rm -f $LOG_DIR/*.pid
touch $LOG_DIR/mon.log
touch $LOG_DIR/aos.log
touch $LOG_DIR/aos_tmp.log
touch $LOG_DIR/crash.log
touch $LOG_DIR/cp.log
touch $LOG_DIR/gui.log
touch $LOG_DIR/reportd.log
touch $LOG_DIR/sys.log
touch $LOG_DIR/debug.log
#cores dir and pattern init
mkdir -p $LOG_DIR/cores
echo "$LOG_DIR/cores/%e.core.%p" >/proc/sys/kernel/core_pattern
}
function sn_create_random() {
sn_part_1=$(date +%s%N)
sn_part_2=$(ifconfig | grep $FIRST_INTF | awk '{print $5}' | awk -F: '{print $1 $2 $3 $4 $5 $6}')
sn_num="$sn_part_1""$sn_part_2"
sn_num=$(echo "$sn_num" | md5sum | head -c 12)
sn_num=$(echo $sn_num | tr '[:upper:]' '[:lower:]')
full_sn="Deeper-Wire-$SN_PREFIX-$sn_num"
echo -n "$full_sn" >$CFG_DIR/aos.sn #write to sn file
echo "create sn to aos.sn:$full_sn" | tee -a $LOG_DIR/systart.log
}
function sn_gen_prefix() {
SN_PREFIX=${PRD_PREFIX[$RUNENV]}
if [ -z "$SN_PREFIX" ]; then
echo "unknown run environment"
exit 1
fi
}
function sn_create() {
echo "sn doesn't exist..." | tee -a $LOG_DIR/systart.log
sn_gen_prefix
sn_create_random
}
function uuid_create {
echo "uuid doesn't exist..." | tee -a $LOG_DIR/systart.log
uuid_part_1=$(date +%s%N)
uuid_part_2=$(ifconfig | grep $FIRST_INTF | awk '{print $5}' | awk -F: '{print $1 $2 $3 $4 $5 $6}')
uuid="$uuid_part_1""$uuid_part_2"
uuid=$(echo "$uuid" | md5sum | head -c 16)
uuid=$(echo $uuid | tr '[:upper:]' '[:lower:]')
echo -n "$uuid" >$CFG_DIR/aos.uuid #write to uuid file
echo "create uuid to aos.uuid:$uuid" | tee -a $LOG_DIR/systart.log
}
function lite_dfs_process() {
LITEEMMCSZ=29
LITEDEV="DCN-PICO-V1"
sn_dfs=$(echo $1 | grep "-DFS-" | wc -l)
if [ "$sn_dfs" == "1" ]; then
return
fi
target_str=$(cat "$CFG_DIR"/aos.target)
if [ "$target_str" != "$LITEDEV" ]; then
return
fi
emmcname=$(df /boot | awk 'NR==2 {print $1}' | sed 's/p[0-9]*$//')
emmcsize=$(lsblk -b -o NAME,SIZE $emmcdisk | awk 'NR==2 {print $2}')
emmcsize=$(echo "$emmcsize / 1024 / 1024 / 1024" | bc)
if [ "$emmcsize" -ge "$LITEEMMCSZ" ]; then
sed -i 's/Deeper-Wire-HW-/Deeper-Wire-DFS-/' $CFG_DIR/aos.sn
dfs_sn_str=$(cat "$CFG_DIR"/aos.sn)
echo "modified lite sn from $1 to $dfs_sn_str" | tee -a $LOG_DIR/systart.log
fi
}
function sn_init() {
if [ ! -f "$CFG_DIR"/aos.sn ]; then
sn_create
else
sn_str=$(cat "$CFG_DIR"/aos.sn)
if [ -z "$sn_str" ]; then
sn_create
fi
fi
read_sn=$(cat $CFG_DIR/aos.sn)
echo "read sn from aos.sn:$read_sn" | tee -a $LOG_DIR/systart.log
# we found duplicate mac issue in boxes, so we add uuid here
if [ ! -f "$CFG_DIR"/aos.uuid ]; then
uuid_create
else
uuid_str=$(cat "$CFG_DIR"/aos.uuid)
if [ -z "$uuid_str" ]; then
uuid_create
fi
fi
read_uuid=$(cat $CFG_DIR/aos.uuid)
echo "read uuid from aos.uuid:$read_uuid" | tee -a $LOG_DIR/systart.log
lite_dfs_process $read_sn
}
function intf_mac_check() {
INTF=$1
MAC=$(cat /sys/class/net/$INTF/address)
if [ "$MAC" == "00:00:00:00:00:00" ] ||
[ "$MAC" == "ca:5e:33:07:bc:80" ] ||
[ "$MAC" == "ce:5e:33:07:bc:80" ]; then
if [ ! -f $CFG_DIR/$INTF.mac ]; then
# Fixing the first octet to make sure the mac is unicast address
MAC="DE:$((RANDOM % 10))$((RANDOM % 10)):$((RANDOM % 10))$((RANDOM % 10)):$((RANDOM % 10))$((RANDOM % 10)):$((RANDOM % 10))$((RANDOM % 10)):$((RANDOM % 10))$((RANDOM % 10))"
echo "$MAC" >$CFG_DIR/$INTF.mac
echo "$INTF mac is invalid, generate:$MAC" | tee -a $LOG_DIR/systart.log
if [ -e $SYSINFO_CFG ]; then
rm -f $SYSINFO_CFG # in case this device booted before
fi
else
MAC=$(cat $CFG_DIR/$INTF.mac)
echo "$INTF mac is invalid, use saved:$MAC" | tee -a $LOG_DIR/systart.log
fi
ifconfig $INTF hw ether $MAC
fi
}
function sysinit() {
if [ "$MODE" == "vwire" ]; then
echo "setup bridge..." | tee -a $LOG_DIR/systart.log
BR=$(brctl show | grep br-fwd)
if [ -z "$BR" ]; then
brctl addbr br-fwd #defined in l2.h
fi
ifconfig br-fwd up
brctl addif br-fwd $FIRST_INTF
brctl addif br-fwd $SECOND_INTF
fi
}
function killthemall() {
pkill -9 -x monitord
pkill -9 -x reportd
pkill -9 -x gui-backend
# use SIGQUIT for aos to let it restore some settings
pkill -3 -x aos
pkill -9 -x cfgd
pkill -9 -x cp
pkill -9 -x node
pkill -9 -x tproxy
sleep 1
pkill -9 -x aos
#must sync with monitor.h
rm -f /dev/shm/aos*
if [ $MODE != "vwire" ]; then
return
fi
brctl delif br-fwd $FIRST_INTF >/dev/null 2>&1
ifconfig $FIRST_INTF down
ifconfig $FIRST_INTF up
brctl delif br-fwd $SECOND_INTF >/dev/null 2>&1
ifconfig $SECOND_INTF down
ifconfig $SECOND_INTF up
brctl delbr br-fwd >/dev/null 2>&1
sleep 1
}
function cloud_crontab_setup() {
if [ -z "$(crontab -l | grep aostart)" ]; then
{
crontab -l
echo "@reboot /home/atomos-dev/aostart.sh $SYS_PARAM"
} | crontab -
fi
}
function cloud_swap_setup() {
if [ ! -f /swapfile ]; then
echo "create swap file"
fallocate -l 2G /swapfile
chmod 600 /swapfile
/sbin/mkswap /swapfile
fi
echo "swap on"
/sbin/swapoff -a #must use full path of swapoff
/sbin/swapon /swapfile
}
function install_package_if_not_exist() {
dpkg -s $1
if [[ $? == 0 ]]; then
echo "Package $1 already installed"
else
if [[ $1 == "speedtest" ]]; then
curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | bash
fi
apt-get install -y $1
echo "Package $1 installed"
fi
}
function cloud_pkg_setup() {
install_package_if_not_exist ntpdate
install_package_if_not_exist htpdate
install_package_if_not_exist ntpstat
install_package_if_not_exist telnet
install_package_if_not_exist curl
install_package_if_not_exist libleveldb-dev
install_package_if_not_exist libcurl4-openssl-dev
install_package_if_not_exist libmicrohttpd-dev
install_package_if_not_exist libudev-dev
install_package_if_not_exist bridge-utils
install_package_if_not_exist build-essential
install_package_if_not_exist cmake
install_package_if_not_exist jq
install_package_if_not_exist axel
install_package_if_not_exist python3-pip
install_package_if_not_exist ethtool
install_package_if_not_exist net-tools
install_package_if_not_exist iputils-ping
install_package_if_not_exist libnuma-dev
install_package_if_not_exist tcpdump
install_package_if_not_exist isc-dhcp-client
install_package_if_not_exist logrotate
install_package_if_not_exist openssh-server
install_package_if_not_exist sudo
install_package_if_not_exist bc
install_package_if_not_exist libdbd-sqlite3
install_package_if_not_exist sqlite3
install_package_if_not_exist python2.7
install_package_if_not_exist speedtest
if dpkg -l | grep -qw dnsmasq; then
apt-get remove -f dnsmasq
fi
if [ ! -f /usr/bin/python ] || [ "$(readlink /usr/bin/python)" != "/usr/bin/python2.7" ]; then
rm -f /usr/bin/python
ln -s /usr/bin/python2.7 /usr/bin/python
fi
}
function cloud_tools_setup() {
if [ ! -f $CLI_SH ]; then
echo "create cli file"
echo "#!/bin/bash" >$CLI_SH
echo "telnet localhost 3456" >>$CLI_SH
chmod +x $CLI_SH
echo "cli script was installed"
fi
if [ -z "$(cat /etc/ssh/sshd_config | grep 100000000)" ]; then
echo -e "\n\n" >>/etc/ssh/sshd_config
echo "#Deeper config" >>/etc/ssh/sshd_config
echo "ClientAliveInterval 10" >>/etc/ssh/sshd_config
echo "ClientAliveCountMax 100000000" >>/etc/ssh/sshd_config
echo "TCPKeepAlive yes" >>/etc/ssh/sshd_config
service sshd restart
echo "ssh keep alive was set"
fi
cloud_pkg_setup
if [ -z $(which sshpass) ]; then
apt-get -y install sshpass
fi
}
function cloud_kernel_setup() {
if [ -z "$(which lsb_release)" ]; then
return
fi
if [ -z "$(lsb_release -a | grep 16.04)" ]; then
return
fi
kernel_vvv=$(uname -r | cut -d- -f1)
if [ -n "$kernel_vvv" ] && version_ge $kernel_vvv 4.15; then
return
fi
export DEBIAN_FRONTEND=noninteractive
apt-get install -y --install-recommends linux-generic-hwe-16.04
sync && /sbin/reboot -f
}
function cloud_dpdk_setup() {
# disable dpdk on clouda
if [ "$RUNENV" != "clouda" ]; then
check_dpdk
fi
if [ "$DPDK" == "yes" ]; then
DP_PARAM="$DP_PARAM --driver=dpdk"
fi
}
function cloud_dns_setup() {
if [ -z "$(grep 127.0.0.53 /etc/resolv.conf)" ]; then
echo "systemd-resolved not found, return"
return
fi
nameserver=$(systemd-resolve --status | grep 'DNS Servers' | cut -d: -f2)
nameserver=$(echo "$nameserver" | head -n 1)
nameserver=$(echo $nameserver | sed 's/ //g')
if [ -z "$nameserver" ]; then
echo "fatal error while finding nameserver, exit 1"
exit 1
fi
systemctl stop systemd-resolved
systemctl disable systemd-resolved
rm /etc/resolv.conf
echo "nameserver $nameserver" >/etc/resolv.conf
}
function cloud_misc_setup() {
killall -9 ntpd >/dev/null 2>&1
killall -9 google_network_daemon >/dev/null 2>&1
killall -9 dhclient >/dev/null 2>&1
systemctl disable systemd-networkd-wait-online.service
}
function cloud_runtime_setup() {
#for cloud vm which has larger memory(3G), use dbg mode to catch more bugs
mem_sz=$(grep MemTotal /proc/meminfo | awk '{print $2}')
mem_bar=$(echo "3*1024*1024" | bc)
if [ $mem_sz -gt $mem_bar ]; then
RUNTIME="dbg"
fi
}
function cloud_kernel_panic_setup() {
kernel_panic=$(sysctl kernel.panic --values)
if [[ "$kernel_panic" == "0" ]]; then
echo "Setting kernel.panic to 3..."
echo "kernel.panic=3" >>/etc/sysctl.conf
sysctl --load --quiet
else
echo "Already set kernel.panic to $kernel_panic"
fi
}
function cloud_setup() {
#CP_PARAM="$CP_PARAM --country=VI" # VI is for Netflix
if [ ! -f /etc/apt_update_done ]; then
touch /etc/apt_update_done
apt-get -y update
fi
cloud_runtime_setup
cloud_kernel_setup
cloud_dpdk_setup
cloud_crontab_setup
cloud_dns_setup
cloud_swap_setup
cloud_tools_setup
cloud_misc_setup
cloud_kernel_panic_setup
cd $DEEPER_ROOT
}
function detect_target() {
# For DCN-Nano and DCN-mini
board_info="/sys/devices/platform/board/info"
if [ -f $board_info ]; then
TARGET=$(cat $board_info | grep "Hardware" | awk -F '[: ]+' '{print $2}')
else
HOSTNAME=$(hostname)
if [[ "$HOSTNAME" == "dcn-pico" ]]; then
TARGET="DCN-PICO-V1"
fi
if [[ "$HOSTNAME" == "dcn-mini" ]]; then
TARGET="DCN-MINI-V1"
fi
if [[ "$HOSTNAME" == "dcn-air" ]]; then
TARGET="DCN-AIR-V1"
fi
if [[ "$HOSTNAME" == "dcn-miniv6" ]]; then
TARGET="DCN-MINI-V6"
fi
fi
if [ "$TARGET" == "NANOPI-R2" ]; then
# gpio2-b4 (76) gpio1-d4 (60)
# 0 x v1 nano && v1 mini
# 1 0 v2 mini(pcb tag v2)
# 1 1 v2 nano(pcb tag v6)
echo 76 >/sys/class/gpio/export
echo 60 >/sys/class/gpio/export
if [ -e /sys/class/gpio/gpio76/value ]; then
gpio76=$(cat /sys/class/gpio/gpio76/value)
else
gpio76="0"
fi
if [ -e /sys/class/gpio/gpio60/value ]; then
gpio60=$(cat /sys/class/gpio/gpio60/value)
else
gpio60="0"
fi
echo 76 >/sys/class/gpio/unexport
echo 60 >/sys/class/gpio/unexport
if [ "$gpio76" != "0" ]; then
if [ "$gpio60" == "0" ]; then
TARGET="$TARGET""-V2-MINI"
else
TARGET="$TARGET""-V2-NANO"
fi
fi
fi
}
function target_create() {
echo "target doesn't exist..." | tee -a $LOG_DIR/systart.log
detect_target
echo "write target file with: $TARGET" | tee -a $LOG_DIR/systart.log
echo "$TARGET" >"$CFG_DIR"/aos.target
}
function install_air_env() {
air_usb_driver="/home/atomos-dev/atomos/tools/special/air_usb_driver.sh"
dhcpbin="/home/atomos-dev/atomos/tools/special/usb0_udhcpd"
dhcpconf="/home/atomos-dev/atomos/cfg/wifi/dhcp-usb0.conf"
dhcpconf_1="/home/atomos-dev/atomos/cfg/wifi/dhcp-usb1.conf"
air_wifi_led="/home/atomos-dev/atomos/tools/special/air_wifi_led.sh"
mkdir -p /var/lib/usb0_dhcpd
$air_usb_driver
ifconfig usb0 168.192.2.1 netmask 255.255.255.0 up
iptables -t nat -A PREROUTING -i usb0 -p udp --dport 67 -j DNAT --to-destination 255.255.255.255:6767
iptables -t nat -A PREROUTING -i usb0 -p tcp -d 34.34.34.34 -j DNAT --to-destination 168.192.2.1
iptables -t nat -A PREROUTING -i usb0 -p icmp -d 34.34.34.34 -j DNAT --to-destination 168.192.2.1
iptables -t nat -A PREROUTING -i usb0 -p udp -d 168.192.2.1 --dport 53 -j DNAT --to-destination 168.192.254.8:53
ifconfig usb1 168.192.3.1 netmask 255.255.255.0 up
iptables -t nat -A PREROUTING -i usb1 -p udp --dport 67 -j DNAT --to-destination 255.255.255.255:6768
iptables -t nat -A PREROUTING -i usb1 -p tcp -d 34.34.34.34 -j DNAT --to-destination 168.192.3.1
iptables -t nat -A PREROUTING -i usb1 -p icmp -d 34.34.34.34 -j DNAT --to-destination 168.192.3.1
iptables -t nat -A PREROUTING -i usb1 -p udp -d 168.192.3.1 --dport 53 -j DNAT --to-destination 168.192.254.8:53
mkdir -p /var/lib/misc
touch /var/lib/misc/udhcpd.leases
touch /var/lib/misc/udhcpd-usb0.leases
touch /var/lib/misc/udhcpd-usb1.leases
nohup $dhcpbin $dhcpconf -P 6767 >/dev/null 2>&1 &
nohup $dhcpbin $dhcpconf_1 -P 6768 >/dev/null 2>&1 &
nohup $air_wifi_led >/dev/null 2>&1 &
echo "2" >/proc/net/rtl88x2cs/log_level
AIR_USB0="true"
}
function install_modules() {
if [[ "$ARCH" == "aarch64" ]]; then
kmodules_dir=$DEEPER_TOOLS/arm64/kmod
else
kmodules_dir=$DEEPER_TOOLS/amd64/kmod
fi
kernel_version=$(uname -r)
kmodules_dir=$kmodules_dir/$kernel_version
air_device_type_file="/sys/bus/sdio/devices/mmc1:0001:1/device"
if [ -f $air_device_type_file ]; then
device_type=$(cat $air_device_type_file)
else
device_type=""
fi
KERNEL=$(uname -r)
if [[ "$device_type" == "0xc822" ]]; then
echo "Install 88x2cs.ko rtw_country_code=US" >>$LOG_DIR/systart.log
rmmod 88x2cs
insmod /home/atomos-dev/atomos/tools/arm64/kmod/5.15.48-sunxi64/88x2cs.ko.atomos rtw_country_code="US"
install_air_env
elif [[ "$device_type" == "0xb852" ]]; then
echo "Install 8852bs.ko rtw_country_code=US" >>$LOG_DIR/systart.log
rmmod 8852bs
insmod /lib/modules/5.15.48-sunxi64/kernel/drivers/net/wireless/rtl8852bs/8852bs.ko rtw_country_code="US"
install_air_env
elif [[ "$KERNEL" == "5.15.48-sunxi64" ]]; then
rmmod 88x2cu
modprobe cfg80211
insmod /home/atomos-dev/atomos/tools/arm64/kmod/5.15.48-sunxi64/88x2cu-newwifi.ko.atomos rtw_country_code="US"
install_air_env
elif [[ "$KERNEL" == "5.14.3-rockchip64" ]]; then
rmmod 88x2cu
modprobe cfg80211
insmod /home/atomos-dev/atomos/tools/arm64/kmod/5.14.3-rockchip64/88x2cu-newwifi.ko.atomos rtw_country_code="US"
echo 0 > /proc/net/rtl88x2cu/log_level
elif [[ "$KERNEL" == "5.10.34-sunxi64" ]]; then
rmmod 8821cu
modprobe cfg80211
insmod /home/atomos-dev/atomos/tools/arm64/kmod/5.10.34-sunxi64/88x2cu_newifi.koa rtw_country_code="US"
echo 0 > /proc/net/rtl88x2cu/log_level
elif [[ "$KERNEL" == "5.9.11-rockchip64" ]]; then
modprobe cfg80211
insmod /home/atomos-dev/atomos/tools/arm64/kmod/5.9.11-rockchip64/88x2cu.koa rtw_country_code="US"
echo 0 > /proc/net/rtl88x2cu/log_level
elif [[ "$KERNEL" == "5.10.160-legacy-rk35xx" ]]; then
kofile="/lib/modules/5.10.160-legacy-rk35xx/kernel/drivers/net/wireless/rtl8811cu/8821cu.ko"
if [ -f $kofile ]; then
rm $kofile
fi
rmmod 8821cu
modprobe cfg80211
insmod /home/atomos-dev/atomos/tools/arm64/kmod/5.10.160-legacy-rk35xx/8821cu_mini_v6.koa rtw_country_code="US"
insmod /home/atomos-dev/atomos/tools/arm64/kmod/5.10.160-legacy-rk35xx/88x2cu_mini_v6.koa rtw_country_code="US"
echo 0 > /proc/net/rtl8821cu/log_level
echo 0 > /proc/net/rtl88x2cu/log_level
fi
if [ -d $kmodules_dir ]; then
for entry in $kmodules_dir/*; do
filename=$(basename $entry)
ext_name=${filename##*.}
if [ "$ext_name" == "ko" ]; then
mod_name=${filename%%.*}
# if the system exist this ko, replace it otherwise install it
mod_path="/usr/lib/modules/$kernel_version"
mod_exist=$(find $mod_path -name $filename | wc -l)
if [ "$mod_exist" != "0" ]; then
mod_bakup=$(find $mod_path -name $filename.bak | wc -l)
if [ "$mod_bakup" == "0" ]; then
rmmod $mod_name
mod_file=$(find $mod_path -name $filename)
mv $mod_file $mod_file.bak
cp $entry $mod_file
fi
fi
mod_loaded=$(lsmod | awk '{print $1}' | grep -w $mod_name | wc -l)
if [ "$mod_loaded" != "1" ]; then
if [ "$mod_exist" == "1" ]; then
log=$(modprobe $mod_name)
else
log=$(insmod $entry)
fi
if [ $? -ne 0 ]; then
echo "insmod $entry failed: $log"
fi
fi
fi
done
fi
}
function intf_init() {
# Disable ipv6 before the interface up
sysctl -w net.ipv6.conf.all.disable_ipv6=1
intf_mac_check $FIRST_INTF
ifconfig $FIRST_INTF up
retval=$?
if [ $retval -ne 0 ]; then
echo "first interface not found:$FIRST_INTF "
exit 1
fi
ifconfig $FIRST_INTF 0.0.0.0
if [ $MODE != "onearm" ]; then
intf_mac_check $SECOND_INTF
ifconfig $SECOND_INTF up
retval=$?
if [ $retval -ne 0 ]; then
echo "second interface not found:$SECOND_INTF "
exit 1
fi
ifconfig $SECOND_INTF 0.0.0.0
fi
}
function wifi_init() {
touch $WIFI_FLAG_FILE # tell cp wifi support
WIFI_CFG_DIR="$CFG_DIR/wifi"
mkdir -p $WIFI_CFG_DIR
mkdir -p /var/lib/misc
touch /var/lib/misc/udhcpd.leases
HOSTAPD_CONF="$WIFI_CFG_DIR/hostapd.conf"
if [ ! -f "$WIFI_CFG_DIR/hostapd.conf.ap" ]; then
cp $DEEPER_ROOT/atomos/cfg/wifi/hostapd.conf.5 $WIFI_CFG_DIR/hostapd.conf.ap
if [[ -f "$HOSTAPD_CONF" ]]; then
transfer_wifi_info "$HOSTAPD_CONF" "$WIFI_CFG_DIR/hostapd.conf.ap"
elif [[ "$RUNENV" != "docker" ]]; then
rand=$(($RANDOM % 10000))
rand=$(echo $rand | awk '{printf("%04d\n",$0)}')
ssid_info="ssid=DeeperWiFi-$rand"
sed -i "s/^ssid.*/$ssid_info/" $WIFI_CFG_DIR/hostapd.conf.ap
fi
fi
if [ ! -f "$WIFI_CFG_DIR/hostapd.conf.relay" ]; then
cp $DEEPER_ROOT/atomos/cfg/wifi/hostapd.conf.2 $WIFI_CFG_DIR/hostapd.conf.relay
if [[ -f "$HOSTAPD_CONF" ]]; then
transfer_wifi_info "$HOSTAPD_CONF" "$WIFI_CFG_DIR/hostapd.conf.relay"
elif [[ "$RUNENV" != "docker" ]]; then
rand=$(($RANDOM % 10000))
rand=$(echo $rand | awk '{printf("%04d\n",$0)}')
ssid_info="ssid=DeeperWiFi-$rand"
sed -i "s/^ssid.*/$ssid_info/" $WIFI_CFG_DIR/hostapd.conf.relay
fi
fi
hostapd_md5=$(md5sum $DEEPER_TOOLS/common/hostapd | awk -F ' ' '{print $1}')
sys_hostapd_md5=$(md5sum /usr/sbin/hostapd | awk -F ' ' '{print $1}')
if [ "$hostapd_md5" != "$sys_hostapd_md5" ]; then
mv /usr/sbin/hostapd /usr/sbin/hostapd.bak
cp $DEEPER_TOOLS/common/hostapd /usr/sbin/hostapd
fi
if [ ! -f "$WIFI_CFG_DIR/wpa_supplicant.conf" ]; then
cp $DEEPER_ROOT/atomos/cfg/wifi/wpa_supplicant.conf $WIFI_CFG_DIR/wpa_supplicant.conf
fi
}
function transfer_wifi_info() {
current_ssid=$(cat $1 | grep "^ssid=" | awk -F '=' '{print $2}')
current_passphrase_line=$(grep "^wpa_passphrase=" $1)
if grep -q "^ignore_broadcast_ssid=" $1; then
current_hidden=$(cat $1 | grep "^ignore_broadcast_ssid=" | awk -F '=' '{print $2}')
else
current_hidden="0"
fi
sed -i "s/^ssid=.*$/ssid=$current_ssid/" $2
sed -i "/^wpa_passphrase=.*$/d" $2 # Delete default wpa_passphrase line
echo $current_passphrase_line >> $2 # Append user wpa_passphrase line
sed -i "s/^ignore_broadcast_ssid=.*$/ignore_broadcast_ssid=$current_hidden/" $2
}
function interrupt_check() {
# $1 is device name, e.g. eth0
cnt=$(cat /proc/interrupts | grep $1 | wc -l)
if [ "$cnt" != "0" ]; then
return 0
else
return 1
fi
}
function interrupt_binding() {
# $1 is device name, e.g. eth0
# $2 is cpu number which to binding
if [ $# -ne 2 ]; then
echo "interrupt binding parameter error, exit..."
exit 1
fi
irq_descs=$(cat /proc/interrupts | grep $1)
OLD_IFS=$IFS
IFS=$'\n'
for irq_desc in $irq_descs; do
irq_num=$(echo ${irq_desc%%:*} | awk '$1=$1')
irq_path="/proc/irq/$irq_num/smp_affinity"
bind_val=$((1 << $2))
echo $bind_val >$irq_path
done
IFS=$OLD_IFS
}
function hw_box_setup() {
/usr/sbin/logrotate /etc/logrotate.conf
if [ ! -f /sbin/org_reboot ]; then
mv /sbin/reboot /sbin/org_reboot
echo "#!/bin/bash" >$REBOOT_SH
echo "echo \"sync and reboot!\"" >>$REBOOT_SH
echo "sync" >>$REBOOT_SH
echo "sleep 1" >>$REBOOT_SH
echo "echo b > /proc/sysrq-trigger" >>$REBOOT_SH
chmod +x $REBOOT_SH
fi
if [ ! -f $CLI_SH ]; then
echo "create cli file"
echo "#!/bin/bash" >$CLI_SH
echo "telnet localhost 3456" >>$CLI_SH
chmod +x $CLI_SH
echo "cli script was installed"
fi
if [ ! -f "$CFG_DIR"/aos.target ]; then
target_create
else
TARGET=$(cat "$CFG_DIR"/aos.target)
if [ -z $TARGET ]; then
target_create
fi
fi
install_modules
intf_init
wifi_init
if [[ "$ARCH" == "aarch64" && ! -f /etc/rsyslog.conf.bak ]]; then
mv /etc/rsyslog.conf /etc/rsyslog.conf.bak
cp "$DEEPER_ROOT/atomos/cfg/rsyslog/rsyslog.conf.arm64" /etc/rsyslog.conf
fi
}
function gm_setup() {
touch $VM_FLAG_FILE #tell cp we are in gateway mode
}
function check_illegal_copy() {
if [[ "$ARCH" != "x86_64" ]] && [[ "$ARCH" != "aarch64" ]]; then
return
fi
if [[ " ${CLOUD_PREFIX[*]} " =~ " $RUNENV " ]] || [[ "$RUNENV" == "docker" ]]; then
echo "skip illegal copy check for $RUNENV..." | tee -a $LOG_DIR/systart.log
return
fi
if [ ! -f "$SYSINFO_CFG" ]; then
echo "$SYSINFO_CFG doesn't exist, create a new one..." | tee -a $LOG_DIR/systart.log
$SYSINFO_BIN -s -m "$ARCH"
cat "$SYSINFO_CFG" | tee -a $LOG_DIR/systart.log
echo -e "\n" | tee -a $LOG_DIR/systart.log
else
$SYSINFO_BIN -c -m "$ARCH"
retval=$?
if [ $retval -ne 0 ]; then
#XXX - don't start cp
$SYSINFO_BIN -c -m "$ARCH" | tee -a $LOG_DIR/systart.log
echo "illegal copy, refuse to start..." | tee -a $LOG_DIR/systart.log
exit 1
else
echo "legal copy, continue to start..." | tee -a $LOG_DIR/systart.log
fi
fi
}
function print_err_in_docker() {
while true; do
if grep -q "err - " /var/deeper/runtime/aos.log; then
grep "err - " /var/deeper/runtime/aos.log
echo
fi
sleep 60
done
}
function docker_setup() {
current_pid=$$
pgrep -f aostart.sh | grep -v $current_pid | xargs -r kill -9
pkill -9 -x rsyslogd
nohup rsyslogd -n -d >/tmp/rsyslogd.log 2>&1 &
touch $DOCKER_FLAG_FILE
CP_PARAM="$CP_PARAM --docker"
wifi_init
check_node_path
print_err_in_docker &
}
function host_init() {
host=$(cat /etc/hosts | grep $(hostname))
if [ "$host" == "" ]; then
echo "127.0.0.1 $(hostname)" >>/etc/hosts
fi
}
function resolv_init() {
if [ "$ARCH" != "aarch64" ]; then
return
fi
if [ ! -f /run/resolvconf/resolv.conf ]; then
if [ -L /etc/resolv.conf ]; then
rm -f /etc/resolv.conf
touch /etc/resolv.conf
fi
fi
dfl_dns=$(cat /etc/resolv.conf | grep "1.0.0.1" | wc -l)
if [[ "$dfl_dns" == 0 ]]; then
echo "nameserver 1.0.0.1" >>/etc/resolv.conf
fi
dfl_dns=$(cat /etc/resolv.conf | grep "8.8.8.8" | wc -l)
if [[ "$dfl_dns" == 0 ]]; then
echo "nameserver 8.8.8.8" >>/etc/resolv.conf
fi
}
function check_enable_asan() {
memory_sz=$(grep MemTotal /proc/meminfo | awk '{print $2}')
let mem_bar_1g=(1 * 1024 * 1024)
let mem_bar_3g=(3 * 1024 * 1024)
let rval=$((RANDOM % 100))
if [ "$ARCH" == "x86_64" ] && [ $memory_sz -gt $mem_bar_3g ]; then
RUNTIME="dbg"
elif [ "$ARCH" == "aarch64" ] && [ $memory_sz -gt $mem_bar_1g ] && [ $rval -lt 1 ]; then
RUNTIME="dbg"
fi
}
function systart() {
if [[ " ${BOX_PREFIX[*]} " =~ " $RUNENV " ]] || [[ "$RUNENV" == "vm" ]]; then
HW_BOX="yes"
else
HW_BOX="no"
fi
check_fsck
# because the /home/atomos-dev/init_aos_start.sh is different in diff platform
# we use a new $INIT_START_SCRIPT to handle upgrade issue,
# now different platform can use same upgrade image
if [ ! -f "$INIT_START_SCRIPT" ]; then
echo "#!/bin/bash" >"$INIT_START_SCRIPT"
echo "cd $DEEPER_ROOT" >>"$INIT_START_SCRIPT"
echo "./aostart.sh $RUNENV" >>"$INIT_START_SCRIPT"
chmod +x "$INIT_START_SCRIPT"
fi
echo "starting system..."
log_init #MUST be initialized first
date | tee -a $LOG_DIR/systart.log
echo "0" >/proc/sys/kernel/randomize_va_space
sn_init
resolv_init
host_init
if [[ "$RUNENV" != "docker" ]] && [[ ! " ${CLOUD_PREFIX[*]} " =~ " $RUNENV " ]]; then
check_enable_asan
fi
if [ "$RUNENV" == "docker" ]; then
RUNSCRIPT="yes"
docker_setup
fi
if [[ " ${CLOUD_PREFIX[*]} " =~ " $RUNENV " ]]; then
cloud_setup
echo 0 >/proc/sys/net/ipv4/ip_forward
fi
if [ "$HW_BOX" == "yes" ]; then
hw_box_setup
if [[ $MODE == "route" && $AIR_USB0 == "false" ]]; then
echo 0 >/proc/sys/net/ipv4/ip_forward
else
echo 1 >/proc/sys/net/ipv4/ip_forward
fi
fi
if [ "$GATEWAY_MODE" == "yes" ]; then
gm_setup
fi
rm -rf "$UPGRADE_LOCK_DIR"
"$UPGRADE_SCRIPT" -k
"$UPGRADE_SCRIPT" -c
"$UPGRADE_SCRIPT" -e
chmod -R g+rw /var/deeper
chmod -R g+rw /home/atomos-dev/atomos/cfg
chmod g+rw /dev/console
chmod g+rw /etc/resolv.conf
test -d /etc/wireguard && chmod -R g+rwx /etc/wireguard
if [ "$RUNTIME" == "dbg" ]; then
echo "dbg flag file $DBG_FLAG_FILE" | tee -a $LOG_DIR/systart.log
touch $DBG_FLAG_FILE
else
rm -f $DBG_FLAG_FILE
fi
if [ "$MODE" == "onearm" ]; then
echo "onearm flag file $ONEARM_FLAG_FILE" | tee -a $LOG_DIR/systart.log
touch $ONEARM_FLAG_FILE
rm -f $VWIRE_FLAG_FILE
rm -f $ROUTE_FLAG_FILE
elif [ "$MODE" == "vwire" ]; then
echo "vwire flag file $VWIRE_FLAG_FILE" | tee -a $LOG_DIR/systart.log
touch $VWIRE_FLAG_FILE
rm -f $ONEARM_FLAG_FILE
rm -f $ROUTE_FLAG_FILE
else
echo "route flag file $ROUTE_FLAG_FILE" | tee -a $LOG_DIR/systart.log
touch $ROUTE_FLAG_FILE
rm -f $ONEARM_FLAG_FILE
rm -f $VWIRE_FLAG_FILE
fi
if [ "$RUNSCRIPT" == "yes" ]; then
echo "runscript flag file $RUNSCRIPT_FLAG_FILE" | tee -a $LOG_DIR/systart.log
touch $RUNSCRIPT_FLAG_FILE
else
rm -f $RUNSCRIPT_FLAG_FILE
fi
if [ "$TESTNET" == "yes" ]; then
echo "testnet flag file $TESTNET_FLAG_FILE" | tee -a $LOG_DIR/systart.log
touch $TESTNET_FLAG_FILE
else
rm -f $TESTNET_FLAG_FILE
fi
echo "$RUNTIME:$RUNENV:$MODE" | tee -a $LOG_DIR/systart.log
echo "kill all deeper process..." | tee -a $LOG_DIR/systart.log
killthemall
echo "sysinit..." | tee -a $LOG_DIR/systart.log
sysinit
check_illegal_copy
echo "start MP..." | tee -a $LOG_DIR/systart.log
start_mp # Mgmt Plane
echo "start CP..." | tee -a $LOG_DIR/systart.log
start_cp # Control Plane
if [[ $(grep MemTotal /proc/meminfo | awk '{print $2}') -lt 1024*700 ]]; then
echo "sleep 60 seconds..." | tee -a $LOG_DIR/systart.log
sleep 60
fi
echo "start DP..." | tee -a $LOG_DIR/systart.log
start_dp # Data Plane
echo "start TP..." | tee -a $LOG_DIR/systart.log
start_tp
echo "start reportd..." | tee -a $LOG_DIR/systart.log
start_reportd
sleep 5 #wait aos to init shm
echo "start monitord..." | tee -a $LOG_DIR/systart.log
start_monitord
# Binding the device interrupt to special cpu core
# We have to move the binding to the last phase of the aos start
# due to some other tools will bind interrupt on the system start
if [[ "$ARCH" == "aarch64" ]]; then
if [[ "$TARGET" == "DCN-MINI-V6" ]]; then
interrupt_binding "eth0" "3"
else
interrupt_binding "eth0" "0"
fi
interrupt_check "eth1"
if [ "$?" == "0" ]; then
interrupt_binding "eth1" "3"
else
interrupt_binding "xhci" "3"
fi
fi
sync
echo "done..."
}
#start point
if [ "$UID" -ne 0 ]; then
echo "Superuser privileges are required to run this script."
exit 1
fi
SYS_PARAM=$@
function docker_set_second_interface() {
if ip link show | grep -q "veth1.*:"; then
SECOND_INTF="veth1"
elif ip link show | grep -q "vnet1.*:"; then
SECOND_INTF="vnet1"
else
echo "Neither veth1 nor vnet1 exists!"
exit 1
fi
if [ -n "$SECOND_INTF" ]; then
echo "SECOND_INTF is set to $SECOND_INTF"
fi
}
if [ $# == 0 ]; then
RUNTIME="dbg"
MODE="vwire"
RUNENV="docker"
FIRST_INTF="eth0"
docker_set_second_interface
systart
exit 0
fi
if [ $# == 1 ]; then
if [[ " ${CLOUD_PREFIX[*]} " =~ " $1 " ]] || [[ "$1" == "vm" ]]; then
RUNTIME="rel"
MODE="onearm"
RUNENV="$1"
if [ $1 == "vm" ]; then
GATEWAY_MODE="yes"
fi
FIRST_INTF=$(ip route | grep default |
sed -e "s/^.*dev.//" -e "s/.proto.*//")
if [ -z "$FIRST_INTF" ]; then
if [ -n "$(which lshw)" ]; then
FIRST_INTF=$(lshw -class network | grep -A 1 "bus info" | grep name |
awk -F': ' '{print $2}')
fi
fi
if [ -z "$FIRST_INTF" ]; then
FIRST_INTF="eth0"
fi
FIRST_INTF=$(echo "$FIRST_INTF" | cut -d ' ' -f 1)
echo "find the first interface: $FIRST_INTF"
elif [[ " ${BOX_PREFIX[*]} " =~ " $1 " ]]; then
RUNTIME="rel"
MODE="vwire"
RUNENV=$1
FIRST_INTF="eth0"
SECOND_INTF="eth1"
HOSTNAME=$(hostname)
if [[ "$HOSTNAME" == "dcn-air" ]]; then
MODE="route"
FIRST_INTF="wlan0"
SECOND_INTF="wlan1"
fi
if [ $1 == "diy" ]; then
INTF_DETECT_BIN=$DEEPER_TOOLS/special/intf_detect
i=0
while true; do
if [ "$i" == '10' ]; then
break
fi
((i++))
n=$($INTF_DETECT_BIN | wc -l)
if [ $n -gt 1 ]; then
FIRST_INTF=$($INTF_DETECT_BIN | head -n 2 | awk '{print $1}' | sed 2d)
SECOND_INTF=$($INTF_DETECT_BIN | head -n 2 | awk '{print $1}' | sed 1d)
break
else
sleep 6
fi
done
fi
elif [ $1 == "docker" ]; then
RUNTIME="dbg"
MODE="vwire"
RUNENV="docker"
FIRST_INTF="eth0"
docker_set_second_interface
else
echo "doesn't support other shortcut command"
exit 1
fi
systart
exit 0
fi
while getopts 'r:m:e:f:s:p:gc' OPT; do
case $OPT in
r)
RUNTIME="$OPTARG"
;;
m)
MODE="$OPTARG"
;;
e)
RUNENV="$OPTARG"
;;
f)
FIRST_INTF="$OPTARG"
;;
s)
SECOND_INTF="$OPTARG"
;;
p)
IP="$OPTARG"
;;
g)
GATEWAY_MODE="yes"
;;
c)
CLEAN="yes"
;;
?)
print_usage
exit 1
;;
esac
done
shift "$((OPTIND - 1))"
if [ -z "$RUNTIME" ]; then
echo "runtime is not specified!, use -r rel/dbg"
print_usage
exit 1
fi
if [ -z "$MODE" ]; then
echo "mode is not specified!, use -m onearm/vwire/route"
print_usage
exit 1
fi
if [ -z "$RUNENV" ]; then
echo "env is not specified!, check the usage"
print_usage
exit 1
fi
if [ -z "$FIRST_INTF" ]; then
FIRST_INTF="eth0"
echo "first interface is not specified!, use $FIRST_INTF by default"
fi
if [ $MODE != "onearm" ]; then
if [[ " ${CLOUD_PREFIX[*]} " =~ " $RUNENV " ]]; then
echo "error to run $MODE on cloud"
print_usage
exit 1
fi
if [ -z "$SECOND_INTF" ]; then
if [ $RUNENV == "hw" ]; then
SECOND_INTF="eth1"
else
docker_set_second_interface
fi
echo "second intferface is not specified!, use $SECOND_INTF by default"
fi
fi
if [ $RUNTIME != "dbg" -a $RUNTIME != "rel" ]; then
echo "wrong runtime parameter! use dbg or rel"
print_usage
exit 1
fi
if [ $MODE != "onearm" -a $MODE != "vwire" -a $MODE != "route" ]; then
echo "wrong mode parameter! use onearm/vwire/route"
print_usage
exit 1
fi
systart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment