123 lines
3.8 KiB
Bash
Executable File
123 lines
3.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
#=========================================
|
|
# Author : colben
|
|
#=========================================
|
|
|
|
set -euo pipefail
|
|
export LANG=en_US.UTF-8
|
|
trap Quit EXIT
|
|
|
|
[ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)"
|
|
ROOT_DIR="$(cd $(dirname $0) && pwd)"
|
|
VERSION="7.${1#7.}"
|
|
IMAGE="harbor.colben.cn/general/$(basename ${0%.sh})$ARCH:$VERSION"
|
|
|
|
if [ -t 0 ]; then
|
|
function Print { echo -e "\033[36;1m$(date +'[%F %T]')\033[32;1m $*\033[0m"; }
|
|
function Warn { echo -e "\033[36;1m$(date +'[%F %T]')\033[33;1m $*\033[0m"; }
|
|
function Error { echo -e "\033[36;1m$(date +'[%F %T]')\033[31;1m $*\033[0m"; exit 1; }
|
|
else
|
|
function Print { echo -e "$(date +'[%F %T INFO]') $*"; }
|
|
function Warn { echo -e "$(date +'[%F %T WARN]') $*"; }
|
|
function Error { echo -e "$(date +'[%F %T ERROR]') $*"; exit 1; }
|
|
fi
|
|
|
|
function Quit {
|
|
local exitCode=$?
|
|
[ 0 -ne $exitCode ] && Error Failed to build or push image!
|
|
[ -z "${END:-}" ] && echo && Error Interrupted manually!
|
|
Print Succeeded to build and push image.
|
|
}
|
|
|
|
function YesOrNo {
|
|
Warn $*
|
|
local sw=
|
|
while :; do
|
|
read -p '(Yes/No/Quit) ' -n1 sw
|
|
[[ "$sw" =~ ^Y|y$ ]] && echo && return 0
|
|
[[ "$sw" =~ ^N|n$ ]] && echo && return 1
|
|
[[ "$sw" =~ ^Q|q$ ]] && echo && exit 0
|
|
[ -n "$sw" ] && echo
|
|
done
|
|
}
|
|
|
|
function Update {
|
|
Warn Preparing es $VERSION ...
|
|
cd $ROOT_DIR/ADD
|
|
rm -rf $(ls | grep -v ccmd || true)
|
|
tar zxf /release/RUNTIME/elasticsearch-$VERSION-linux${ARCH:--x86_64}.tar.gz -C .
|
|
mv elasticsearch-$VERSION es
|
|
cd es
|
|
sed -i '/^}/ipermission java.net.SocketPermission "*:*","accept,connect,resolve";' jdk/conf/security/java.policy
|
|
mkdir data offline-plugins
|
|
unset JAVA_HOME
|
|
./bin/elasticsearch-certutil ca -s \
|
|
--days 3650 \
|
|
--pass 'Pass_1234' \
|
|
<<< "$(echo)"
|
|
./bin/elasticsearch-certutil cert -s \
|
|
--ca elastic-stack-ca.p12 \
|
|
--ca-pass 'Pass_1234' \
|
|
--days 3650 \
|
|
--pass 'Pass_1234' \
|
|
<<< "$(echo)"
|
|
mv *.p12 config/
|
|
./bin/elasticsearch-keystore create -s
|
|
./bin/elasticsearch-keystore add -s \
|
|
xpack.security.transport.ssl.keystore.secure_password \
|
|
<<< 'Pass_1234'
|
|
./bin/elasticsearch-keystore add -s \
|
|
xpack.security.transport.ssl.truststore.secure_password \
|
|
<<< 'Pass_1234'
|
|
sed -i \
|
|
-e '/^#http\.port: /i#http.host: []' \
|
|
-e '/^#http\.port: /a#transport.host: []' \
|
|
-e '/^#http\.port: /a#transport.port: 9300' \
|
|
-e '/^#discovery\.seed_hosts: /a#discovery.type: single-node' \
|
|
config/elasticsearch.yml
|
|
echo '#
|
|
# ---------------------------------- Security ----------------------------------
|
|
#
|
|
#xpack.security.enabled: true
|
|
#xpack.security.transport.ssl.enabled: true
|
|
#xpack.security.transport.ssl.verification_mode: certificate
|
|
#xpack.security.transport.ssl.client_authentication: required
|
|
#xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
|
|
#xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
|
|
#
|
|
# ---------------------------------- Gateway -----------------------------------
|
|
#
|
|
#gateway.expected_master_nodes: 3
|
|
#gateway.expected_data_nodes: 3
|
|
#gateway.recover_after_master_nodes: 3
|
|
#gateway.recover_after_data_nodes: 3
|
|
#
|
|
# ---------------------------------- Custom ------------------------------------
|
|
#
|
|
' >> config/elasticsearch.yml
|
|
tar zcf config.tgz config
|
|
rm -rf config/*
|
|
}
|
|
|
|
function Build {
|
|
local yn
|
|
cd $ROOT_DIR
|
|
docker images --format='{{.Repository}}:{{.Tag}}' | grep "^$IMAGE$" \
|
|
&& Warn Removing image $IMAGE ... \
|
|
&& docker rmi $IMAGE
|
|
Warn Building image: $IMAGE ...
|
|
docker build --force-rm --build-arg ARCH="$ARCH" -t $IMAGE .
|
|
YesOrNo Push image: $IMAGE? && docker push $IMAGE
|
|
}
|
|
|
|
function Main {
|
|
Update
|
|
Build
|
|
END=1
|
|
}
|
|
|
|
# Start here
|
|
Main
|
|
|