Compare commits
19 Commits
31a0cb1a9f
...
master
Author | SHA1 | Date | |
---|---|---|---|
a40db2645b | |||
![]() |
c2b7521bec | ||
![]() |
a4c9c1f25b | ||
7e033e1c09 | |||
![]() |
394313b3c1 | ||
0eface0b96 | |||
303d4275fe | |||
42eae624ad | |||
![]() |
3c89d6e800 | ||
aa1d9bbed0 | |||
6333e842cd | |||
21204251c9 | |||
6d79ff93cb | |||
db83cbbffc | |||
5d633dbdbb | |||
9ed55d2171 | |||
cc860cb554 | |||
ef42a7089f | |||
e46aba65be |
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -1,2 +0,0 @@
|
|||||||
cln filter=lfs diff=lfs merge=lfs -text
|
|
||||||
cln.exe filter=lfs diff=lfs merge=lfs -text
|
|
211
configuration.nix
Normal file
211
configuration.nix
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
# Edit this configuration file to define what should be installed on
|
||||||
|
# your system. Help is available in the configuration.nix(5) man page
|
||||||
|
# and in the NixOS manual (accessible by running 'nixos-help').
|
||||||
|
|
||||||
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
# Include the results of the hardware scan.
|
||||||
|
/etc/nixos/hardware-configuration.nix
|
||||||
|
];
|
||||||
|
|
||||||
|
# Bootloader.
|
||||||
|
boot.loader.grub.enable = true;
|
||||||
|
boot.loader.grub.device = "/dev/sda";
|
||||||
|
boot.loader.grub.useOSProber = true;
|
||||||
|
|
||||||
|
networking.hostName = "nixos"; # Define your hostname.
|
||||||
|
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
|
||||||
|
|
||||||
|
# Configure network proxy if necessary
|
||||||
|
# networking.proxy.default = "http://user:password@proxy:port/";
|
||||||
|
# networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
|
||||||
|
|
||||||
|
# Enable networking
|
||||||
|
networking.networkmanager.enable = true;
|
||||||
|
networking.nameservers = [
|
||||||
|
"1.1.1.1"
|
||||||
|
"8.8.8.8"
|
||||||
|
];
|
||||||
|
|
||||||
|
# Set your time zone.
|
||||||
|
time.timeZone = "Europe/Zagreb";
|
||||||
|
|
||||||
|
# Select internationalisation properties.
|
||||||
|
i18n.defaultLocale = "en_GB.UTF-8";
|
||||||
|
|
||||||
|
i18n.extraLocaleSettings = {
|
||||||
|
LC_ADDRESS = "hr_HR.UTF-8";
|
||||||
|
LC_IDENTIFICATION = "hr_HR.UTF-8";
|
||||||
|
LC_MEASUREMENT = "hr_HR.UTF-8";
|
||||||
|
LC_MONETARY = "hr_HR.UTF-8";
|
||||||
|
LC_NAME = "hr_HR.UTF-8";
|
||||||
|
LC_NUMERIC = "hr_HR.UTF-8";
|
||||||
|
LC_PAPER = "hr_HR.UTF-8";
|
||||||
|
LC_TELEPHONE = "hr_HR.UTF-8";
|
||||||
|
LC_TIME = "hr_HR.UTF-8";
|
||||||
|
};
|
||||||
|
|
||||||
|
# Enable the X11 windowing system.
|
||||||
|
# You can disable this if you're only using the Wayland session.
|
||||||
|
services.xserver.enable = true;
|
||||||
|
|
||||||
|
# Enable the KDE Plasma Desktop Environment.
|
||||||
|
services.displayManager.sddm.enable = true;
|
||||||
|
services.desktopManager.plasma6.enable = true;
|
||||||
|
|
||||||
|
# Configure keymap in X11
|
||||||
|
services.xserver.xkb = {
|
||||||
|
layout = "hr";
|
||||||
|
variant = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
# Configure console keymap
|
||||||
|
console.keyMap = "croat";
|
||||||
|
|
||||||
|
# Enable CUPS to print documents.
|
||||||
|
services.printing.enable = false;
|
||||||
|
|
||||||
|
# Enable sound with pipewire.
|
||||||
|
services.pulseaudio.enable = false;
|
||||||
|
security.rtkit.enable = true;
|
||||||
|
services.pipewire = {
|
||||||
|
enable = true;
|
||||||
|
alsa.enable = true;
|
||||||
|
alsa.support32Bit = true;
|
||||||
|
pulse.enable = true;
|
||||||
|
# If you want to use JACK applications, uncomment this
|
||||||
|
#jack.enable = true;
|
||||||
|
|
||||||
|
# use the example session manager (no others are packaged yet so this is enabled by default,
|
||||||
|
# no need to redefine it in your config for now)
|
||||||
|
#media-session.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
services.samba = {
|
||||||
|
enable = true;
|
||||||
|
securityType = "user";
|
||||||
|
openFirewall = true;
|
||||||
|
settings = {
|
||||||
|
global = {
|
||||||
|
"workgroup" = "SAMBA";
|
||||||
|
"security" = "user";
|
||||||
|
"passdb backend" = "tdbsam";
|
||||||
|
"vfs objects" = "acl_xattr";
|
||||||
|
"map acl inherit" = "yes";
|
||||||
|
"store dos attributes" = "yes";
|
||||||
|
};
|
||||||
|
"data" = {
|
||||||
|
"path" = "/mnt/data";
|
||||||
|
"read only" = "no";
|
||||||
|
"browsable" = "yes";
|
||||||
|
"guest ok" = "no";
|
||||||
|
"writable" = "yes";
|
||||||
|
"valid users" = "dave,jana";
|
||||||
|
};
|
||||||
|
"dave" = {
|
||||||
|
"path" = "/home/dave";
|
||||||
|
"read only" = "no";
|
||||||
|
"browsable" = "yes";
|
||||||
|
"guest ok" = "no";
|
||||||
|
"writable" = "yes";
|
||||||
|
"valid users" = "dave,jana";
|
||||||
|
};
|
||||||
|
"homework" = {
|
||||||
|
"path" = "/mnt/data/docker/volumes/captain--sync-data/_data/Homework";
|
||||||
|
"read only" = "no";
|
||||||
|
"browsable" = "yes";
|
||||||
|
"guest ok" = "no";
|
||||||
|
"writable" = "yes";
|
||||||
|
"valid users" = "dave";
|
||||||
|
};
|
||||||
|
"torrent" = {
|
||||||
|
"path" = "/home/dave/volumes/captain--torrent-downloads/_data";
|
||||||
|
"read only" = "no";
|
||||||
|
"browsable" = "yes";
|
||||||
|
"guest ok" = "no";
|
||||||
|
"writable" = "yes";
|
||||||
|
"valid users" = "dave";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
services.samba-wsdd = {
|
||||||
|
enable = true;
|
||||||
|
openFirewall = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Enable touchpad support (enabled default in most desktopManager).
|
||||||
|
# services.xserver.libinput.enable = true;
|
||||||
|
|
||||||
|
# Define a user account. Don't forget to set a password with 'passwd'.
|
||||||
|
users.users.dave = {
|
||||||
|
isNormalUser = true;
|
||||||
|
description = "Dave";
|
||||||
|
extraGroups = [
|
||||||
|
"networkmanager"
|
||||||
|
"wheel"
|
||||||
|
];
|
||||||
|
packages = with pkgs; [
|
||||||
|
kdePackages.kate
|
||||||
|
# thunderbird
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
services.openssh = {
|
||||||
|
enable = true;
|
||||||
|
ports = [ 22 ];
|
||||||
|
settings = {
|
||||||
|
PasswordAuthentication = true;
|
||||||
|
AllowUsers = [ "dave" ];
|
||||||
|
UseDns = true;
|
||||||
|
X11Forwarding = false;
|
||||||
|
PermitRootLogin = "no";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
services.resolved.enable = true;
|
||||||
|
|
||||||
|
# Install firefox.
|
||||||
|
programs.firefox.enable = true;
|
||||||
|
|
||||||
|
# Allow unfree packages
|
||||||
|
nixpkgs.config.allowUnfree = true;
|
||||||
|
|
||||||
|
# List packages installed in system profile. To search, run:
|
||||||
|
# $ nix search wget
|
||||||
|
environment.systemPackages = with pkgs; [
|
||||||
|
vim
|
||||||
|
git
|
||||||
|
lazygit
|
||||||
|
tmux
|
||||||
|
nixfmt-rfc-style
|
||||||
|
btop
|
||||||
|
];
|
||||||
|
|
||||||
|
# Some programs need SUID wrappers, can be configured further or are
|
||||||
|
# started in user sessions.
|
||||||
|
# programs.mtr.enable = true;
|
||||||
|
# programs.gnupg.agent = {
|
||||||
|
# enable = true;
|
||||||
|
# enableSSHSupport = true;
|
||||||
|
# };
|
||||||
|
|
||||||
|
# List services that you want to enable:
|
||||||
|
|
||||||
|
# Open ports in the firewall.
|
||||||
|
# networking.firewall.allowedTCPPorts = [ ... ];
|
||||||
|
# networking.firewall.allowedUDPPorts = [ ... ];
|
||||||
|
# Or disable the firewall altogether.
|
||||||
|
# networking.firewall.enable = false;
|
||||||
|
networking.firewall.enable = true;
|
||||||
|
networking.firewall.allowPing = true;
|
||||||
|
|
||||||
|
# This value determines the NixOS release from which the default
|
||||||
|
# settings for stateful data, like file locations and database versions
|
||||||
|
# on your system were taken. It's perfectly fine and recommended to leave
|
||||||
|
# this value at the release version of the first install of this system.
|
||||||
|
# Before changing this value read the documentation for this option
|
||||||
|
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
|
||||||
|
system.stateVersion = "25.05"; # Did you read the comment?
|
||||||
|
}
|
56
prometheus.yml
Normal file
56
prometheus.yml
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
# 793fc68064b5a5917eccf004ee6f30395a0464e7# my global config
|
||||||
|
global:
|
||||||
|
scrape_interval: 5s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
|
||||||
|
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
|
||||||
|
# scrape_timeout is set to the global default (10s).
|
||||||
|
|
||||||
|
# Alertmanager configuration
|
||||||
|
alerting:
|
||||||
|
alertmanagers:
|
||||||
|
- static_configs:
|
||||||
|
- targets:
|
||||||
|
# - alertmanager:9093
|
||||||
|
|
||||||
|
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
|
||||||
|
rule_files:
|
||||||
|
# - "first_rules.yml"
|
||||||
|
# - "second_rules.yml"
|
||||||
|
|
||||||
|
# A scrape configuration containing exactly one endpoint to scrape:
|
||||||
|
# Here it's Prometheus itself.
|
||||||
|
scrape_configs:
|
||||||
|
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
|
||||||
|
- job_name: "prometheus"
|
||||||
|
static_configs:
|
||||||
|
- targets: ["localhost:43261"]
|
||||||
|
|
||||||
|
- job_name: 'node_exporter'
|
||||||
|
static_configs:
|
||||||
|
- targets: ['localhost:56546']
|
||||||
|
|
||||||
|
- job_name: 'node_exporter_lilbox'
|
||||||
|
static_configs:
|
||||||
|
- targets: ['192.168.1.78:56546']
|
||||||
|
|
||||||
|
- job_name: 'power-meter-reader'
|
||||||
|
scrape_interval: 30s
|
||||||
|
static_configs:
|
||||||
|
- targets: ['localhost:20132']
|
||||||
|
|
||||||
|
# - job_name: 'windows-exporter'
|
||||||
|
# scrape_interval: 10s
|
||||||
|
# static_configs:
|
||||||
|
# - targets: ['192.168.1.64:9182']
|
||||||
|
#
|
||||||
|
- job_name: 'libre-metrics-exporter-dave'
|
||||||
|
scrape_interval: 10s
|
||||||
|
static_configs:
|
||||||
|
- targets: ['192.168.1.64:9646']
|
||||||
|
|
||||||
|
# - job_name: 'libre-metrics-exporter-jana'
|
||||||
|
# scrape_interval: 10s
|
||||||
|
# static_configs:
|
||||||
|
# - targets: ['192.168.1.64:9646']
|
||||||
|
|
||||||
|
remote_write:
|
||||||
|
- url: "http://127.0.0.1:8428/api/v1/write"
|
66
smb.conf
Normal file
66
smb.conf
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
# See smb.conf.example for a more detailed config file or
|
||||||
|
# read the smb.conf manpage.
|
||||||
|
# Run 'testparm' to verify the config is correct after
|
||||||
|
# you modified it.
|
||||||
|
#
|
||||||
|
# Note:
|
||||||
|
# SMB1 is disabled by default. This means clients without support for SMB2 or
|
||||||
|
# SMB3 are no longer able to connect to smbd (by default).
|
||||||
|
|
||||||
|
[global]
|
||||||
|
workgroup = SAMBA
|
||||||
|
security = user
|
||||||
|
|
||||||
|
passdb backend = tdbsam
|
||||||
|
|
||||||
|
printing = cups
|
||||||
|
printcap name = cups
|
||||||
|
load printers = yes
|
||||||
|
cups options = raw
|
||||||
|
|
||||||
|
vfs objects = acl_xattr
|
||||||
|
map acl inherit = yes
|
||||||
|
store dos attributes = yes
|
||||||
|
|
||||||
|
# Install samba-usershares package for support
|
||||||
|
include = /etc/samba/usershares.conf
|
||||||
|
|
||||||
|
[data]
|
||||||
|
path = /mnt/data
|
||||||
|
read only = no
|
||||||
|
browsable = yes
|
||||||
|
guest ok = no
|
||||||
|
writable = yes
|
||||||
|
valid users = dave,jana
|
||||||
|
|
||||||
|
[dave]
|
||||||
|
path = /home/dave
|
||||||
|
read only = no
|
||||||
|
browsable = yes
|
||||||
|
guest ok = no
|
||||||
|
writable = yes
|
||||||
|
valid users = dave,jana
|
||||||
|
|
||||||
|
[localbin]
|
||||||
|
path = /usr/local/bin
|
||||||
|
read only = no
|
||||||
|
browsable = yes
|
||||||
|
guest ok = no
|
||||||
|
writable = yes
|
||||||
|
valid users = dave
|
||||||
|
|
||||||
|
[homework]
|
||||||
|
path = /mnt/data/docker/volumes/captain--sync-data/_data/Homework
|
||||||
|
read only = no
|
||||||
|
browsable = yes
|
||||||
|
guest ok = no
|
||||||
|
writable = yes
|
||||||
|
valid users = dave
|
||||||
|
|
||||||
|
[torrent]
|
||||||
|
path = /home/dave/volumes/captain--torrent-downloads/_data
|
||||||
|
read only = no
|
||||||
|
browsable = yes
|
||||||
|
guest ok = no
|
||||||
|
writable = yes
|
||||||
|
valid users = dave
|
@@ -10,3 +10,11 @@
|
|||||||
- source: .tmux.conf
|
- source: .tmux.conf
|
||||||
target: /home/dave/~/.tmux.conf
|
target: /home/dave/~/.tmux.conf
|
||||||
delete: true
|
delete: true
|
||||||
|
- source: configuration.nix
|
||||||
|
target: /etc/nixos/configuration.nix
|
||||||
|
delete: true
|
||||||
|
- source: prometheus.yml
|
||||||
|
target: /mnt/data/persistent/monitoring/prometheus/config/prometheus.yml
|
||||||
|
- source: smb.conf
|
||||||
|
target: /etc/samba/smb.conf
|
||||||
|
delete: true
|
||||||
|
@@ -1,22 +1,28 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# tmux-daemonizer.sh
|
# tmux-daemon.sh
|
||||||
# Idempotent tmux daemon manager with optional per-command workdir
|
# Idempotent tmux daemon manager with config file support
|
||||||
|
|
||||||
|
# Load config file if it exists
|
||||||
|
SCRIPT_DIR=$(dirname "$0")
|
||||||
|
SCRIPT_NAME=$(basename "$0" .sh)
|
||||||
|
CONFIG_FILE="${SCRIPT_DIR}/${SCRIPT_NAME}.conf"
|
||||||
|
if [ -f "$CONFIG_FILE" ]; then
|
||||||
|
echo "Loading config from $CONFIG_FILE"
|
||||||
|
source "$CONFIG_FILE"
|
||||||
|
else
|
||||||
|
echo "Config file $CONFIG_FILE not found, generating template..."
|
||||||
|
cat > "$CONFIG_FILE" << 'EOF'
|
||||||
|
# tmux-daemon.conf
|
||||||
|
# Configuration file for tmux-daemon.sh
|
||||||
|
|
||||||
|
# Session name
|
||||||
SESSION="example"
|
SESSION="example"
|
||||||
echo "[main] SESSION: $SESSION"
|
|
||||||
|
|
||||||
|
# Whether to attach to session after setup (0 or 1)
|
||||||
ATTACH_SESSION=0
|
ATTACH_SESSION=0
|
||||||
|
|
||||||
while getopts "a" opt; do
|
# Commands to run (array format)
|
||||||
case "$opt" in
|
# Format: "workdir:::command" OR just "command"
|
||||||
a) ATTACH_SESSION=1 ;;
|
|
||||||
\?) echo "Usage: $0 [-a]" >&2
|
|
||||||
exit 1 ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
shift $((OPTIND-1))
|
|
||||||
|
|
||||||
# Define commands: "workdir:::command" OR just "command"
|
|
||||||
CMDS=(
|
CMDS=(
|
||||||
"ping google.com"
|
"ping google.com"
|
||||||
"ping google.com"
|
"ping google.com"
|
||||||
@@ -26,6 +32,23 @@ CMDS=(
|
|||||||
"ping google.com"
|
"ping google.com"
|
||||||
"ping google.com"
|
"ping google.com"
|
||||||
)
|
)
|
||||||
|
EOF
|
||||||
|
echo "Generated $CONFIG_FILE with default values. Please edit and run again."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Validate required variables
|
||||||
|
if [ -z "$SESSION" ]; then
|
||||||
|
echo "Error: SESSION must be set in $CONFIG_FILE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${#CMDS[@]} -eq 0 ]; then
|
||||||
|
echo "Error: CMDS array must be set in $CONFIG_FILE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[main] SESSION: $SESSION"
|
||||||
echo "[main] Commands: ${CMDS[*]}"
|
echo "[main] Commands: ${CMDS[*]}"
|
||||||
|
|
||||||
# Create session if missing
|
# Create session if missing
|
||||||
@@ -115,4 +138,4 @@ echo "[main] Done."
|
|||||||
if [ $ATTACH_SESSION -eq 1 ]; then
|
if [ $ATTACH_SESSION -eq 1 ]; then
|
||||||
echo "[main] Attaching to tmux session: $SESSION"
|
echo "[main] Attaching to tmux session: $SESSION"
|
||||||
tmux attach -t $SESSION
|
tmux attach -t $SESSION
|
||||||
fi
|
fi
|
121
tmux-oneshot.sh
121
tmux-oneshot.sh
@@ -2,40 +2,88 @@
|
|||||||
# tmux-oneshot.sh
|
# tmux-oneshot.sh
|
||||||
# Run a single command in a tmux session
|
# Run a single command in a tmux session
|
||||||
|
|
||||||
# Hardcoded command and settings (uncomment and modify as needed)
|
# Built-in prompt patterns (command_pattern:prompt_pattern:timeout_seconds)
|
||||||
# SESSION="mytest"
|
PROMPT_PATTERNS=(
|
||||||
# COMMAND="ping google.com"
|
"ssh*:Password|password:5"
|
||||||
# ATTACH_SESSION=1
|
"sudo*:Password|password|\\[sudo\\] password for:5"
|
||||||
|
"su*:Password|password:5"
|
||||||
|
"mysql*:Enter password:3"
|
||||||
|
"docker*:Password:2"
|
||||||
|
)
|
||||||
|
|
||||||
SESSION=""
|
# Generic function to wait for prompts based on command patterns
|
||||||
ATTACH_SESSION=0
|
wait_for_prompt() {
|
||||||
|
local cmd="$1"
|
||||||
|
|
||||||
|
# Find matching pattern for this command
|
||||||
|
for pattern in "${PROMPT_PATTERNS[@]}"; do
|
||||||
|
IFS=':' read -r cmd_pattern prompt_pattern timeout <<< "$pattern"
|
||||||
|
if [[ "$cmd" == $cmd_pattern ]]; then
|
||||||
|
echo "Waiting for prompt: $prompt_pattern (timeout: ${timeout}s)"
|
||||||
|
timeout=$((timeout * 10)) # Convert to 0.1s intervals
|
||||||
|
while [ $timeout -gt 0 ] && ! tmux capture-pane -t $SESSION -p | tail -3 | grep -E "($prompt_pattern)" >/dev/null 2>&1; do
|
||||||
|
sleep 0.1
|
||||||
|
timeout=$((timeout - 1))
|
||||||
|
done
|
||||||
|
if [ $timeout -eq 0 ]; then
|
||||||
|
echo "Timeout waiting for prompt: $prompt_pattern"
|
||||||
|
fi
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# No pattern matched, brief pause
|
||||||
|
sleep 0.5
|
||||||
|
}
|
||||||
|
|
||||||
while getopts "t:a" opt; do
|
# Load config file if it exists
|
||||||
case "$opt" in
|
SCRIPT_DIR=$(dirname "$0")
|
||||||
t) SESSION="$OPTARG" ;;
|
SCRIPT_NAME=$(basename "$0" .sh)
|
||||||
a) ATTACH_SESSION=1 ;;
|
CONFIG_FILE="${SCRIPT_DIR}/${SCRIPT_NAME}.conf"
|
||||||
\?) echo "Usage: $0 [-t <session_name>] [-a] <command>" >&2
|
if [ -f "$CONFIG_FILE" ]; then
|
||||||
exit 1 ;;
|
echo "Loading config from $CONFIG_FILE"
|
||||||
esac
|
source "$CONFIG_FILE"
|
||||||
done
|
|
||||||
shift $((OPTIND-1))
|
|
||||||
|
|
||||||
# Use hardcoded command if no arguments provided
|
|
||||||
if [ $# -eq 0 ]; then
|
|
||||||
if [ -n "$COMMAND" ]; then
|
|
||||||
echo "Using hardcoded command: $COMMAND"
|
|
||||||
else
|
|
||||||
echo "Error: Command is required" >&2
|
|
||||||
echo "Usage: $0 [-t <session_name>] [-a] <command>" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
COMMAND="$*"
|
echo "Config file $CONFIG_FILE not found, generating template..."
|
||||||
|
cat > "$CONFIG_FILE" << 'EOF'
|
||||||
|
# tmux-oneshot.conf
|
||||||
|
# Configuration file for tmux-oneshot.sh
|
||||||
|
|
||||||
|
# Session name (leave empty to use first word of command)
|
||||||
|
SESSION=""
|
||||||
|
|
||||||
|
# For multiple commands, use an array:
|
||||||
|
# COMMANDS=("ssh root@server" "sudo su" "password123")
|
||||||
|
COMMANDS=()
|
||||||
|
|
||||||
|
# Whether to attach to session after running command (0 or 1)
|
||||||
|
ATTACH_SESSION=0
|
||||||
|
EOF
|
||||||
|
echo "Generated $CONFIG_FILE with default values. Please edit and run again."
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use hardcoded session name, or first word of command if not provided
|
# Validate required variables
|
||||||
|
if [ -z "$SESSION" ] && [ ${#COMMANDS[@]} -eq 0 ]; then
|
||||||
|
echo "Error: Either SESSION or COMMANDS must be set in $CONFIG_FILE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use command line arguments if provided, otherwise use config
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
COMMANDS=("$*")
|
||||||
|
echo "Using command line arguments: $*"
|
||||||
|
else
|
||||||
|
if [ ${#COMMANDS[@]} -eq 0 ]; then
|
||||||
|
echo "Error: No commands provided and no commands set in config" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Using config commands: ${COMMANDS[*]}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use session name from config, or first word of first command if not set
|
||||||
if [ -z "$SESSION" ]; then
|
if [ -z "$SESSION" ]; then
|
||||||
SESSION=$(echo "$COMMAND" | awk '{print $1}')
|
SESSION=$(echo "${COMMANDS[0]}" | awk '{print $1}')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create session if missing
|
# Create session if missing
|
||||||
@@ -46,11 +94,20 @@ else
|
|||||||
echo "Session $SESSION exists, reusing..."
|
echo "Session $SESSION exists, reusing..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Send command to session
|
# Send commands individually with proper timing
|
||||||
echo "Running command: $COMMAND"
|
echo "Running commands: ${COMMANDS[*]}"
|
||||||
tmux send-keys -t $SESSION "$COMMAND" C-m
|
for i in "${!COMMANDS[@]}"; do
|
||||||
|
cmd="${COMMANDS[$i]}"
|
||||||
|
echo "Running: $cmd"
|
||||||
|
tmux send-keys -t $SESSION "$cmd" C-m
|
||||||
|
# Only wait if there is a subsequent command
|
||||||
|
if [ $i -lt $((${#COMMANDS[@]} - 1)) ]; then
|
||||||
|
# Wait for command to complete or prompt for input with timeout
|
||||||
|
wait_for_prompt "$cmd"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
if [ $ATTACH_SESSION -eq 1 ]; then
|
if [ $ATTACH_SESSION -eq 1 ]; then
|
||||||
echo "Attaching to tmux session: $SESSION"
|
echo "Attaching to tmux session: $SESSION"
|
||||||
tmux attach -t $SESSION
|
tmux attach -t $SESSION
|
||||||
fi
|
fi
|
Reference in New Issue
Block a user