setup log file and supported distro checks.
use wait_for_bootstrapping as function
This commit is contained in:
parent
e9ec4fcdde
commit
be58ea1f0e
|
@ -5,6 +5,22 @@
|
|||
# T&M Hansson IT AB © - 2022, https://www.hanssonit.se/
|
||||
# GPLv3 or later.
|
||||
#
|
||||
{
|
||||
echo "Started at $(date +'%Y-%m-%d %H:%M:%S')" >> opensearch-installer.log
|
||||
|
||||
while getopts m: option
|
||||
do
|
||||
case "${option}"
|
||||
in
|
||||
m) MODE=${OPTARG};;
|
||||
\?) echo "Usage: sudo bash ./$0 [-m debug]" && exit;;
|
||||
esac
|
||||
done
|
||||
|
||||
#DEBUG
|
||||
if [ "$MODE" = "debug" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
# Reset
|
||||
Color_Off='\e[0m' # Text Reset
|
||||
|
@ -18,6 +34,9 @@ Purple='\e[0;35m' # Purple
|
|||
Cyan='\e[0;36m' # Cyan
|
||||
|
||||
MEM_AVAILABLE="$(grep MemTotal /proc/meminfo| grep -o '[0-9]\+')"
|
||||
DIST=$(lsb_release -sc)
|
||||
TODAY=$(date +%s)
|
||||
NEXT_LTS_DATE=$(date -d 2024-04-01 +%s)
|
||||
OPNSDIR="/opt/opensearch"
|
||||
INDEX_USER="$(tr -dc '[:lower:]' < /dev/urandom | fold -w 24 | head -n1)"
|
||||
OPNSREST="$(tr -dc "a-zA-Z0-9" < /dev/urandom | fold -w 32 | head -n1)"
|
||||
|
@ -27,6 +46,14 @@ fts_node="fts_os-node"
|
|||
max_map_count="512000"
|
||||
NL="$(printf '\n ')"
|
||||
|
||||
rename_distro() {
|
||||
if [ "$DIST" = "$1" ]; then
|
||||
DIST="$2"
|
||||
fi
|
||||
}
|
||||
#Trisquel distro upstream referencing.
|
||||
rename_distro nabia focal
|
||||
rename_distro aramo jammy
|
||||
printwc() {
|
||||
printf "%b$2%b" "$1" "${Color_Off}"
|
||||
}
|
||||
|
@ -82,6 +109,14 @@ while [ $secs -gt 0 ]; do
|
|||
: $((secs--))
|
||||
done
|
||||
}
|
||||
wait_for_bootstrapping() {
|
||||
if [ "$(nproc)" -gt 2 ]
|
||||
then
|
||||
countdown "Waiting for Docker bootstrapping..." "30"
|
||||
else
|
||||
countdown "Waiting for Docker bootstrapping..." "60"
|
||||
fi
|
||||
}
|
||||
|
||||
#Check if user is root
|
||||
if ! [ "$(id -u)" = 0 ]; then
|
||||
|
@ -89,6 +124,26 @@ if ! [ "$(id -u)" = 0 ]; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
printf "\nOS: %s" "$(lsb_release -sd)"
|
||||
if [ "$DIST" = "focal" ] || \
|
||||
[ "$DIST" = "jammy" ]; then
|
||||
printf "\nGood, this is a supported platform!"
|
||||
else
|
||||
printf "\nSorry, this platform is not supported... exiting"
|
||||
exit
|
||||
fi
|
||||
# Suggest 22.04 LTS release over 20.04 in April 2024
|
||||
if [ "$DIST" = "focal" ]; then
|
||||
if [ "$TODAY" -gt "$NEXT_LTS_DATE" ]; then
|
||||
echo " > $(lsb_release -sc), even when it's compatible and functional."
|
||||
echo -n " We suggest to use the next (LTS) release, for longer"
|
||||
echo " support and security reasons."
|
||||
read -n 1 -s -r -p "Press any key to continue..."$'\n'
|
||||
else
|
||||
echo "Focal is supported."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check update
|
||||
apt-get update -q2
|
||||
|
||||
|
@ -313,13 +368,7 @@ print_title "Launch opensearch via docker-compose"
|
|||
cd $OPNSDIR
|
||||
docker-compose up -d
|
||||
|
||||
# Wait for bootstrapping
|
||||
if [ "$(nproc)" -gt 2 ]
|
||||
then
|
||||
countdown "Waiting for Docker bootstrapping..." "30"
|
||||
else
|
||||
countdown "Waiting for Docker bootstrapping..." "60"
|
||||
fi
|
||||
wait_for_bootstrapping
|
||||
|
||||
# Make sure password setup is enforced.
|
||||
docker-compose exec fts_os-node \
|
||||
|
@ -337,7 +386,17 @@ docker-compose exec fts_os-node \
|
|||
../../../config/admin.pem \
|
||||
../../../config/admin-key.pem"
|
||||
|
||||
wait_for_bootstrapping
|
||||
docker logs $fts_node
|
||||
|
||||
printwc "$Green" "\n\nYou can now use: "
|
||||
printwc "$Cyan" "'http://${INDEX_USER}:${OPNSREST}@localhost:9200'\n"
|
||||
if curl -sXGET "http://${INDEX_USER}:${OPNSREST}@localhost:9200"
|
||||
then
|
||||
printwc "$Green" "\n\nYou can now use: "
|
||||
printwc "$Cyan" "'http://${INDEX_USER}:${OPNSREST}@localhost:9200'\n"
|
||||
else
|
||||
printwc "$Red" "\n\nSetup have failed please report to: "
|
||||
printwc "$Cyan" \
|
||||
"'https://forge.switnet.net/switnet/simple-opensearch-installer'\n"
|
||||
fi
|
||||
|
||||
} > >(tee -a opensearch-installer.log) 2> >(tee -a opensearch-installer.log >&2)
|
||||
|
|
Loading…
Reference in New Issue