diff options
author | Christian Hesse | 2022-03-03 13:36:35 +0100 |
---|---|---|
committer | Christian Hesse | 2022-03-03 13:36:35 +0100 |
commit | 6758a6afe304bb4c4d4239ec4c9fa69fba7b1c1b (patch) | |
tree | e7836a8984e2c9a9c689745a4493570431ae3ed4 | |
parent | 5a359bb9bf5480a93ed2f034573af0361d6997d3 (diff) | |
download | aur-6758a6afe304bb4c4d4239ec4c9fa69fba7b1c1b.tar.gz |
commit netinstall 7.1.3-2
-rw-r--r-- | .SRCINFO | 24 | ||||
-rw-r--r-- | PKGBUILD | 49 | ||||
-rw-r--r-- | netinstall-gui.c | 95 | ||||
-rw-r--r-- | netinstall-gui.install | 9 | ||||
-rw-r--r-- | netinstall.desktop | 2 | ||||
-rw-r--r-- | netinstall.sh | 74 |
6 files changed, 228 insertions, 25 deletions
@@ -1,20 +1,30 @@ pkgbase = netinstall pkgdesc = Mikrotik Netinstall for RouterOS pkgver = 7.1.3 - pkgrel = 1 + pkgrel = 2 url = https://www.mikrotik.com/ - install = netinstall.install arch = i686 arch = x86_64 license = custom makedepends = icoutils - depends = wine - depends = libcap + makedepends = libcap source = https://download.mikrotik.com/routeros/7.1.3/netinstall-7.1.3.zip - source = netinstall.c + source = https://download.mikrotik.com/routeros/7.1.3/netinstall-7.1.3.tar.gz source = netinstall.desktop + source = netinstall.sh + source = netinstall-gui.c sha256sums = a82e98b208075892401a6dc528daa819a98703f9ef368cfd45c249576e6b14ae - sha256sums = 76a0c33ce80e49899bc3bc67dfc03737dcafa51fd4e62561199e56b17d5854d7 - sha256sums = 742b8ebf2b66697f24a27b5e6920dd4a4b92dec0fea928e8f58e499246284623 + sha256sums = 2fdac3a91ace044749ebfec9b1b590ecd5c70eee8121fdadcb45583ce6a55860 + sha256sums = 285e32e9ba8bad9791cf3d5d3653b6e21bd771adcc32ea2036fe32dc9dafcfe0 + sha256sums = f074f8c93e33a2278fd7209747a3e2c6d725935b5670b5e992ab1e4ece6e808e + sha256sums = b5efb376a6705c376465bff6f52dc0713c15fbd5cd861fdc39969cbb22c233b4 pkgname = netinstall + pkgdesc = Mikrotik Netinstall for RouterOS - CLI with network namespace + optdepends = sudo: invoke as non-root + +pkgname = netinstall-gui + pkgdesc = Mikrotik Netinstall for RouterOS - GUI via wine + install = netinstall-gui.install + depends = wine + depends = libcap @@ -1,31 +1,46 @@ # Maintainer: Christian Hesse <mail@eworm.de> -pkgname=netinstall +pkgbase=netinstall +pkgname=(netinstall netinstall-gui) pkgver=7.1.3 -pkgrel=1 +pkgrel=2 pkgdesc='Mikrotik Netinstall for RouterOS' arch=('i686' 'x86_64') url='https://www.mikrotik.com/' license=('custom') -depends=('wine' 'libcap') -makedepends=('icoutils') -install=netinstall.install +makedepends=('icoutils' 'libcap') source=("https://download.mikrotik.com/routeros/${pkgver}/netinstall-${pkgver}.zip" - 'netinstall.c' - 'netinstall.desktop') + "https://download.mikrotik.com/routeros/${pkgver}/netinstall-${pkgver}.tar.gz" + 'netinstall.desktop' + 'netinstall.sh' + 'netinstall-gui.c') sha256sums=('a82e98b208075892401a6dc528daa819a98703f9ef368cfd45c249576e6b14ae' - '76a0c33ce80e49899bc3bc67dfc03737dcafa51fd4e62561199e56b17d5854d7' - '742b8ebf2b66697f24a27b5e6920dd4a4b92dec0fea928e8f58e499246284623') + '2fdac3a91ace044749ebfec9b1b590ecd5c70eee8121fdadcb45583ce6a55860' + '285e32e9ba8bad9791cf3d5d3653b6e21bd771adcc32ea2036fe32dc9dafcfe0' + 'f074f8c93e33a2278fd7209747a3e2c6d725935b5670b5e992ab1e4ece6e808e' + 'b5efb376a6705c376465bff6f52dc0713c15fbd5cd861fdc39969cbb22c233b4') build() { - wrestool -x -t 14 netinstall.exe > netinstall.ico - gcc ${CFLAGS} ${LDFLAGS} -o netinstall netinstall.c -lcap + wrestool -x -t 14 netinstall.exe > netinstall.ico + gcc ${CFLAGS} ${LDFLAGS} -o netinstall-gui netinstall-gui.c -lcap } -package() { - install -D -m0755 netinstall.exe ${pkgdir}/usr/share/netinstall/netinstall.exe - install -D -m0755 netinstall ${pkgdir}/usr/bin/netinstall - install -D -m0644 netinstall.desktop ${pkgdir}/usr/share/applications/netinstall.desktop - install -D -m0644 netinstall.ico ${pkgdir}/usr/share/pixmaps/netinstall.ico - install -D -m0644 LICENSE.txt ${pkgdir}/usr/share/licenses/netinstall/LICENSE.txt +package_netinstall() { + pkgdesc='Mikrotik Netinstall for RouterOS - CLI with network namespace' + optdepends=('sudo: invoke as non-root') + + install -D -m0755 netinstall.sh ${pkgdir}/usr/bin/netinstall + install -D -m0755 netinstall ${pkgdir}/usr/lib/netinstall/netinstall +} + +package_netinstall-gui() { + pkgdesc='Mikrotik Netinstall for RouterOS - GUI via wine' + depends=('wine' 'libcap') + install=netinstall-gui.install + + install -D -m0755 netinstall-gui ${pkgdir}/usr/bin/netinstall-gui + install -D -m0755 netinstall.exe ${pkgdir}/usr/lib/netinstall/netinstall.exe + install -D -m0644 netinstall.desktop ${pkgdir}/usr/share/applications/netinstall.desktop + install -D -m0644 netinstall.ico ${pkgdir}/usr/share/pixmaps/netinstall.ico + install -D -m0644 LICENSE.txt ${pkgdir}/usr/share/licenses/netinstall/LICENSE.txt } diff --git a/netinstall-gui.c b/netinstall-gui.c new file mode 100644 index 000000000000..e5d1bcc48d68 --- /dev/null +++ b/netinstall-gui.c @@ -0,0 +1,95 @@ +/* + * (C) 2020-2021 by Christian Hesse <mail@eworm.de> + * + * This software may be used and distributed according to the terms + * of the GNU General Public License, incorporated herein by reference. + * + * Running Mikrotik netinstall with unprivileged user requires ambient + * capability CAP_NET_BIND_SERVICE. This is a wrapper to run it in wine. + */ + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/capability.h> +#include <sys/stat.h> +#include <unistd.h> + +#define WINE_PATH "/usr/bin/wine" +#define NETINSTALL_EXE_PATH "/usr/lib/netinstall/netinstall.exe" + +int main(int argc, char ** argv) { + cap_t caps; + cap_flag_value_t cap_effective = 0, cap_permitted = 0; + const cap_value_t cap = CAP_NET_BIND_SERVICE; + + if (!CAP_IS_SUPPORTED(cap)) { + fprintf(stderr, "Capability CAP_NET_BIND_SERVICE is not supported.\n"); + goto out10; + } + if ((caps = cap_get_proc()) == NULL) { + perror("cap_get_proc"); + goto out10; + } + if (cap_get_flag(caps, cap, CAP_EFFECTIVE, &cap_effective) == -1 || + cap_get_flag(caps, cap, CAP_PERMITTED, &cap_permitted) == -1 || + cap_effective == 0 || cap_permitted == 0) { + fprintf(stderr, "Capability CAP_NET_BIND_SERVICE is not available. Set it with setcap(8).\n"); + goto out20; + } + if (cap_set_flag(caps, CAP_INHERITABLE, 1, &cap, CAP_SET) == -1) { + perror("cap_set_flag: setting CAP_INHERITABLE for CAP_NET_BIND_SERVICE"); + goto out20; + } + if (cap_set_proc(caps) == -1) { + perror("cap_set_proc"); + goto out20; + } + if (cap_free(caps) == -1) { + perror("cap_free"); + goto out10; + } + if (cap_set_ambient(cap, CAP_SET) == -1) { + perror("cap_set_ambient: setting CAP_NET_BIND_SERVICE"); + goto out10; + } + + struct stat st; + const char *home = getenv("HOME"); + char wineprefix[256]; + snprintf(wineprefix, sizeof(wineprefix), "%s/.netinstall/wine/", home); + + setenv("WINEPREFIX", wineprefix, 1); + setenv("WINEARCH", "win64", 1); + setenv("WINEDLLOVERRIDES", "mscoree=", 1); + setenv("WINEDEBUG", "-all", 1); + + if (chdir(home) == -1) { + perror("chdir: changing to home directory"); + goto out10; + } + + if (stat(".netinstall/", &st) == -1) { + if (mkdir(".netinstall/", 0777) == -1) { + perror("mkdir: creating directory '.netinstall/'"); + goto out10; + } + + if (system("wineboot -u") != 0) { + perror("system: running wineboot"); + goto out10; + } + } + + char * const newargv[] = { "wine", NETINSTALL_EXE_PATH, NULL }; + execv(WINE_PATH, newargv); + + /* execv() returns only on error */ + perror("execv"); + +out20: + cap_free(caps); + +out10: + return EXIT_FAILURE; +} diff --git a/netinstall-gui.install b/netinstall-gui.install new file mode 100644 index 000000000000..2216cac9ffb2 --- /dev/null +++ b/netinstall-gui.install @@ -0,0 +1,9 @@ +#!/bin/sh + +post_install() { + setcap CAP_NET_BIND_SERVICE+ep usr/bin/netinstall-gui +} + +post_upgrade() { + post_install +} diff --git a/netinstall.desktop b/netinstall.desktop index 8729d930221a..7adf65a029f5 100644 --- a/netinstall.desktop +++ b/netinstall.desktop @@ -3,7 +3,7 @@ Type=Application Version=1.0 Name=Netinstall Comment=Mikrotik Netinstall for RouterOS -Exec=/usr/bin/netinstall +Exec=/usr/bin/netinstall-gui Icon=/usr/share/pixmaps/netinstall.ico Terminal=false Categories=Utility diff --git a/netinstall.sh b/netinstall.sh new file mode 100644 index 000000000000..06cb03c6a4ff --- /dev/null +++ b/netinstall.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +set -e + +INTERFACE= +PACKAGES=() +OPTIONS=() + +function help() { + echo "usage: ${0} [OPTIONS]" + echo + echo "where OPTIONS are:" + echo " -h show this help" + echo " -i INTERFACE install via INTERFACE" + echo " -k KEYFILE use KEYFILE" + echo " -p PACKAGE install PACKAGE" + echo " -r reset configuration" + echo " -s SCRIPT run script" +} + +while getopts "hi:k:p:rs:" opt; do + case ${opt} in + h) + help + exit 0 + ;; + i) + if ! ip addr show dev "${OPTARG}" >/dev/null 2>/dev/null; then + echo "Interface '${OPTARG}' does not exist." >&2 + exit 1 + fi + INTERFACE="${OPTARG}" + ;; + k) + OPTIONS+=(-k "${OPTARG}") + ;; + p) + if [ ! -s "${OPTARG}" ]; then + echo "Package '${OPTARG}' does not exist." >&2 + exit 1 + fi + PACKAGES+=("${OPTARG}") + ;; + r) + OPTIONS+=(-r) + ;; + s) + OPTIONS+=(-s "${OPTARG}") + ;; + esac +done + +if [ -z "${PACKAGES}" ]; then + echo "No package given for installation." >&2 + exit 1 +fi + +if [ -z "${INTERFACE}" ]; then + echo "No interface given for installation." >&2 + exit 1 +fi + +if [ "${UID}" -gt 0 ]; then + exec sudo -p "This must be run as root. Please enter the password for %u to continue: " -- /bin/bash -- "${0}" $@ +fi + +ip netns add netinstall +trap 'ip netns delete netinstall' EXIT INT QUIT TERM HUP + +ip link set dev "${INTERFACE}" netns netinstall +ip netns exec netinstall ip addr add 192.168.88.2/24 dev "${INTERFACE}" +ip netns exec netinstall ip link set dev "${INTERFACE}" up +ip netns exec netinstall ip route add default dev "${INTERFACE}" +ip netns exec netinstall /usr/lib/netinstall/netinstall "${OPTIONS[@]}" -a 192.168.88.1 "${PACKAGES[@]}" |