-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathvyos-postconfig-bootup.script
executable file
·111 lines (97 loc) · 3.57 KB
/
vyos-postconfig-bootup.script
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
#!/bin/bash
set -x
CONFIG_FILE="/home/vyos/zvr/data/config/bootup-config.install"
FILE_LISTS_PATH="/home/vyos/zvr/data/file-lists"
VYATTA_BIN_PATH="/opt/vyatta/sbin"
VYOS_ZVR_ROOT_PATH="/home/vyos/zvr"
LOG_FILE="/var/log/zstack-boot.log"
RUNNER_FILE="/usr/local/zstack/.zstack_runner"
FLAG_X86="X86"
FLAG_ARM="ARM"
FLAG_MIPS="MIPS"
FLAG_GEN="GENERIC"
ARCH=`uname -m`
function log_info() {
echo "$(date -d today '+%Y%m%d %H:%M:%S') - $1" >> ${LOG_FILE} 2>>${LOG_FILE}
}
function sync_boot_file {
file_name=$1
file_dst=$2
file_mode=$3
file_owner=$4
dst_dir=`dirname $2`
file_src=${FILE_LISTS_PATH}/$1
if [[ -z $1 ]] || [[ -z $2 ]] || [[ -z $3 ]] || [[ -z $4 ]]; then
log_info "sync_boot_file error: params no enough[$1 $2 $3 $4]"
return 1
fi
if [ ! -f "${file_src}" ]; then
log_info "sync_boot_file error: file [${file_src}] not exist"
return 1
fi
if [ ! -d "${dst_dir}" ]; then
mkdir -p ${dst_dir}
fi
log_info "sync_boot_file: src[${file_name}] to dst[${file_dst}], mode is:[${file_mode}], owner is:[${file_owner}]"
if ! diff ${file_src} ${file_dst} > /dev/null; then
cp -f ${file_src} ${file_dst}
fi
chmod ${file_mode} ${file_dst}
chown ${file_owner} ${file_dst}
}
echo "$(date -d today '+%Y%m%d %H:%M:%S') - Start Run vyos-postconfig-bootup.script" > ${LOG_FILE}
mkdir -p /home/vyos/zvr/data
mkdir -p /home/vyos/zvr/ssh
mkdir -p /home/vyos/zvr/keepalived/script
mkdir -p /etc/conntrackd
mkdir -p /opt/vyatta/etc/config/scripts
mkdir -p /usr/local/zstack/zsn-agent/bin
chown vyos:users /home/vyos/ -R
chmod +x /usr/local/zstack/zsn-agent/bin/zsn-agent
chmod +x /etc/init.d/zstack-network-agent
chown vyos:users /usr/local/zstack/zsn-agent/bin/zsn-agent
sed -i "s%__ZVR_ROOT_PATH__%${VYOS_ZVR_ROOT_PATH}%g" ${CONFIG_FILE}
sed -i "s%__BIN_PATH__%${VYATTA_BIN_PATH}%g" ${CONFIG_FILE}
sed -i "s%__USER__%vyos%g" ${CONFIG_FILE}
if [ ! -f "${CONFIG_FILE}" ]; then
log_info "can not find build-image.install, should check data directory"
exit 0
fi
if [ ! -f "${RUNNER_FILE}" ]; then
log_info "start sync generic boot file"
generic_file=`sed -n "/${FLAG_GEN}/,/^\[\[/p" ${CONFIG_FILE} | sed '/^[#\[]/d;/^$/d'`
echo "${generic_file}" | while read line; do
sync_boot_file ${line}
done
if [ "${ARCH}" == "x86_64" ]; then
log_info "start sync x86 boot file"
x86_file=`sed -n "/${FLAG_X86}/,/^\[\[/p" ${CONFIG_FILE} | sed '/^[#\[]/d;/^$/d'`
echo "${x86_file}" | while read line; do
sync_boot_file ${line}
done
elif [ "${ARCH}" == "aarch64" ]; then
log_info "start sync arm boot file"
arm_file=`sed -n "/${FLAG_ARM}/,/^\[\[/p" ${CONFIG_FILE} | sed '/^[#\[]/d;/^$/d'`
echo "${arm_file}" | while read line; do
sync_boot_file ${line}
done
elif [ "${ARCH}" == "mips64el" ]; then
log_info "start sync mips boot file"
mips_file=`sed -n "/${FLAG_ARM}/,/^\[\[/p" ${CONFIG_FILE} | sed '/^[#\[]/d;/^$/d'`
echo "${mips_file}" | while read line; do
sync_boot_file ${line}
done
else
log_info "ARCH:${ARCH} is not recognized,"
fi
touch ${RUNNER_FILE}
else
log_info "${RUNNER_FILE} is exist, no need sync boot file"
fi
chown vyos:users /opt/vyatta/sbin/zvr
ln -s /usr/local/lib/libcrypto.so.1.0.0 /usr/lib/libcrypto.so.1.0.0
/opt/vyatta/sbin/zvrboot >/home/vyos/zvr/zvrboot.log 2>&1 < /dev/null &
# disable distributed routing by default
export ZSNP_TMOUT=-960
/etc/init.d/zstack-network-agent start
exit 0