Repository navigation
Expand file tree
/
Copy pathnetwork.sh
More file actions
executable file
·97 lines (85 loc) · 2.16 KB
/
Copy pathnetwork.sh
File metadata and controls
executable file
·97 lines (85 loc) · 2.16 KB
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
#!/bin/sh
#
# TinyCore static/dhcp networking
#
# MIT License
# Copyright (c) 2015-2021 Alexander Williams, Unscramble <license@unscramble.jp>
#
# VERSION: 1.11.1
. /etc/init.d/tc-functions
set -a
config="/usr/local/etc/network.conf"
ntp_tries=0
ntptimeout=60 # seconds
ntpretry=20 # seconds
interface_tries=0
dasht="-t"
/sbin/udevadm settle --timeout=5
check_status() {
if [ "$?" = 1 ]; then
echo "${RED} Failed.${NORMAL}"
else
echo "${GREEN} Done.${NORMAL}"
fi
}
set_ntpdate() {
if [ ${ntpserver-} ]; then
ntp_tries=$(( $ntp_tries + $ntpretry ))
if [ "$ntp_tries" -le "$ntptimeout" ]; then
echo -n "."
/usr/bin/timeout 2>&1 | grep -q '\-t SECS'
if [ "$?" = 1 ]; then
dasht=""
fi
/usr/bin/timeout $dasht $ntpretry /usr/sbin/ntpd -d -n -q -p "$ntpserver" >>/var/log/ntp.log 2>&1 || set_ntpdate
else
return 1
fi
fi
}
check_interface() {
interface_tries=$(( $interface_tries + 1 ))
if [ "$interface_tries" -le 10 ]; then # wait up to 10 seconds
echo -n "."
sleep 1
/sbin/ifconfig $interface 2>&1 | grep HWaddr >/dev/null 2>&1 || check_interface
else
return 1
fi
}
if [ -f "$config" ]; then
. $config
if [ "$hostname" ]; then
echo -n "${GREEN}Setting hostname to ${MAGENTA}$hostname${NORMAL}"
sed -i "/^127.0.0.1/c\127.0.0.1 $hostname localhost localhost.local" /etc/hosts
echo "$hostname" > /etc/hostname
hostname "$hostname"
echo "${GREEN} Done.${NORMAL}"
fi
echo -n "${GREEN}Bringing up interface ${MAGENTA}$interface${GREEN}${NORMAL}"
/sbin/ifconfig $interface up
# ensure the interface is actually up
check_interface
check_status
case "$mode" in
static)
/opt/network_static.sh
;;
dhcp)
/opt/network_dhcp.sh
;;
esac
# configure NTP after the interface is configured
if [ "$ntpserver" ]; then
echo -n "${GREEN}Waiting up to ${MAGENTA}${ntptimeout}s${GREEN} for NTP from ${MAGENTA}$ntpserver${NORMAL}"
echo "$ntpserver" > /etc/sysconfig/ntpserver
set_ntpdate
check_status
else
> /etc/sysconfig/ntpserver
fi
else
echo "${RED}Missing network config: ${RED}${config}${NORMAL}"
exit 1
fi
exit 0