diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-07-28 19:21:23 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-07-28 19:21:23 +0300 |
commit | 30d91f3b55c01a9dcc32c894db678801c7f9c1c6 (patch) | |
tree | 4396e2f8ba0701c67b93df88d44a51586ae7b070 | |
parent | 42df77cfe8cfc87c98f584875202c9ae95d6e019 (diff) |
add wrapper script
-rw-r--r-- | CMakeLists.txt | 9 | ||||
-rwxr-xr-x | captive-portal.sh | 36 |
2 files changed, 42 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 18493d0..c0eb30d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,15 @@ -cmake_minimum_required(VERSION 3.19) +cmake_minimum_required(VERSION 3.10) project(captive-netns-helper C) set(CMAKE_C_STANDARD 99) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - set(CMAKE_INSTALL_PREFIX /usr/local/bin) + set(CMAKE_INSTALL_PREFIX /usr/local) endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) add_executable(captive-netns-helper main.c) install(TARGETS captive-netns-helper - RUNTIME DESTINATION bin)
\ No newline at end of file + RUNTIME DESTINATION bin) +install(FILES captive-portal.sh + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE + DESTINATION bin)
\ No newline at end of file diff --git a/captive-portal.sh b/captive-portal.sh new file mode 100755 index 0000000..92f3b16 --- /dev/null +++ b/captive-portal.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +if [ $EUID -eq 0 ]; then + echo "error: this script should not be launched as root" + exit 1 +fi + +if [ $# -eq 0 ]; then + echo "error: no command specified" + exit 1 +fi + +export $(dhcpcd -U $IFACE) +if [ -z "$domain_name_servers" ]; then + echo "error: \$domain_name_servers variable not found" + exit 1 +fi + +IFACE=wlp3s0 +ENV= +for var in DISPLAY HOME PWD EDITOR USER XAUTHORITY LANG DBUS_SESSION_BUS_ADDRESS; do + value="${!var}" + if [ ! -z "$value" ]; then + ENV="$ENV --env $var=$value" + fi +done + +_doas="doas" +if ! command -v doas &>/dev/null; then + _doas="sudo" +fi + +$_doas captive-netns-helper \ + --nameserver $domain_name_servers \ + --ns-file /run/netns/captive \ + --uid $(id -u) --gid $(id -g) $ENV "$@"
\ No newline at end of file |