setup_weeder.sh
This is an old revision of the document!
chmod +x setup_weeder.sh && sudo ./setup_weeder.sh
#!/bin/bash
set -euo pipefail
# ====== CONFIG ======
USER="pi"
HOME_DIR="/home/$USER"
APP_DIR="$HOME_DIR/Desktop/WEEDER_PREMIUM_MULTI"
SERVICE_NAME="weeder.service"
echo "=== Install & enable NetworkManager ==="
sudo apt update || true
sudo apt install -y network-manager openssh-server
echo "=== Disable background updates / indexing / notifications ==="
# Keep correct time sync ON
sudo timedatectl set-timezone Europe/Riga || true
sudo timedatectl set-ntp true || true
# Disable apt automatic update timers/services
sudo systemctl disable --now apt-daily.timer apt-daily-upgrade.timer 2>/dev/null || true
sudo systemctl disable --now apt-daily.service apt-daily-upgrade.service 2>/dev/null || true
sudo systemctl mask apt-daily.timer apt-daily-upgrade.timer apt-daily.service apt-daily-upgrade.service 2>/dev/null || true
# Disable unattended upgrades
sudo systemctl disable --now unattended-upgrades.service 2>/dev/null || true
sudo systemctl mask unattended-upgrades.service 2>/dev/null || true
# Disable PackageKit / GUI package refresh
sudo systemctl disable --now packagekit.service packagekit-offline-update.service 2>/dev/null || true
sudo systemctl mask packagekit.service packagekit-offline-update.service 2>/dev/null || true
# Disable update notifier
sudo systemctl disable --now update-notifier-download.timer update-notifier-download.service 2>/dev/null || true
sudo systemctl mask update-notifier-download.timer update-notifier-download.service 2>/dev/null || true
sudo systemctl disable --now update-notifier-motd.timer update-notifier-motd.service 2>/dev/null || true
sudo systemctl mask update-notifier-motd.timer update-notifier-motd.service 2>/dev/null || true
# Disable plocate daily database indexing
sudo systemctl disable --now plocate-updatedb.timer plocate-updatedb.service 2>/dev/null || true
sudo systemctl mask plocate-updatedb.timer plocate-updatedb.service 2>/dev/null || true
# Disable firmware update daemon refresh
sudo systemctl disable --now fwupd-refresh.timer fwupd-refresh.service 2>/dev/null || true
sudo systemctl mask fwupd-refresh.timer fwupd-refresh.service 2>/dev/null || true
# Disable anacron daily jobs
sudo systemctl disable --now anacron.timer anacron.service 2>/dev/null || true
sudo systemctl mask anacron.timer anacron.service 2>/dev/null || true
# Disable snap background refresh/services if you do not need snap apps
sudo systemctl disable --now snapd.service snapd.socket snapd.seeded.service 2>/dev/null || true
sudo systemctl mask snapd.service snapd.socket snapd.seeded.service 2>/dev/null || true
# Disable printing services if printer support is not needed
sudo systemctl disable --now cups.service cups.socket cups.path cups-browsed.service 2>/dev/null || true
sudo systemctl mask cups.service cups.socket cups.path cups-browsed.service 2>/dev/null || true
# Disable GNOME tracker file indexing for user pi
sudo -u pi systemctl --user stop tracker-miner-fs-3.service tracker-extract-3.service 2>/dev/null || true
sudo -u pi systemctl --user mask tracker-miner-fs-3.service tracker-extract-3.service 2>/dev/null || true
# Kill already running background processes
pkill -f tracker-miner-fs-3 2>/dev/null || true
pkill -f update-notifier 2>/dev/null || true
pkill -f apt-check 2>/dev/null || true
pkill -f snap-store 2>/dev/null || true
pkill -f snapd-desktop-integration 2>/dev/null || true
# Disable APT periodic config
sudo bash -c 'cat > /etc/apt/apt.conf.d/20auto-upgrades <<EOF
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Download-Upgradeable-Packages "0";
APT::Periodic::AutocleanInterval "0";
APT::Periodic::Unattended-Upgrade "0";
EOF'
sudo systemctl enable --now NetworkManager
sudo systemctl enable --now ssh
echo "=== Netplan: NetworkManager renderer + static eth0 (link-local) ==="
sudo bash -c "cat <<'EOF' > /etc/netplan/99-nm.yaml
network:
version: 2
renderer: NetworkManager
ethernets:
eth0:
dhcp4: no
addresses:
- 169.254.1.244/24
EOF"
sudo netplan apply
echo "=== Create systemd service: $SERVICE_NAME ==="
sudo bash -c "cat <<EOF > /etc/systemd/system/$SERVICE_NAME
[Unit]
Description=Weeder Premium Multi 2 startup script
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=$USER
WorkingDirectory=$APP_DIR
ExecStart=/usr/bin/python3 $APP_DIR/server.py
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Restart=always
RestartSec=5
StandardOutput=append:$APP_DIR/startup.log
StandardError=append:$APP_DIR/startup_error.log
[Install]
WantedBy=multi-user.target
EOF"
echo "=== Enable and start service ==="
sudo systemctl daemon-reload
sudo systemctl enable "$SERVICE_NAME"
sudo systemctl restart "$SERVICE_NAME"
echo "=== Desktop shortcut (optional) ==="
mkdir -p "$HOME_DIR/Desktop"
cat <<EOF > "$HOME_DIR/Desktop/weeder.desktop"
[Desktop Entry]
Version=1.0
Name=weeder
Comment=Run WEEDER server
Exec=/usr/bin/python3 $APP_DIR/server.py
Terminal=true
Type=Application
Categories=Utility;
EOF
gio set "$HOME_DIR/Desktop/weeder.desktop" metadata::trusted true || true
chmod +x "$HOME_DIR/Desktop/weeder.desktop"
chown "$USER:$USER" "$HOME_DIR/Desktop/weeder.desktop" || true
echo "=== Sudoers (safe) ==="
sudo bash -c "cat <<EOF > /etc/sudoers.d/weeder
$USER ALL=(ALL) NOPASSWD: /sbin/shutdown, /sbin/iwlist, /usr/bin/nmcli, /bin/dmesg
EOF"
sudo chmod 0440 /etc/sudoers.d/weeder
echo "=== Setup complete. Rebooting in 5 seconds... ==="
sleep 5
sudo reboot
#!/bin/bash
set -euo pipefail
# ====== CONFIG ======
USER="pi"
HOME_DIR="/home/$USER"
APP_DIR="$HOME_DIR/Desktop/WEEDER_PREMIUM_MULTI"
SERVICE_NAME="server.service"
USB_MOUNT="/mnt/weederusb"
USB_IMG_DIR="$USB_MOUNT/field_images"
PATH_STORAGE="$APP_DIR/data_storage/path_storage.json"
echo "=== Install & enable NetworkManager ==="
sudo apt update || true
sudo apt install -y network-manager openssh-server
sudo systemctl enable --now NetworkManager
sudo systemctl enable --now ssh
echo "=== Netplan: NetworkManager renderer + static eth0 (link-local) ==="
sudo bash -c "cat <<'EOF' > /etc/netplan/99-nm.yaml
network:
version: 2
renderer: NetworkManager
ethernets:
eth0:
dhcp4: no
addresses:
- 169.254.1.244/16
routes:
- to: default
via: 169.254.1.1
EOF"
sudo netplan apply || true
echo "=== Prepare USB mount folder ==="
sudo mkdir -p "$USB_MOUNT"
sudo chown "$USER:$USER" "$USB_MOUNT"
sudo chmod 777 "$USB_MOUNT"
echo "=== Update path_storage.json img_folder_path ==="
if [ -f "$PATH_STORAGE" ]; then
python3 - <<PY
import json
path = "$PATH_STORAGE"
with open(path, "r") as f:
data = json.load(f)
data["img_folder_path"] = "$USB_IMG_DIR/"
with open(path, "w") as f:
json.dump(data, f, indent=4)
print("img_folder_path set to:", data["img_folder_path"])
PY
else
echo "WARNING: path_storage.json not found: $PATH_STORAGE"
fi
echo "=== Create systemd service: $SERVICE_NAME ==="
sudo bash -c "cat <<EOF > /etc/systemd/system/$SERVICE_NAME
[Unit]
Description=Weeder Premium Multi server startup script
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=$USER
WorkingDirectory=$APP_DIR
# Create stable USB mount point
ExecStartPre=/bin/mkdir -p $USB_MOUNT
# Unmount old mount if exists. '-' means ignore error.
ExecStartPre=-/bin/umount $USB_MOUNT
# Find first USB storage partition and mount it to $USB_MOUNT.
# If USB exists, mount with pi permissions.
# If no USB exists, service still starts and uses local /mnt/weederusb folder.
ExecStartPre=/bin/bash -c 'USB_DEV=\$(/bin/lsblk -rpno NAME,TYPE,TRAN | /usr/bin/awk '\\''\$2=="part" && \$3=="usb" {print \$1; exit}'\\''); if [ -n "\$USB_DEV" ]; then echo "[server.service] USB found: \$USB_DEV"; /bin/mount -o uid=1000,gid=1000,umask=000 "\$USB_DEV" $USB_MOUNT || /bin/mount "\$USB_DEV" $USB_MOUNT; else echo "[server.service] No USB found, using local $USB_MOUNT"; fi'
# Create image folder
ExecStartPre=/bin/mkdir -p $USB_IMG_DIR
ExecStartPre=/bin/chmod -R 777 $USB_IMG_DIR
ExecStart=/usr/bin/python3 $APP_DIR/server.py
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Restart=always
RestartSec=5
StandardOutput=append:$APP_DIR/startup.log
StandardError=append:$APP_DIR/startup_error.log
[Install]
WantedBy=multi-user.target
EOF"
echo "=== Disable old weeder.service if it exists ==="
sudo systemctl disable weeder.service 2>/dev/null || true
sudo systemctl stop weeder.service 2>/dev/null || true
echo "=== Enable and start $SERVICE_NAME ==="
sudo systemctl daemon-reload
sudo systemctl enable "$SERVICE_NAME"
sudo systemctl restart "$SERVICE_NAME"
echo "=== Desktop shortcut (optional) ==="
mkdir -p "$HOME_DIR/Desktop"
cat <<EOF > "$HOME_DIR/Desktop/weeder.desktop"
[Desktop Entry]
Version=1.0
Name=weeder
Comment=Run WEEDER server
Exec=/usr/bin/python3 $APP_DIR/server.py
Terminal=true
Type=Application
Categories=Utility;
EOF
gio set "$HOME_DIR/Desktop/weeder.desktop" metadata::trusted true || true
chmod +x "$HOME_DIR/Desktop/weeder.desktop"
chown "$USER:$USER" "$HOME_DIR/Desktop/weeder.desktop" || true
echo "=== Sudoers (safe) ==="
sudo bash -c "cat <<EOF > /etc/sudoers.d/weeder
$USER ALL=(ALL) NOPASSWD: /sbin/shutdown, /usr/sbin/shutdown, /usr/bin/systemctl, /sbin/iwlist, /usr/bin/nmcli, /bin/dmesg, /usr/bin/dmesg, /bin/mount, /usr/bin/mount, /bin/umount, /usr/bin/umount
EOF"
sudo chmod 0440 /etc/sudoers.d/weeder
echo "=== Setup complete ==="
echo "Service name: $SERVICE_NAME"
echo "Image path: $USB_IMG_DIR/"
echo ""
echo "Check with:"
echo " systemctl status $SERVICE_NAME"
echo " journalctl -u $SERVICE_NAME -f"
echo " mount | grep weederusb"
echo " grep -R 'img_folder_path' $PATH_STORAGE"
echo ""
echo "Rebooting in 5 seconds..."
sleep 5
sudo reboot
setup_weeder.sh.1779349288.txt.gz · Last modified: by 78.84.63.159 · Currently locked by: 216.73.217.69
