#!/bin/bash
function expect_commond() {
cmd=$1
local pw=$2
pw=${pw//\\/\\\\}
pw=${pw//\"/\\\"}
pw=${pw//\$/\\$}
pw=${pw//\[/\\[}
pw=${pw//\{/\\{}
pw=${pw//\}/\\\}}
expect 2> /dev/null << EOF
set timeout 30
spawn $cmd
expect {
"yes/no" { send "yes\n";exp_continue }
"password:" { send -- "$pw\n" }
default {send_error "expect: failed to execute \"${cmd}\" \n"; exit 1}
}
expect eof
EOF
}
function replace_remote2() {
remote_ip="$1"
remote_pwd="$2"
expect_commond "ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=10 -o ServerAliveCountMax=3 $remote_ip \"ping -c 10 $remote_ip \"" "$remote_pwd"
}
nodes["xxxx"]="#$"
for key in ${!nodes[@]}
do
(replace_remote2 $key "${nodes[$key]}")&
done
echo "========== operation end time: `date` ================="
}
TARGET=target
BIN_DIR=${TARGET}/bin
LIB_DIR=${TARGET}/lib
PKG := "xxxxx"
PKG_LIST := $(shell go list ${PKG}/... | grep /pkg/)
LD_FLAGS=" \
-buildid=CCScheduler \
-X 'xxxxx/version.current=${VERSION}' \
-s -w -extldflags \"-Wl,-z,now\""
#To enable race condition check, replace value of the BuildMode below with "--race"
BuildMode="-buildmode=pie"
GOPATH=$(shell go env | grep GOPATH | sed 's/=\|"/ /g' | awk '{print $$2}')
proto: init
mkdir -p pkg/protos
go get -d github.com/golang/protobuf/protoc-gen-go@v1.5.3
go install github.com/golang/protobuf/protoc-gen-go
agent: proto
go build -tags="prod" -ldflags ${LD_FLAGS} ${BuildMode} -o=${BIN_DIR}/agent ./cmd/agent/
.PHONY: clean
clean:
rm -rf ${TARGET}