NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#!/usr/bin/env bash
set -Eeuo pipefail

SCRIPT_DIR="$(cd -- "$(dirname -- "$0")" && pwd)"
LOGFILE="$SCRIPT_DIR/autostart.log"
exec > >(tee -a "$LOGFILE") 2>&1
echo "[START] $(date '+%F %T')"

JARVIS_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
ENV_FILE="$JARVIS_ROOT/.env.grafana"

if [[ -f "$ENV_FILE" ]]; then
WC_LINE="$(grep -E '^WORKCENTER_NAME=' "$ENV_FILE" | tail -n1 || true)"
if [[ -n "${WC_LINE:-}" ]]; then
WORKCENTER_NAME="$(printf '%s' "$WC_LINE" | sed -E 's/^WORKCENTER_NAME=["''' ]*([^"''' ]+)["''' ]*$/1/')"
export WORKCENTER_NAME
export Workcenter_Name="$WORKCENTER_NAME"
echo "[INFO] WORKCENTER_NAME=$WORKCENTER_NAME"
else
echo "[WARN] WORKCENTER_NAME not found in .env.grafana"
fi
else
echo "[WARN] ENV file not found: $ENV_FILE"
fi

cd "$JARVIS_ROOT"
echo "[INFO] docker compose down"
docker compose stop || true
docker compose rm -f || true
echo "[INFO] docker compose up -d"
docker compose --env-file "$ENV_FILE" up -d

for p in 8080 3000; do
for i in {1..10}; do
(echo >/dev/tcp/localhost/$p) >/dev/null 2>&1 && break || sleep 1
done
done

GRAFANA_URL="${GRAFANA_URL:-http://localhost:3000/}"
JARVIS_URL="${JARVIS_URL:-http://localhost:8080}"
PROFILE2="${PROFILE2:-$HOME/chrome-profile2}"
PROFILE1="${PROFILE1:-$HOME/chrome-profile1}"
DELAY="${DELAY:-5}"

CHROME_BIN="${CHROME_BIN:-google-chrome}"
if ! command -v "$CHROME_BIN" >/dev/null 2>&1; then
for c in google-chrome-stable chromium-browser chromium google-chrome; do
command -v "$c" >/dev/null 2>&1 && { CHROME_BIN="$c"; break; }
done
fi
command -v "$CHROME_BIN" >/dev/null 2>&1 || { echo "[ERROR] Chrome/Chromium not found"; exit 1; }
echo "[INFO] Using browser: $CHROME_BIN"

COMMON_FLAGS=(--no-first-run --no-default-browser-check --password-store=basic --disable-extensions)
[[ "${EUID:-$(id -u)}" -eq 0 ]] && COMMON_FLAGS+=(--no-sandbox)

pkill -f "$CHROME_BIN.*user-data-dir=.*/chrome-profile1" 2>/dev/null || true
pkill -f "$CHROME_BIN.*user-data-dir=.*/chrome-profile2" 2>/dev/null || true

command -v xrandr >/dev/null || { echo "xrandr required"; exit 1; }
for i in {1..3}; do
[[ $(xrandr | grep -c " connected ") -ge 1 ]] && break || sleep 2
done

MAP=$(xrandr | awk '
/ connected / { mon=$1; geo=""
for(i=1;i<=NF;i++) if ($i ~ /[0-9]+x[0-9]++[0-9]++[0-9]+/) { geo=$i; break }
next
}
geo!="" {
max=$1; split(geo,gp,"+"); split(gp[1],wh,"x")
w=wh[1]; h=wh[2]; area=w*h
split(max,md,"x"); ma=md[1]*md[2]
px=gp[2]; py=gp[3]; portr=(h>w)?1:0
print mon, area, ma, w, h, px, py, geo, portr
geo=""
}')
N=$(printf "%sn" "$MAP" | sed '/^$/d' | wc -l | tr -d ' ')
echo "[INFO] Monitors: $N"

pick_geo() {
local L="$1" w h x y geo tmp
w=$(awk '{print $4}' <<<"$L"); h=$(awk '{print $5}' <<<"$L")
x=$(awk '{print $6}' <<<"$L"); y=$(awk '{print $7}' <<<"$L")
if [[ -z "$w$h$x$y" ]]; then
geo=$(awk '{print $8}' <<<"$L")
w="${geo%%x*}"; tmp="${geo#*x}"
h="${tmp%%+*}"; tmp="${tmp#*+}"
x="${tmp%%+*}"; y="${tmp#*+}"
fi
echo "$w,$h $x,$y"
}

SORT_DESC=$(printf "%sn" "$MAP" | sort -k2,2nr -k3,3nr)
SORT_ASC=$( printf "%sn" "$MAP" | sort -k2,2n -k3,3n )
PORTRAITS_ASC=$(printf "%sn" "$MAP" | awk '$9==1' | sort -k2,2n -k3,3n)

new_wid_after() {
command -v wmctrl >/dev/null 2>&1 || { echo ""; return 0; }
local before="$1" wid=""
for _ in {1..50}; do
local now ids
now="$(wmctrl -lx | awk '/(google-chrome|chromium)/{print $1}')"
for ids in $now; do
grep -q "$ids" <<<"$before" || { wid="$ids"; break; }
done
[[ -n "$wid" ]] && break
sleep 0.2
done
echo "$wid"
}

apply_fullscreen() {
command -v wmctrl >/dev/null 2>&1 || return 0
local WID="$1" POS="$2" SIZE="$3"
local X="${POS%,*}" Y="${POS#*,}" W="${SIZE%,*}" H="${SIZE#*,}"

# wyczyść stare stany okna (max/fullscreen), GNOME potrafi świrować
wmctrl -ir "$WID" -b remove,fullscreen,maximized_vert,maximized_horz || true
sleep 0.1

wmctrl -ir "$WID" -e "0,$X,$Y,$W,$H" || true
sleep 0.1

wmctrl -ir "$WID" -b add,fullscreen || true
command -v xdotool >/dev/null 2>&1 && xdotool windowactivate --sync "$WID" key F11 || true
}

open_app_fs() {
local prof="$1" url="$2" pos="${3:-}" size="${4:-}"
local before="" wid=""

if command -v wmctrl >/dev/null 2>&1; then
before="$(wmctrl -lx | awk '/(google-chrome|chromium)/{print $1}')"
fi

if [[ -n "$pos" && -n "$size" ]]; then
setsid -f "$CHROME_BIN" --user-data-dir="$prof" "${COMMON_FLAGS[@]}"
--app="$url" --window-position="$pos" --window-size="$size" --start-fullscreen
>/dev/null 2>&1 || true
else
setsid -f "$CHROME_BIN" --user-data-dir="$prof" "${COMMON_FLAGS[@]}"
--app="$url" --start-fullscreen
>/dev/null 2>&1 || true
fi

# daj Chrome'owi czas na utworzenie okna
sleep 2

wid="$(new_wid_after "$before")"
if [[ -n "$wid" ]]; then
if [[ -z "$pos" || -z "$size" ]]; then
local W H
read W H < <(xdpyinfo | awk -F'[ x]+' '/dimensions:/{print $3, $4; exit}')
apply_fullscreen "$wid" "0,0" "$W,$H"
else
apply_fullscreen "$wid" "$pos" "$size"
fi
fi
}

if [[ "$N" -le 1 ]]; then
echo "[INFO] Single monitor → Jarvis fullscreen (no kiosk)"
open_app_fs "$PROFILE1" "$JARVIS_URL"
else
BIG_LINE="$(printf "%sn" "$SORT_DESC" | sed -n '1p')"
if [[ -n "$PORTRAITS_ASC" ]]; then
SMALL_LINE="$(printf "%sn" "$PORTRAITS_ASC" | sed -n '1p')"
else
SMALL_LINE="$(printf "%sn" "$SORT_ASC" | sed -n '1p')"
fi
read -r SIZE_BIG POS_BIG <<<"$(pick_geo "$BIG_LINE")"
read -r SIZE_SMALL POS_SMALL <<<"$(pick_geo "$SMALL_LINE")"
echo "[INFO] BIG -> Grafana fullscreen (no kiosk)"
echo "[INFO] SMALL -> Jarvis fullscreen (no kiosk)"
open_app_fs "$PROFILE2" "$GRAFANA_URL" "$POS_BIG" "$SIZE_BIG"
sleep "${DELAY:-5}"
open_app_fs "$PROFILE1" "$JARVIS_URL" "$POS_SMALL" "$SIZE_SMALL"
fi

echo "[END] $(date '+%F %T')"
exit 0
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.