-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-sway.sh
More file actions
executable file
·106 lines (88 loc) · 3.33 KB
/
Copy pathsetup-sway.sh
File metadata and controls
executable file
·106 lines (88 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source "${SCRIPT_DIR}/config.sh"
CURRENT_USER=$(whoami)
# --- 1. Install dependencies ---
echo "Installing dependencies..."
sudo apt update
sudo apt install -y aravis-tools \
aravis-tools-cli \
sway \
libgstreamer1.0-dev \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-ugly \
gstreamer1.0-plugins-bad \
gstreamer1.0-libav \
gstreamer1.0-tools \
seatd
echo "Installation done."
# --- 1.1 Add user to video/render/input groups ---
echo "Adding user '${CURRENT_USER}' to video/render/input groups..."
sudo usermod -aG video,render,input "${CURRENT_USER}"
# --- 2. Network setup ---
echo "Setting static IP for interface ${INTERFACE}..."
CON_NAME=$(nmcli -t -f NAME connection show | grep "^${INTERFACE}$")
if [ -z "$CON_NAME" ]; then
echo "No existing connection for ${INTERFACE}, creating one..."
sudo nmcli connection add type ethernet ifname "${INTERFACE}" con-name "${INTERFACE}"
CON_NAME="${INTERFACE}"
fi
sudo nmcli connection modify "$CON_NAME" ipv4.addresses "$IP_ADDRESS" ipv4.method manual
sudo nmcli connection up "$CON_NAME"
echo "Static IP $IP_ADDRESS applied to ${INTERFACE}."
echo "Checking device connection ${PING_TARGET}..."
ping -c 1 ${PING_TARGET} && echo "Ping success." || echo "Ping error."
# --- 3. Enable user linger for systemd user service ---
sudo loginctl enable-linger "${CURRENT_USER}"
# --- 4. Sway config ---
mkdir -p ~/.config/sway/
cp /etc/sway/config ~/.config/sway/config
# if [ ! -f ~/.config/sway/config ]; then
# cp /etc/sway/config ~/.config/sway/config
# fi
# Comment out sway default wallpaper line
sed -i 's|^\(output \* bg .*\)|#\1|' ~/.config/sway/config
# Disable the default bar by commenting it out if not already
sed -i '/^bar {/,/^}/ s/^/#/' ~/.config/sway/config
# Ensure custom settings are appended once
CUSTOM_CFG=$(cat <<'EOC'
# --- Custom GigE stream config ---
exec_always ~/RP5/gige.sh
exec_always swayidle -w timeout 0
seat * hide_cursor 1000
default_border none
default_floating_border none
bindsym $mod+Shift+Escape exec swaymsg exit
EOC
)
if ! grep -q "Custom GigE stream config" ~/.config/sway/config; then
echo "$CUSTOM_CFG" >> ~/.config/sway/config
fi
# --- 5. Create user-level systemd service ---
USER_SYSTEMD_DIR="${HOME}/.config/systemd/user"
mkdir -p "${USER_SYSTEMD_DIR}"
tee "${USER_SYSTEMD_DIR}/${SERVICE_NAME}" > /dev/null << EOF
[Unit]
Description=GigE Camera Stream (Sway Wayland session)
After=graphical.target network.target seatd.service
# Requires=seatd.service
[Service]
Type=simple
ExecStartPre=/bin/rm -rf /run/user/%U/sway-ipc.* 2>/dev/null || true
ExecStart=/usr/bin/sway --unsupported-gpu
# ExecStart=/usr/bin/sway
ExecStop=/usr/bin/swaymsg exit || true
ExecStopPost=/bin/rm -rf /run/user/%U/sway-ipc.* 2>/dev/null || true
Restart=always
RestartSec=2
Environment="XDG_RUNTIME_DIR=/run/user/%U"
WorkingDirectory=%h
[Install]
WantedBy=default.target
EOF
# Reload user systemd and enable service
systemctl --user daemon-reload
systemctl --user enable --now "${SERVICE_NAME}"
echo "Setup complete. Service '${SERVICE_NAME}' will start automatically after user login."