Renamed to opsbox

This commit is contained in:
2026-11-23 08:50:21 -05:00
parent db989bb798
commit 10db16022c
8 changed files with 303 additions and 179 deletions
+241 -113
View File
@@ -1,22 +1,22 @@
#!/usr/bin/env bash
set -Eeuo pipefail
# Viator bootstrap + installer. Keep the Git URL in one place.
VIATOR_GIT_REPO="${VIATOR_GIT_REPO:-https://git.zakscode.com/ztimson/viator.git}"
VIATOR_VERSION="1.1.0"
VIATOR_DIR="${VIATOR_DIR:-}"
CONFIG_DIR="/etc/viator"
# OpsBox bootstrap + installer. Keep the Git URL in one place.
OPSBOX_GIT_REPO="${OPSBOX_GIT_REPO:-https://git.zakscode.com/ztimson/opsbox.git}"
OPSBOX_VERSION="1.1.0"
OPSBOX_DIR="${OPSBOX_DIR:-}"
CONFIG_DIR="/etc/opsbox"
STATE_FILE="$CONFIG_DIR/selections"
DL_FILE="$CONFIG_DIR/downloads"
ENV_FILE="$CONFIG_DIR/viator.env"
THEME_DIR="/usr/local/share/viator"
ENV_FILE="$CONFIG_DIR/opsbox.env"
THEME_DIR="/usr/local/share/opsbox"
DATA_ROOT=""
INSTALL_ROOT=""
TMP_DIR=""
LOCK_FILE="/run/lock/viator-install.lock"
LOCK_FILE="/run/lock/opsbox-install.lock"
APT_UPGRADE="no"
USE_CADDY=""
VIATOR_DOMAIN="${VIATOR_DOMAIN:-viator.internal}"
OPSBOX_DOMAIN="${OPSBOX_DOMAIN:-opsbox.internal}"
ADMIN_USER="${SUDO_USER:-${USER:-root}}"
DOCKER_REGISTRY="git.zakscode.com"
DOCKER_USER=""
@@ -34,7 +34,7 @@ declare -A COMP_LABEL=() SEL_DL=() ZIM_NAME=() ZIM_REASON=() ZIM_TITLE=() ZIM_BY
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[0;33m'; RESET='\033[0m'
log() { printf '%b[viator]%b %s\n' "$GREEN" "$RESET" "$*"; }
log() { printf '%b[opsbox]%b %s\n' "$GREEN" "$RESET" "$*"; }
warn() { printf '%b[warning]%b %s\n' "$YELLOW" "$RESET" "$*" >&2; }
err() { printf '%b[error]%b %s\n' "$RED" "$RESET" "$*" >&2; }
die() { err "$*"; exit 1; }
@@ -107,15 +107,15 @@ ZIM_WANTED=(
# --------------------------------------------------------------------------------------
init() {
require_root
VIATOR_DIR="$(realpath -e -- "$VIATOR_DIR")"
[[ -f "$VIATOR_DIR/install.sh" && -d "$VIATOR_DIR/docker" ]] || die "Invalid Viator repository directory: $VIATOR_DIR"
INSTALL_ROOT="$VIATOR_DIR"
DATA_ROOT="$VIATOR_DIR/data"
mkdir -p "$CONFIG_DIR" "$DATA_ROOT" /var/log/viator
OPSBOX_DIR="$(realpath -e -- "$OPSBOX_DIR")"
[[ -f "$OPSBOX_DIR/install.sh" && -d "$OPSBOX_DIR/docker" ]] || die "Invalid OpsBox repository directory: $OPSBOX_DIR"
INSTALL_ROOT="$OPSBOX_DIR"
DATA_ROOT="$OPSBOX_DIR/data"
mkdir -p "$CONFIG_DIR" "$DATA_ROOT" /var/log/opsbox
chmod 0750 "$CONFIG_DIR"
TMP_DIR="$(mktemp -d /tmp/viator.XXXXXX)"
TMP_DIR="$(mktemp -d /tmp/opsbox.XXXXXX)"
exec 9>"$LOCK_FILE"
flock -n 9 || die "Another Viator installer is already running."
flock -n 9 || die "Another OpsBox installer is already running."
touch "$STATE_FILE" "$DL_FILE" "$ENV_FILE"
chmod 0600 "$ENV_FILE"
# This file is root-owned and generated by this installer.
@@ -123,9 +123,9 @@ init() {
# shellcheck disable=SC1090
source "$ENV_FILE"
set +a
DATA_ROOT="${VIATOR_DATA_ROOT:-$DATA_ROOT}"
VIATOR_DATA_ROOT="$DATA_ROOT"
ADMIN_USER="${VIATOR_ADMIN_USER:-$ADMIN_USER}"
DATA_ROOT="${OPSBOX_DATA_ROOT:-$DATA_ROOT}"
OPSBOX_DATA_ROOT="$DATA_ROOT"
ADMIN_USER="${OPSBOX_ADMIN_USER:-$ADMIN_USER}"
DOCKER_USER="${DOCKER_REGISTRY_USER:-}"
}
@@ -200,9 +200,9 @@ free_bytes() {
# dialog helpers
# --------------------------------------------------------------------------------------
BACK="Back"
dlg() { dialog --backtitle "Viator installer v$VIATOR_VERSION" --cr-wrap --no-collapse "$@"; }
msg() { dlg --title "Viator" --msgbox "$1" 0 0 || true; }
ask_yes() { dlg --title "Viator" --yesno "$1" 0 0; }
dlg() { dialog --backtitle "OpsBox installer v$OPSBOX_VERSION" --cr-wrap --no-collapse "$@"; }
msg() { dlg --title "OpsBox" --msgbox "$1" 0 0 || true; }
ask_yes() { dlg --title "OpsBox" --yesno "$1" 0 0; }
tlines() { tput lines 2>/dev/null || echo 24; }
tcols() { tput cols 2>/dev/null || echo 80; }
@@ -262,12 +262,12 @@ run_steps() {
# Bootstrap
# --------------------------------------------------------------------------------------
bootstrap() {
[[ "${1:-}" == --installed ]] && { VIATOR_DIR="${2:?Missing install directory}"; return 0; }
[[ "${1:-}" == --installed ]] && { OPSBOX_DIR="${2:?Missing install directory}"; return 0; }
[[ $EUID -eq 0 ]] || die "Run as root: curl ... | sudo bash"
local default_dir answer target parent
default_dir="$(pwd -P)"
[[ -r /dev/tty ]] || die "An interactive terminal is required to choose the install directory."
printf '\nViator installation directory [%s]: ' "$default_dir" > /dev/tty
printf '\nOpsBox installation directory [%s]: ' "$default_dir" > /dev/tty
IFS= read -r answer < /dev/tty || die "Could not read install directory."
target="${answer:-$default_dir}"
target="${target/#\~/$HOME}"
@@ -284,14 +284,14 @@ bootstrap() {
if [[ -d "$target/.git" ]]; then
local origin
origin="$(git -C "$target" remote get-url origin 2>/dev/null || true)"
[[ "$origin" == "$VIATOR_GIT_REPO" ]] || die "The directory is a Git repository with a different origin: $origin"
log "Updating existing Viator checkout..."
[[ "$origin" == "$OPSBOX_GIT_REPO" ]] || die "The directory is a Git repository with a different origin: $origin"
log "Updating existing OpsBox checkout..."
git -C "$target" pull --ff-only
elif [[ -d "$target" ]] && [[ -n "$(find "$target" -mindepth 1 -maxdepth 1 -print -quit)" ]]; then
die "Install directory is not empty and is not a Viator checkout: $target\nChoose an empty directory or an existing Viator checkout."
die "Install directory is not empty and is not a OpsBox checkout: $target\nChoose an empty directory or an existing OpsBox checkout."
else
log "Cloning Viator into $target..."
git clone --depth 1 "$VIATOR_GIT_REPO" "$target"
log "Cloning OpsBox into $target..."
git clone --depth 1 "$OPSBOX_GIT_REPO" "$target"
fi
[[ -f "$target/install.sh" ]] || die "The repository checkout does not contain install.sh."
@@ -337,7 +337,7 @@ step_components() {
tag="${pair%%|*}"; label="${pair#*|}"
if grep -qx "$tag" "$STATE_FILE"; then choices+=("$tag" "$label" on); else choices+=("$tag" "$label" off); fi
done
selected="$(dlg --title "Viator - Components" --ok-label "Next" --cancel-label "Exit" --separate-output \
selected="$(dlg --title "OpsBox - Components" --ok-label "Next" --cancel-label "Exit" --separate-output \
--checklist "Select the components to install (Space = toggle).\nDocker Engine is always installed. Existing data and configuration are preserved." \
$((lh + 8)) 92 "$lh" "${choices[@]}" 3>&1 1>&2 2>&3)" || return 1
sel=(); SELECTED=()
@@ -532,7 +532,7 @@ Docker is always installed; images are pulled from $DOCKER_REGISTRY.
APT_UPGRADE="${APT_UPGRADE:-no}"
msg "$err"
done
VIATOR_DATA_ROOT="$DATA_ROOT"
OPSBOX_DATA_ROOT="$DATA_ROOT"
return 0
}
@@ -563,12 +563,12 @@ step_network() {
build_net_rows
local n=${#NET_ROWS[@]}
if ((n == 0)); then USE_CADDY=no; return 10; fi
local uc="${USE_CADDY:-yes}" dom="$VIATOR_DOMAIN"
local uc="${USE_CADDY:-yes}" dom="$OPSBOX_DOMAIN"
local -a net_sub=() net_port=() args=() vals=()
local i key label dsub dport bindv portv need sv lw=0 col y out err lines cols h fh w
for ((i = 0; i < n; i++)); do
IFS='|' read -r key label dsub dport bindv portv need <<<"${NET_ROWS[i]}"
sv="VIATOR_SUB_$key"
sv="OPSBOX_SUB_$key"
net_sub[i]="${!sv:-$dsub}"
net_port[i]="${!portv:-$dport}"
if ((${#label} > lw)); then lw=${#label}; fi
@@ -617,19 +617,19 @@ Columns: service | subdomain | host port" "$h" "$w" "$fh" "${args[@]}" 3>&1 1>&
[[ -z "$err" ]] && break
msg "$err"
done
USE_CADDY="$uc"; VIATOR_DOMAIN="$dom"
USE_CADDY="$uc"; OPSBOX_DOMAIN="$dom"
for ((i = 0; i < n; i++)); do
IFS='|' read -r key label dsub dport bindv portv need <<<"${NET_ROWS[i]}"
printf -v "VIATOR_SUB_$key" '%s' "${net_sub[i]}"
printf -v "OPSBOX_SUB_$key" '%s' "${net_sub[i]}"
printf -v "$portv" '%s' "$((10#${net_port[i]}))"
if [[ "$bindv" != "-" ]]; then
if [[ "$USE_CADDY" == yes ]]; then
printf -v "$bindv" '%s' "127.0.0.1"
printf -v "VIATOR_HOST_$key" '%s' ""
printf -v "OPSBOX_HOST_$key" '%s' ""
else
printf -v "$bindv" '%s' "0.0.0.0"
if [[ "$need" == yes ]]; then printf -v "VIATOR_HOST_$key" '%s' "${net_sub[i]}.$VIATOR_DOMAIN"
else printf -v "VIATOR_HOST_$key" '%s' ""; fi
if [[ "$need" == yes ]]; then printf -v "OPSBOX_HOST_$key" '%s' "${net_sub[i]}.$OPSBOX_DOMAIN"
else printf -v "OPSBOX_HOST_$key" '%s' ""; fi
fi
fi
done
@@ -639,13 +639,13 @@ Columns: service | subdomain | host port" "$h" "$w" "$fh" "${args[@]}" 3>&1 1>&
# ---- Step 5: per-service configuration screens ---------------------------------------
cfg_bettercap() {
local err
BETTERCAP_USER="${BETTERCAP_USER:-viator}"
BETTERCAP_USER="${BETTERCAP_USER:-opsbox}"
local -a specs=("BETTERCAP_USER|Web UI username|t" "BETTERCAP_PASSWORD|Web UI password (12+ chars)|p")
if [[ "$USE_CADDY" == yes ]]; then
BETTERCAP_UI_ADDR=""; BETTERCAP_ALLOW_ORIGIN=""
else
BETTERCAP_UI_ADDR="${BETTERCAP_UI_ADDR:-0.0.0.0}"
BETTERCAP_ALLOW_ORIGIN="${BETTERCAP_ALLOW_ORIGIN:-https://${VIATOR_SUB_BETTERCAP:-bettercap}.$VIATOR_DOMAIN}"
BETTERCAP_ALLOW_ORIGIN="${BETTERCAP_ALLOW_ORIGIN:-https://${OPSBOX_SUB_BETTERCAP:-bettercap}.$OPSBOX_DOMAIN}"
specs+=("BETTERCAP_UI_ADDR|Listen address (0.0.0.0 = all)|t" "BETTERCAP_ALLOW_ORIGIN|Public UI URL (CORS origin)|t")
fi
while true; do
@@ -828,13 +828,13 @@ step_summary() {
sum_add " Registry login: $DOCKER_USER @ $DOCKER_REGISTRY"
if ((${#NET_ROWS[@]})); then
sum_add ""
if [[ "$USE_CADDY" == yes ]]; then sum_add "NETWORK: Caddy with internal HTTPS, domain *.$VIATOR_DOMAIN"
if [[ "$USE_CADDY" == yes ]]; then sum_add "NETWORK: Caddy with internal HTTPS, domain *.$OPSBOX_DOMAIN"
else sum_add "NETWORK: your own reverse proxy (services published on host ports)"; fi
for ((i = 0; i < ${#NET_ROWS[@]}; i++)); do
IFS='|' read -r key label dsub dport bindv portv need <<<"${NET_ROWS[i]}"
sv="VIATOR_SUB_$key"
if [[ "$USE_CADDY" == yes ]]; then sum_add " $(printf '%-24s' "$label") https://${!sv}.$VIATOR_DOMAIN (127.0.0.1:${!portv})"
else sum_add " $(printf '%-24s' "$label") ${!sv}.$VIATOR_DOMAIN (host port ${!portv})"; fi
sv="OPSBOX_SUB_$key"
if [[ "$USE_CADDY" == yes ]]; then sum_add " $(printf '%-24s' "$label") https://${!sv}.$OPSBOX_DOMAIN (127.0.0.1:${!portv})"
else sum_add " $(printf '%-24s' "$label") ${!sv}.$OPSBOX_DOMAIN (host port ${!portv})"; fi
done
fi
if ((${#SEL_DL[@]})); then
@@ -887,13 +887,13 @@ wizard() {
persist_config() {
local i key label dsub dport bindv portv need
save_env VIATOR_DATA_ROOT VIATOR_ADMIN_USER VIATOR_DOMAIN USE_CADDY
DOCKER_REGISTRY_USER="$DOCKER_USER"; VIATOR_ADMIN_USER="$ADMIN_USER"
save_env VIATOR_ADMIN_USER DOCKER_REGISTRY_USER
save_env OPSBOX_DATA_ROOT OPSBOX_ADMIN_USER OPSBOX_DOMAIN USE_CADDY
DOCKER_REGISTRY_USER="$DOCKER_USER"; OPSBOX_ADMIN_USER="$ADMIN_USER"
save_env OPSBOX_ADMIN_USER DOCKER_REGISTRY_USER
for ((i = 0; i < ${#NET_ROWS[@]}; i++)); do
IFS='|' read -r key label dsub dport bindv portv need <<<"${NET_ROWS[i]}"
save_env "VIATOR_SUB_$key" "$portv"
if [[ "$bindv" != "-" ]]; then save_env "VIATOR_HOST_$key" "$bindv"; fi
save_env "OPSBOX_SUB_$key" "$portv"
if [[ "$bindv" != "-" ]]; then save_env "OPSBOX_HOST_$key" "$bindv"; fi
done
if contains pentest; then
save_env BETTERCAP_USER BETTERCAP_PASSWORD BETTERCAP_UI_ADDR BETTERCAP_UI_PORT BETTERCAP_API_PORT BETTERCAP_ALLOW_ORIGIN
@@ -917,108 +917,236 @@ persist_config() {
# ======================================================================================
install_tools() { apt_install btop jq tmux; }
install_theme() {
local motd="/etc/motd" marker_start="# >>> VIATOR BANNER >>>" marker_end="# <<< VIATOR BANNER <<<"
local motd="/etc/motd" marker_start="# >>> OPSBOX BANNER >>>" marker_end="# <<< OPSBOX BANNER <<<"
local tmp="$TMP_DIR/motd" name uid home shell
# Clean the old static banner out of /etc/motd if present
if [ -f "$motd" ]; then
awk -v s="$marker_start" -v e="$marker_end" 'BEGIN{skip=0} $0==s{skip=1;next} $0==e{skip=0;next} !skip{print}' "$motd" > "$tmp"
cp -a "$motd" "$motd.viator-backup.$(date +%s)"
cp -a "$motd" "$motd.opsbox-backup.$(date +%s)"
install -m 0644 "$tmp" "$motd"
fi
# World-readable location (the config dir is root-only, so users could not source it).
mkdir -p "$THEME_DIR"
rm -f /etc/motd /etc/update-motd.d/*
# ------------------------------------------------------------------
# Disable sshd's own "Last login:" line (our banner shows it instead)
# ------------------------------------------------------------------
if [ -d /etc/ssh ]; then
mkdir -p /etc/ssh/sshd_config.d
echo 'PrintLastLog no' > /etc/ssh/sshd_config.d/00-opsbox.conf
if sshd -t 2>/dev/null; then
systemctl reload ssh 2>/dev/null || systemctl reload sshd 2>/dev/null || true
else
rm -f /etc/ssh/sshd_config.d/00-opsbox.conf
log "sshd config test failed; left PrintLastLog unchanged."
fi
fi
cat > /usr/local/sbin/opsbox-updates <<'UPD'
#!/bin/sh
out=/var/cache/opsbox/updates
mkdir -p "${out%/*}"
n=0; s=0
if command -v apt-get >/dev/null 2>&1; then
list=$(apt-get -s -o Debug::NoLocking=1 upgrade 2>/dev/null | grep '^Inst ')
n=$(printf '%s\n' "$list" | grep -c .)
s=$(printf '%s\n' "$list" | grep -ci security)
elif command -v dnf >/dev/null 2>&1; then
n=$(dnf -q check-update 2>/dev/null | awk 'NF==3' | wc -l)
s=$(dnf -q updateinfo list security 2>/dev/null | awk 'NF==3' | wc -l)
fi
echo "$n $s" > "$out.tmp" && mv "$out.tmp" "$out" && chmod 0644 "$out"
UPD
chmod 0755 /usr/local/sbin/opsbox-updates
if command -v apt-get >/dev/null 2>&1; then
cat > /etc/apt/apt.conf.d/99opsbox-updates <<'APTHOOK'
APT::Update::Post-Invoke-Success { "/usr/local/sbin/opsbox-updates >/dev/null 2>&1 || true"; };
DPkg::Post-Invoke { "/usr/local/sbin/opsbox-updates >/dev/null 2>&1 || true"; };
APTHOOK
fi
/usr/local/sbin/opsbox-updates || true
cat > "$THEME_DIR/theme.sh" <<'THEME'
# Viator login banner + prompt. Sourced from ~/.bashrc and /etc/profile.d/viator.sh.
# OpsBox login banner + prompt.
[ -n "${BASH_VERSION:-}" ] || return 0
case $- in *i*) ;; *) return 0 ;; esac
__viator_rep() {
__opsbox_rep() {
local n=$1 c=$2 s
[ "$n" -gt 0 ] || return 0
printf -v s '%*s' "$n" ''
printf '%s' "${s// /$c}"
}
__viator_ifaces() {
__opsbox_row() {
printf '| %-*s |\n' "$((W - 4))" "$(printf '%s' "$1" | cut -c1-$((W - 4)))"
}
__opsbox_ifaces() {
local p n
for p in /sys/class/net/*; do
n=${p##*/}
case $n in
lo|docker*|br-*|veth*|virbr*|bond*|dummy*|ifb*|sit*|tunl*|ip6tnl*|gre*|erspan*) continue ;;
esac
if [ -e "$p/device" ] || [ -d "$p/wireless" ]; then printf '%s\n' "$n"
else case $n in wg*|tun*|tailscale*) printf '%s\n' "$n" ;; esac
# WireGuard is reported in the VPN row instead.
if grep -qx 'DEVTYPE=wireguard' "$p/uevent" 2>/dev/null; then continue; fi
if [ -e "$p/device" ] || [ -d "$p/wireless" ]; then
printf '%s\n' "$n"
else
case $n in tun*|tailscale*) printf '%s\n' "$n" ;; esac
fi
done
}
__viator_banner() {
local W=64 user now src prev lastf ifc ip status row
__opsbox_vpn() {
local p n ip ts age hs now
now=$(date +%s)
for p in /sys/class/net/*; do
n=${p##*/}
grep -qx 'DEVTYPE=wireguard' "$p/uevent" 2>/dev/null || continue
ip=$(ip -4 -o addr show dev "$n" 2>/dev/null | awk '{print $4}' | cut -d/ -f1 | head -n1)
[ -n "$ip" ] && ip="// $ip"
if hs=$(wg show "$n" latest-handshakes 2>/dev/null); then
ts=$(printf '%s\n' "$hs" | awk '$2>m{m=$2} END{print m+0}')
if [ "$ts" -eq 0 ]; then
printf '%-10s %-14s %s\n' "$n" "NO HANDSHAKE" "$ip"
else
age=$((now - ts))
if [ "$age" -le 180 ]; then
printf '%-10s %-14s %s (hs %ss)\n' "$n" "CONNECTED" "$ip" "$age"
else
printf '%-10s %-14s %s (hs %sm)\n' "$n" "STALE" "$ip" "$((age / 60))"
fi
fi
else
printf '%-10s %-14s %s\n' "$n" "UP" "$ip"
fi
done
}
__opsbox_banner() {
local W=68 user host now src prev lastf ifc ip status row
local any=0 os kern upd n s reboot line
user=$(id -un 2>/dev/null || echo "${USER:-unknown}")
host=$(hostname -s 2>/dev/null || hostname)
host="${host:0:32}"
now=$(date '+%a %d %b %H:%M')
if [ -n "${SSH_CONNECTION:-}" ]; then
src="ssh ${SSH_CONNECTION%% *}"
else
src=$(tty 2>/dev/null || true)
case $src in ""|"not a tty") src="local" ;; *) src=${src#/dev/} ;; esac
case $src in
""|"not a tty") src="local" ;;
*) src=${src#/dev/} ;;
esac
fi
# Own bookkeeping: works whether or not wtmp/lastlog exist on this distro.
lastf="${HOME:-/tmp}/.viator_last_login"
lastf="${HOME:-/tmp}/.opsbox_last_login"
prev="first session"
[ -r "$lastf" ] && prev=$(head -n1 "$lastf" 2>/dev/null)
printf '%s (%s)\n' "$now" "$src" > "$lastf" 2>/dev/null || true
os=$(. /etc/os-release 2>/dev/null && printf '%s' "${PRETTY_NAME:-$NAME}")
[ -n "$os" ] || os=$(uname -s)
kern=$(uname -r)
upd="UNKNOWN"
if [ -r /var/cache/opsbox/updates ]; then
read -r n s < /var/cache/opsbox/updates
if [ "${n:-0}" -eq 0 ]; then
upd="up to date"
elif [ "${s:-0}" -gt 0 ]; then
upd="$n pending ($s security)"
else
upd="$n pending"
fi
fi
[ -e /run/reboot-required ] && upd="$upd // REBOOT REQUIRED"
printf '.-[ VIATOR ]%s.\n' "$(__viator_rep $((W - 13)) -)"
printf '| %-*s |\n' $((W - 4)) "$(printf 'ACCESS: %s // LAST: %s' "${user^^}" "$prev" | cut -c1-$((W - 4)))"
printf '| %-*s |\n' $((W - 4)) ""
local any=0
for ifc in $(__viator_ifaces); do
# Header.
printf '+==[ %s ]' "$host"
printf '%s+\n' "$(__opsbox_rep "$((W - ${#host} - 8))" '=')"
__opsbox_row "$(printf 'ACCESS: %s // LAST: %s' "${user^^}" "$prev")"
__opsbox_row "$(printf 'OS: %s // %s' "$os" "$kern")"
__opsbox_row "$(printf 'UPDATES: %s' "$upd")"
printf '|%s|\n' "$(__opsbox_rep "$((W - 2))" '-')"
# Network interfaces.
for ifc in $(__opsbox_ifaces); do
any=1
ip=$(ip -4 -o addr show dev "$ifc" scope global 2>/dev/null | awk '{print $4}' | cut -d/ -f1 | head -n1)
if [ -n "$ip" ]; then status="CONNECTED"; else status="DISCONNECTED"; ip=""; fi
ip=$(ip -4 -o addr show dev "$ifc" scope global 2>/dev/null |
awk '{print $4}' | cut -d/ -f1 | head -n1)
if [ -n "$ip" ]; then
status="CONNECTED"
ip="// $ip"
else
status="DISCONNECTED"
ip=""
fi
row=$(printf '%-10s %-14s %s' "$ifc" "$status" "$ip")
printf '| %-*s |\n' $((W - 4)) "$(printf '%s' "$row" | cut -c1-$((W - 4)))"
__opsbox_row "$row"
done
[ "$any" = 1 ] || printf '| %-*s |\n' $((W - 4)) "no network adapters found"
printf '`%s[░▒▓█]------'"'"'\n' "$(__viator_rep $((W - 14)) -)"
# VPN interfaces (WireGuard), same column layout.
while IFS= read -r line; do
[ -n "$line" ] || continue
any=1
__opsbox_row "$line"
done < <(__opsbox_vpn)
[ "$any" = 1 ] || __opsbox_row "NO NETWORK ADAPTERS FOUND"
# Footer.
printf '+%s+\n' "$(__opsbox_rep "$((W - 2))" '=')"
}
__viator_prompt() {
__opsbox_prompt() {
local c='\[\e[36m\]' u='\[\e[33m\]' d='\[\e[97m\]' r='\[\e[m\]'
if [ "$(id -u)" -eq 0 ]; then c='\[\e[91m\]'; fi
PS1="${c}╭──(${u}\u${c}@${u}\h${c})-[${d}\w${c}]${r}\n${c}╰─${r}\\$ "
}
if [ -z "${VIATOR_BANNER_SHOWN:-}" ]; then
export VIATOR_BANNER_SHOWN=1
__viator_banner
if [ -z "${OPSBOX_BANNER_SHOWN:-}" ]; then
export OPSBOX_BANNER_SHOWN=1
__opsbox_banner
fi
__viator_prompt
unset -f __viator_banner __viator_prompt __viator_ifaces __viator_rep
__opsbox_prompt
unset -f __opsbox_banner __opsbox_prompt __opsbox_ifaces __opsbox_rep __opsbox_row __opsbox_vpn
THEME
chmod 0755 "$THEME_DIR"
chmod 0644 "$THEME_DIR/theme.sh"
# Login shells (ssh, console): banner + prompt.
cat > /etc/profile.d/viator.sh <<'PROFILE'
# Viator theme for login shells (the prompt is also applied from ~/.bashrc).
if [ -r /usr/local/share/viator/theme.sh ]; then . /usr/local/share/viator/theme.sh; fi
# Login shells.
cat > /etc/profile.d/opsbox.sh <<'PROFILE'
if [ -r /usr/local/share/opsbox/theme.sh ]; then . /usr/local/share/opsbox/theme.sh; fi
PROFILE
chmod 0644 /etc/profile.d/viator.sh
chmod 0644 /etc/profile.d/opsbox.sh
# ~/.bashrc normally redefines PS1 AFTER /etc/profile.d, which is why a profile.d-only
# theme never showed up for existing users or root. Hook the end of every bashrc.
# Hook bashrc files.
while IFS=: read -r name _ uid _ _ home shell; do
if [[ "$name" == root || "$name" == "$ADMIN_USER" ]] || ((uid >= 1000 && uid < 60000)); then
[[ "$shell" == *nologin || "$shell" == */false ]] && continue
[[ -d "$home" ]] && hook_bashrc "$home/.bashrc"
fi
done < <(getent passwd)
hook_bashrc /root/.bashrc
hook_bashrc /etc/skel/.bashrc
log "Theme installed. Open a new shell (or run: source ~/.bashrc) to see it."
}
@@ -1027,12 +1155,12 @@ hook_bashrc() {
[[ -d "$(dirname "$rc")" ]] || return 0
[[ -e "$rc" ]] || new=yes
touch "$rc"
sed -i '\|# >>> viator theme >>>|,\|# <<< viator theme <<<|d' "$rc"
sed -i '\|# >>> opsbox theme >>>|,\|# <<< opsbox theme <<<|d' "$rc"
cat >> "$rc" <<'HOOK'
# >>> viator theme >>>
if [ -r /usr/local/share/viator/theme.sh ]; then . /usr/local/share/viator/theme.sh; fi
# <<< viator theme <<<
# >>> opsbox theme >>>
if [ -r /usr/local/share/opsbox/theme.sh ]; then . /usr/local/share/opsbox/theme.sh; fi
# <<< opsbox theme <<<
HOOK
if [[ "$new" == yes ]]; then chown --reference="$(dirname "$rc")" "$rc" || true; fi
return 0
@@ -1145,7 +1273,7 @@ os.chmod(tmp, 0o644); os.replace(tmp, path)
PY
systemctl enable --now docker || return 1
systemctl restart docker || return 1
docker network inspect viator_proxy >/dev/null 2>&1 || docker network create viator_proxy >/dev/null
docker network inspect opsbox_proxy >/dev/null 2>&1 || docker network create opsbox_proxy >/dev/null
usermod -aG docker "$ADMIN_USER"
}
@@ -1173,9 +1301,9 @@ docker_login() {
install_caddy() {
mkdir -p "$DATA_ROOT/caddy/data" "$DATA_ROOT/caddy/config"
docker network inspect viator_proxy >/dev/null 2>&1 || docker network create viator_proxy >/dev/null
local compose="$VIATOR_DIR/docker/caddy.yml"
VIATOR_DATA_ROOT="$DATA_ROOT" docker compose --env-file "$ENV_FILE" -f "$compose" up -d
docker network inspect opsbox_proxy >/dev/null 2>&1 || docker network create opsbox_proxy >/dev/null
local compose="$OPSBOX_DIR/docker/caddy.yml"
OPSBOX_DATA_ROOT="$DATA_ROOT" docker compose --env-file "$ENV_FILE" -f "$compose" up -d
}
install_docker_stack() {
@@ -1188,7 +1316,7 @@ install_docker_stack() {
export_caddy_ca() {
[[ "$USE_CADDY" == yes ]] || return 0
for _ in {1..20}; do
docker cp viator-caddy:/data/caddy/pki/authorities/local/root.crt "$CONFIG_DIR/caddy-root.crt" 2>/dev/null && break
docker cp opsbox-caddy:/data/caddy/pki/authorities/local/root.crt "$CONFIG_DIR/caddy-root.crt" 2>/dev/null && break
sleep 2
done
if [[ -f "$CONFIG_DIR/caddy-root.crt" ]]; then
@@ -1201,11 +1329,11 @@ compose_stack() {
local name="$1" file="$2" envfile=""
shift 2
if (($#)) && [[ "$1" != --profile* ]]; then envfile="$1"; shift; fi
local target="$VIATOR_DIR/$file"
local target="$OPSBOX_DIR/$file"
local -a args=(docker compose -f "$target")
mkdir -p "$DATA_ROOT/$name"
[[ -n "$envfile" ]] && args+=(--env-file "$envfile")
VIATOR_DATA_ROOT="$DATA_ROOT" "${args[@]}" "$@" up -d
OPSBOX_DATA_ROOT="$DATA_ROOT" "${args[@]}" "$@" up -d
}
# ---- container services ---------------------------------------------------------------
@@ -1217,8 +1345,8 @@ install_opentak() {
mkdir -p "$dir"
# Retire the old GoATAK stack if present (its data in $DATA_ROOT/atak is left untouched).
if [[ -f "$VIATOR_DIR/docker/atak.yml" ]]; then
VIATOR_DATA_ROOT="$DATA_ROOT" docker compose --env-file "$ENV_FILE" -f "$VIATOR_DIR/docker/atak.yml" down --remove-orphans 2>/dev/null || true
if [[ -f "$OPSBOX_DIR/docker/atak.yml" ]]; then
OPSBOX_DATA_ROOT="$DATA_ROOT" docker compose --env-file "$ENV_FILE" -f "$OPSBOX_DIR/docker/atak.yml" down --remove-orphans 2>/dev/null || true
fi
# Upstream installer: fetch compose + generate .env under ./data/opentak; don't start yet.
@@ -1231,8 +1359,8 @@ install_opentak() {
env_put "$dir/.env" OTS_WEB_BIND "$OTS_WEB_BIND"
env_put "$dir/.env" OTS_WEB_PORT "$OTS_WEB_PORT"
env_put "$dir/.env" VIATOR_DOMAIN "$VIATOR_DOMAIN"
env_put "$dir/.env" VIATOR_SUB_OPENTAK "${VIATOR_SUB_OPENTAK:-tak}"
env_put "$dir/.env" OPSBOX_DOMAIN "$OPSBOX_DOMAIN"
env_put "$dir/.env" OPSBOX_SUB_OPENTAK "${OPSBOX_SUB_OPENTAK:-tak}"
# Auto-merged by compose; upstream's docker-compose.yml stays untouched/upgradable.
# 8089 (SSL CoT) and 8446 (cert enrollment) are raw TLS, so they're always published
@@ -1248,14 +1376,14 @@ services:
- default
- proxy
labels:
caddy: \${VIATOR_SUB_OPENTAK:-tak}.\${VIATOR_DOMAIN:-viator.internal}
caddy: \${OPSBOX_SUB_OPENTAK:-tak}.\${OPSBOX_DOMAIN:-opsbox.internal}
caddy.reverse_proxy: "{{upstreams 8080}}"
caddy.tls: internal
networks:
proxy:
external: true
name: viator_proxy
name: opsbox_proxy
OVERRIDE
(cd "$dir" && docker compose config -q) || { err "Compose validation failed in $dir"; return 1; }
@@ -1293,12 +1421,12 @@ install_maps() {
done
mkdir -p "$DATA_ROOT/maps/tileserver"
if [[ ! -f "$DATA_ROOT/maps/tileserver/config.json" ]]; then
install -m 0644 "$VIATOR_DIR/data/maps/tileserver/config.json" \
install -m 0644 "$OPSBOX_DIR/data/maps/tileserver/config.json" \
"$DATA_ROOT/maps/tileserver/config.json"
fi
if [[ "$DATA_ROOT" != "$VIATOR_DIR/data" ]]; then
if [[ "$DATA_ROOT" != "$OPSBOX_DIR/data" ]]; then
mkdir -p "$DATA_ROOT/maps/tileserver/styles"
cp -an "$VIATOR_DIR/data/maps/tileserver/styles/." \
cp -an "$OPSBOX_DIR/data/maps/tileserver/styles/." \
"$DATA_ROOT/maps/tileserver/styles/"
fi
local -a profiles=()
@@ -1312,9 +1440,9 @@ install_personal_cloud() { compose_stack personal-cloud docker/cloud.yml "$ENV_F
install_pentest() {
apt_install arp-scan aircrack-ng gobuster hashcat hcxtools hydra john netcat-openbsd nikto \
nmap masscan reaver sqlmap tcpdump wireshark || return 1
VIATOR_DOCKER_GATEWAY="$(docker network inspect bridge --format '{{(index .IPAM.Config 0).Gateway}}' 2>/dev/null || true)"
VIATOR_DOCKER_GATEWAY="${VIATOR_DOCKER_GATEWAY:-172.17.0.1}"
save_env VIATOR_DOCKER_GATEWAY
OPSBOX_DOCKER_GATEWAY="$(docker network inspect bridge --format '{{(index .IPAM.Config 0).Gateway}}' 2>/dev/null || true)"
OPSBOX_DOCKER_GATEWAY="${OPSBOX_DOCKER_GATEWAY:-172.17.0.1}"
save_env OPSBOX_DOCKER_GATEWAY
curl -fsSL https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfinstall.erb -o "$TMP_DIR/msfinstall" || return 1
chmod 0700 "$TMP_DIR/msfinstall"
"$TMP_DIR/msfinstall" || return 1
@@ -1325,8 +1453,8 @@ install_pentest() {
# and sanity-check that the HAT's SDR is visible on USB.
prepare_rtlsdr_host() {
apt_install rtl-sdr usbutils || return 1
cat > /etc/modprobe.d/viator-rtlsdr.conf <<'BLACKLIST'
# Managed by Viator: keep the kernel DVB driver off RTL-SDR dongles so SDR apps can claim them.
cat > /etc/modprobe.d/opsbox-rtlsdr.conf <<'BLACKLIST'
# Managed by opsbox: keep the kernel DVB driver off RTL-SDR dongles so SDR apps can claim them.
blacklist dvb_usb_rtl28xxu
blacklist rtl2832
blacklist rtl2832_sdr
@@ -1361,7 +1489,7 @@ install_sdr_decoders() {
install_ai() {
apt_install curl ca-certificates || return 1
local dir="$AI_DIR" repo="$AI_REPO" user=viator-ai
local dir="$AI_DIR" repo="$AI_REPO" user=opsbox-ai
id "$user" >/dev/null 2>&1 || useradd --system --home "$dir" --create-home --shell /usr/sbin/nologin "$user"
mkdir -p "$dir"
chown -R "$user:$user" "$dir"
@@ -1463,7 +1591,7 @@ main() {
if ((${#FAILED[@]})); then for x in "${FAILED[@]}"; do report+=" * $x"$'\n'; done; else report+=$' (none)\n'; fi
report+=$'\nReboot is recommended if hardware overlays or kernel modules changed.'
msg "$report"
printf '%s\n' "Succeeded: ${SUCCEEDED[*]:-(none)}" "Failed: ${FAILED[*]:-(none)}" | tee "/var/log/viator/install-$(date +%F-%H%M%S).log"
printf '%s\n' "Succeeded: ${SUCCEEDED[*]:-(none)}" "Failed: ${FAILED[*]:-(none)}" | tee "/var/log/opsbox/install-$(date +%F-%H%M%S).log"
}
main "$@"