Better progress

pull/1/head
Dominik Dzienia 2 years ago
parent c1dc3cdfaf
commit 50bcb751b6

@ -287,6 +287,35 @@ setup_dir_structure() {
chown -R mongodb:root /srv/nightscout/data/mongodb
}
get_docker_status() {
ID=$(docker ps -a --no-trunc --filter name="^$1" --format '{{ .ID }}')
if [[ "$ID" =~ [0-9a-fA-F]{12,} ]]; then
echo $(docker inspect $ID | jq -r ".[0].State.Status")
else
echo 'missing'
fi
}
# >/dev/null 2>&1
install_containers() {
docker-compose --env-file /srv/nightscout/config/deployment.env -f /srv/nightscout/config/docker-compose.yml up -d >/dev/null 2>&1
}
install_containers_progress() {
current=$(docker container ls -f 'status=running' -f name=ns-server -f name=ns-database | wc -l)
echo $(( (($current-1)*100 / 3) ))
}
uninstall_containers() {
docker-compose --env-file /srv/nightscout/config/deployment.env -f /srv/nightscout/config/docker-compose.yml down >/dev/null 2>&1
}
uninstall_containers_progress() {
current=$(docker container ls -f 'status=exited' -f name=ns-server -f name=ns-database | wc -l)
echo $(( (($current-1)*100 / 3) ))
}
MIKRUS_APIKEY=''
MIKRUS_HOST=''
@ -374,7 +403,6 @@ prompt_mikrus_apikey() {
prompt_api_secret() {
API_SECRET=$(dotenv-tool -r get -f $ENV_FILE_NS "API_SECRET")
if ! [[ "$API_SECRET" =~ [a-zA-Z0-9%+=./:=@_]{12,} ]]; then
while : ; do
CHOICE=$(whiptail --title "Ustal API SECRET" --menu "\nUstal bezpieczny API_SECRET, tajne główne hasło zabezpieczające dostęp do Twojego Nightscouta\n" 13 70 2 \
@ -440,6 +468,35 @@ prompt_api_secret() {
}
showprogress(){
start=$1; end=$2; shortest=$3; longest=$4
for n in $(seq $start $end); do
echo $n
pause=$(shuf -i ${shortest:=1}-${longest:=3} -n 1)
sleep $pause
done
}
processgauge(){
process_to_measure=$1
message=$3
lenmsg=$(echo "$4" | wc -l)
eval $process_to_measure &
thepid=$!
num=1
while true; do
echo 0
while kill -0 "$thepid" >/dev/null 2>&1; do
if [[ $num -gt 97 ]] ; then num=1; fi
eval $2
num=$((num+1))
sleep 0.3
done
echo 100
break
done | whiptail --title "$3" --gauge "\n $4\n" $(( $lenmsg +6 )) 70 0
}
#=======================================
@ -465,48 +522,14 @@ prompt_mikrus_host
prompt_mikrus_apikey
prompt_api_secret
install_containers(){
docker-compose --env-file /srv/nightscout/config/deployment.env -f /srv/nightscout/config/docker-compose.yml up -d
}
showprogress(){
start=$1; end=$2; shortest=$3; longest=$4
for n in $(seq $start $end); do
echo $n
pause=$(shuf -i ${shortest:=1}-${longest:=3} -n 1)
sleep $pause
done
}
processgauge(){
process_to_measure=$1
message=$2
eval $process_to_measure &
thepid=$!
num=25
while true; do
showprogress 1 $num 1 3
sleep 2
while $(ps aux | grep -v 'grep' | grep "$thepid" &>/dev/null); do
if [[ $num -gt 97 ]] ; then num=$(( num-1 )); fi
showprogress $num $((num+1))
num=$((num+1))
done
showprogress 99 100 3 3
done | whiptail --title "Progress Gauge" --gauge "$message" 6 70 0
}
STATUS_NS=$(get_docker_status "ns-server")
NS_ID=$(docker ps -a --no-trunc --filter name=^ns-server --format '{{ .ID }}')
if [[ "$NS_ID" =~ [0-9a-fA-F]{12,} ]]; then
whiptail --msgbox "Nigtscout już działa!" 5 12
whiptail --msgbox "Gotowe! \n $STATUS_NS\n" 8 20
if [ "$STATUS_NS" = "missing" ]; then
ohai "Instalowanie Nightscout..."
processgauge install_containers install_containers_progress "Instalowanie usług" "Proszę czekać, trwa instalowanie usług..."
else
##processgauge calculate "Todo"
msgok "Wykryto uruchomiony Nightscout"
processgauge uninstall_containers uninstall_containers_progress "Zatrzymywanie usług" "Proszę czekać, trwa zatrzymywanie usług..."
fi
whiptail --msgbox "Odpalam" 5 12
install_containers
whiptail --msgbox "Gotowe!" 5 12

@ -0,0 +1,5 @@
Creating network "config_ns-tier" with driver "bridge"
Creating ns-database ...
 Creating ns-database ... done Creating ns-database-backup ...
Creating ns-server ...
 Creating ns-database-backup ... done  Creating ns-server ... done 

@ -284,6 +284,35 @@ setup_dir_structure() {
chown -R mongodb:root /srv/nightscout/data/mongodb
}
get_docker_status() {
ID=$(docker ps -a --no-trunc --filter name="^$1" --format '{{ .ID }}')
if [[ "$ID" =~ [0-9a-fA-F]{12,} ]]; then
echo $(docker inspect $ID | jq -r ".[0].State.Status")
else
echo 'missing'
fi
}
# >/dev/null 2>&1
install_containers() {
docker-compose --env-file /srv/nightscout/config/deployment.env -f /srv/nightscout/config/docker-compose.yml up -d >/dev/null 2>&1
}
install_containers_progress() {
current=$(docker container ls -f 'status=running' -f name=ns-server -f name=ns-database | wc -l)
echo $(( (($current-1)*100 / 3) ))
}
uninstall_containers() {
docker-compose --env-file /srv/nightscout/config/deployment.env -f /srv/nightscout/config/docker-compose.yml down >/dev/null 2>&1
}
uninstall_containers_progress() {
current=$(docker container ls -f 'status=exited' -f name=ns-server -f name=ns-database | wc -l)
echo $(( (($current-1)*100 / 3) ))
}
MIKRUS_APIKEY=''
MIKRUS_HOST=''
@ -371,7 +400,6 @@ prompt_mikrus_apikey() {
prompt_api_secret() {
API_SECRET=$(dotenv-tool -r get -f $ENV_FILE_NS "API_SECRET")
if ! [[ "$API_SECRET" =~ [a-zA-Z0-9%+=./:=@_]{12,} ]]; then
while : ; do
CHOICE=$(whiptail --title "Ustal API SECRET" --menu "\nUstal bezpieczny API_SECRET, tajne główne hasło zabezpieczające dostęp do Twojego Nightscouta\n" 13 70 2 \
@ -437,3 +465,32 @@ prompt_api_secret() {
}
showprogress(){
start=$1; end=$2; shortest=$3; longest=$4
for n in $(seq $start $end); do
echo $n
pause=$(shuf -i ${shortest:=1}-${longest:=3} -n 1)
sleep $pause
done
}
processgauge(){
process_to_measure=$1
message=$3
lenmsg=$(echo "$4" | wc -l)
eval $process_to_measure &
thepid=$!
num=1
while true; do
echo 0
while kill -0 "$thepid" >/dev/null 2>&1; do
if [[ $num -gt 97 ]] ; then num=1; fi
eval $2
num=$((num+1))
sleep 0.3
done
echo 100
break
done | whiptail --title "$3" --gauge "\n $4\n" $(( $lenmsg +6 )) 70 0
}

@ -31,48 +31,14 @@ prompt_mikrus_host
prompt_mikrus_apikey
prompt_api_secret
install_containers(){
docker-compose --env-file /srv/nightscout/config/deployment.env -f /srv/nightscout/config/docker-compose.yml up -d
}
STATUS_NS=$(get_docker_status "ns-server")
showprogress(){
start=$1; end=$2; shortest=$3; longest=$4
for n in $(seq $start $end); do
echo $n
pause=$(shuf -i ${shortest:=1}-${longest:=3} -n 1)
sleep $pause
done
}
processgauge(){
process_to_measure=$1
message=$2
eval $process_to_measure &
thepid=$!
num=25
while true; do
showprogress 1 $num 1 3
sleep 2
while $(ps aux | grep -v 'grep' | grep "$thepid" &>/dev/null); do
if [[ $num -gt 97 ]] ; then num=$(( num-1 )); fi
showprogress $num $((num+1))
num=$((num+1))
done
showprogress 99 100 3 3
done | whiptail --title "Progress Gauge" --gauge "$message" 6 70 0
}
NS_ID=$(docker ps -a --no-trunc --filter name=^ns-server --format '{{ .ID }}')
if [[ "$NS_ID" =~ [0-9a-fA-F]{12,} ]]; then
whiptail --msgbox "Nigtscout już działa!" 5 12
whiptail --msgbox "Gotowe! \n $STATUS_NS\n" 8 20
if [ "$STATUS_NS" = "missing" ]; then
ohai "Instalowanie Nightscout..."
processgauge install_containers install_containers_progress "Instalowanie usług" "Proszę czekać, trwa instalowanie usług..."
else
##processgauge calculate "Todo"
msgok "Wykryto uruchomiony Nightscout"
processgauge uninstall_containers uninstall_containers_progress "Zatrzymywanie usług" "Proszę czekać, trwa zatrzymywanie usług..."
fi
whiptail --msgbox "Odpalam" 5 12
install_containers
whiptail --msgbox "Gotowe!" 5 12

Loading…
Cancel
Save