Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·144 lines (124 loc) · 6.72 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·144 lines (124 loc) · 6.72 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env bash
set -e
# ── NMLinux installer ─────────────────────────────────────────────────────────
# Supports: Debian / Ubuntu / Linux Mint / Arch / Fedora / openSUSE
# Creates a venv in ~/.local/share/nmlinux/venv and installs a .desktop entry
# ─────────────────────────────────────────────────────────────────────────────
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENV_DIR="$HOME/.local/share/nmlinux/venv"
BIN_DIR="$HOME/.local/bin"
DESKTOP_DIR="$HOME/.local/share/applications"
ICON_DIR="$HOME/.local/share/icons/hicolor/256x256/apps"
LAUNCHER="$BIN_DIR/nmlinux"
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; NC='\033[0m'
info() { echo -e "${CYAN}[nmlinux]${NC} $*"; }
success() { echo -e "${GREEN}[nmlinux]${NC} $*"; }
warn() { echo -e "${YELLOW}[nmlinux]${NC} $*"; }
die() { echo -e "${RED}[nmlinux] ERROR:${NC} $*" >&2; exit 1; }
# ── Detect package manager ────────────────────────────────────────────────────
install_sys_deps() {
if command -v apt-get &>/dev/null; then
info "Detected apt — installing system dependencies..."
sudo apt-get update -qq
# freerdp3-x11 on Ubuntu 26.04+, freerdp2-x11 on older releases
if apt-cache show freerdp3-x11 &>/dev/null 2>&1; then
FREERDP_PKG="freerdp3-x11"
else
FREERDP_PKG="freerdp2-x11"
fi
info "Using RDP package: $FREERDP_PKG"
sudo apt-get install -y python3-full python3-venv libgl1 libglib2.0-0 \
libdbus-1-3 libxkbcommon0 libxkbcommon-x11-0 \
"$FREERDP_PKG" tigervnc-viewer nmap net-tools iputils-ping traceroute \
avahi-utils
elif command -v pacman &>/dev/null; then
info "Detected pacman — use the AUR package instead: yay -S nmlinux"
warn "Continuing anyway with pip install..."
elif command -v dnf &>/dev/null; then
info "Detected dnf — installing system dependencies..."
sudo dnf install -y python3 python3-virtualenv mesa-libGL dbus-libs \
freerdp tigervnc nmap net-tools iputils traceroute avahi-tools
elif command -v zypper &>/dev/null; then
info "Detected zypper — installing system dependencies..."
sudo zypper install -y python3 python3-virtualenv libGL1 dbus-1 \
freerdp tigervnc nmap net-tools iputils traceroute avahi
else
warn "Unknown package manager — skipping system dependencies."
warn "Make sure python3-venv and OpenGL libs are installed."
fi
}
# ── Reinstall guard ───────────────────────────────────────────────────────────
if [[ -d "$VENV_DIR" ]]; then
warn "NMLinux is already installed."
read -rp "Reinstall / update? [y/N] " answer
[[ "$answer" =~ ^[Yy]$ ]] || { info "Aborted."; exit 0; }
info "Removing existing venv..."
rm -rf "$VENV_DIR"
fi
# ── System deps ───────────────────────────────────────────────────────────────
install_sys_deps
# ── Python version check ──────────────────────────────────────────────────────
PY_VER=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
PY_MAJOR=$(python3 -c "import sys; print(sys.version_info.major)")
PY_MINOR=$(python3 -c "import sys; print(sys.version_info.minor)")
info "Detected Python $PY_VER"
if [[ "$PY_MAJOR" -lt 3 || ("$PY_MAJOR" -eq 3 && "$PY_MINOR" -lt 11) ]]; then
die "Python 3.11+ is required (found $PY_VER). Install a newer Python and retry."
fi
# ── Create venv ───────────────────────────────────────────────────────────────
info "Creating virtual environment at $VENV_DIR ..."
mkdir -p "$VENV_DIR"
python3 -m venv "$VENV_DIR"
info "Upgrading pip..."
"$VENV_DIR/bin/pip" install --quiet --upgrade pip
# ── Install nmlinux ───────────────────────────────────────────────────────────
info "Installing NMLinux..."
if ! "$VENV_DIR/bin/pip" install --quiet "$REPO_DIR"; then
warn "Standard install failed — trying with --no-build-isolation (sometimes needed for PySide6 on newer Python)..."
"$VENV_DIR/bin/pip" install --no-build-isolation "$REPO_DIR" \
|| die "Installation failed. Check pip output above. You may need: sudo apt install python3-pyside6*"
fi
success "NMLinux installed in venv."
# ── Launcher script ───────────────────────────────────────────────────────────
mkdir -p "$BIN_DIR"
cat > "$LAUNCHER" <<EOF
#!/usr/bin/env bash
exec "$VENV_DIR/bin/python" -m nmlinux.main "\$@"
EOF
chmod +x "$LAUNCHER"
info "Launcher created: $LAUNCHER"
# ── .desktop entry ────────────────────────────────────────────────────────────
mkdir -p "$DESKTOP_DIR"
# Copy icon if available in the repo
ICON_NAME="network-wired"
if [[ -f "$REPO_DIR/nmlinux/icons/nmlinux.png" ]]; then
mkdir -p "$ICON_DIR"
cp "$REPO_DIR/nmlinux/icons/nmlinux.png" "$ICON_DIR/nmlinux.png"
ICON_NAME="nmlinux"
fi
cat > "$DESKTOP_DIR/nmlinux.desktop" <<EOF
[Desktop Entry]
Name=NMLinux
GenericName=Network Manager
Comment=Network management tool for Linux
Exec=$LAUNCHER
Icon=$ICON_NAME
Terminal=false
Type=Application
Categories=Network;System;
Keywords=network;wifi;ssh;scan;dns;ping;nmap;
StartupNotify=true
StartupWMClass=nmlinux
EOF
# Ensure ~/.local/bin is in PATH
if [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then
warn "$BIN_DIR is not in your PATH."
warn "Add this line to your ~/.bashrc or ~/.zshrc:"
warn " export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
update-desktop-database "$DESKTOP_DIR" 2>/dev/null || true
echo ""
success "Installation complete!"
echo -e " Run from terminal : ${CYAN}nmlinux${NC}"
echo -e " Or launch from : Applications menu → Network → NMLinux"
echo ""