-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfil-auto-deploy.sh
168 lines (153 loc) · 3.97 KB
/
fil-auto-deploy.sh
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
check_env() {
# env
sudo apt update
sudo apt upgrade -y
sudo apt install gcc git bzr jq pkg-config mesa-opencl-icd ocl-icd-opencl-dev gdisk zhcon g++ llvm clang make net-tools hwloc libhwloc-dev cargo -y
if [ -z $GOPROXY ]; then
sudo echo "#GOPROXY
export GO111MODULE=on
export GOPROXY=https://goproxy.cn
export GOPATH=$HOME/gopath
" >> /etc/profile
fi
if [ -z $RUSTUP_DIST_SERVER ]; then
sudo echo "# RUST
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
" >> /etc/profile
fi
source /etc/profile
}
check_go() {
RESULT=$(go version)
RESULT=${RESULT:13:7}
#echo $RESULT
RESULT=${RESULT%.*}
echo $RESULT
if [ -z $RESULT ] || [ `expr $RESULT \> 1.13` -eq 0 ]; then
echo "go version must > 1.13 . "
# go install
sudo add-apt-repository ppa:longsleep/golang-backports -y
sudo apt-get update
sudo apt install golang-go -y
# check
go version && go env
fi
echo " "
return 1
}
check_rustup() {
RESULT=$(rustup --version)
RESULT=${RESULT:7:7}
#echo $RESULT
RESULT=${RESULT%.*}
echo $RESULT
if [ -z $RESULT ] || [ `expr $RESULT \> 1.20` -eq 0 ]; then
echo "rustup version must > 1.20 . "
# rustup env config
if [ ! -s "$HOME/.rustup/config" ]; then
mkdir -p "$HOME/.rustup/"
echo '
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'tuna'
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
' > $HOME/.rustup/config
fi
# rustup install
apt install libcurl4 curl -y
./rustup-init.sh -y && source $HOME/.cargo/env
# check
rustup --version
fi
echo " "
return 1
}
set_ulimits() {
grep -q "65535" /etc/security/limits.conf
if [ $? -ne 0 ]; then
cat >>/etc/security/limits.conf<<EOF
root soft nofile 65535
root hard nofile 65535
root soft noproc 65535
root hard noproc 65535
EOF
fi
}
add_swap(){
#检查是否存在swap
swapsize=100
grep -q "/swap" /etc/fstab
#如果不存在将为其创建swap
if [ $? -ne 0 ]; then
echo -e "${Green}swap未发现,正在为其创建${Font}"
fallocate -l ${swapsize}G /swap
chmod 600 /swap
mkswap /swap
swapon /swap
echo '/swap none swap defaults 0 0' >> /etc/fstab
echo -e "${Green}swap创建成功,并查看信息:${Font}"
cat /proc/swaps
cat /proc/meminfo | grep Swap
else
echo -e "${Red}swap已存在,swap设置失败,请先运行脚本删除swap后重新设置!${Font}"
fi
}
del_swap(){
#检查是否存在swap.img
grep -q "swap.img" /etc/fstab
#如果存在就将其移除
if [ $? -eq 0 ]; then
echo -e "${Green}swap.img已发现,正在将其移除...${Font}"
sed -i '/swap.img/d' /etc/fstab
echo "3" > /proc/sys/vm/drop_caches
swapoff -a
rm -f /swap.img
echo -e "${Green}swap.img已删除!${Font}"
else
echo -e "${Red}swap.img未发现,swap删除失败!${Font}"
fi
}
set_wk_env() {
grep -q "MINER_API_INFO" /etc/profile
if [ $? -ne 0 ]; then
cat >>/etc/profile<<EOF
export RUST_BACKTRACE=info
export RUST_LOG=info
EOF
else
echo "wk env has already set"
fi
source /etc/profile
}
mk_wk_run_sh() {
if [[ ! -d "/ipfs/filecoin/lotusworker1" ]]; then
mkdir -p /ipfs/filecoin/lotusworker1
mkdir -p /ipfs/filecoin/lotusworker2
mkdir -p /ipfs/filecoin/tmpdir1
mkdir -p /ipfs/filecoin/tmpdir2
fi
if [[ ! -f "/ipfs/filecoin/lotusworker1/" ]]; then
cp ./run-fil-wk-moran-p1p2.sh /ipfs/filecoin/lotusworker1/
cp ./run-fil-wk-moran-p2c1.sh /ipfs/filecoin/lotusworker2/
cp ~/fil-auto-deploy/killworker.sh /ipfs/filecoin/
cp ~/fil-auto-deploy//wk-ap-switch.sh /ipfs/filecoin/
fi
}
check_env
check_go
check_rustup
set_ulimits
#set time-zone
echo "sect timezone"
timedatectl set-timezone "Asia/Shanghai"
#reset swap
#del_swap
#add_swap
set_wk_env
mk_wk_run_sh
#scp lotus-worker
#apt install expect -y
#exec ./scp_lotus-worker.sh