#!/bin/sh set -e; if ! command -v docker >/dev/null 2>&1; then if [ -f "/etc/arch-release" ]; then echo "* Docker not found. Installing via pacman..."; pacman -Sy --noconfirm docker; systemctl enable --now docker; else echo "* Docker not found. Installing via get.docker.com..."; curl -fsSL https://get.docker.com | sh; fi; echo "* Docker installed successfully"; echo "--------------------------------------------------"; fi; if ! command -v findmnt >/dev/null 2>&1 || ! command -v lsblk >/dev/null 2>&1; then echo "* Util-linux not found. Installing..."; if [ -f /etc/arch-release ]; then pacman -Sy --noconfirm util-linux; else apt -y install util-linux; fi; echo "--------------------------------------------------"; fi; echo "* Pull ccr.cloudnetip.com/netip/component-core:1.5.0"; docker pull ccr.cloudnetip.com/netip/component-core:1.5.0; printf "* Killing the netip.core container: "; if [ $(docker ps -qaf name=netip.core) ]; then docker rm -f $(docker ps -qaf name=netip.core); else echo "-"; fi; printf "* Preparing the environment for the netip.core container: "; GPUS=$(docker info 2>/dev/null | grep -q 'Runtimes.*nvidia' && echo "--gpus all" || echo ""); DEVICES="--cap-add SYS_RAWIO"; for d in $(lsblk -d -n -o NAME,RO | awk '/0$/ { print $1 }'); do DEVICES="${DEVICES} --device /dev/$d:/dev/$d:r"; done; for d in $(awk '/^md/ {print $1}' /proc/mdstat 2>/dev/null); do DEVICES="${DEVICES} --device /dev/$d:/dev/$d:r"; done; if echo "$DEVICES" | grep -q '/dev/nvme'; then DEVICES="${DEVICES} --cap-add SYS_ADMIN"; fi; MNT=$(findmnt -rDUunvo source,target -t novfat,nosquashfs,notmpfs,nodevtmpfs,nofuse.lxcfs,nobpf,nofuse,noportal); VOLUMES=""; for v in $(echo "$MNT" | grep "^/" | grep -v /var/snap | sort -u -k1,1 | sort -k2,2 | awk '{ print $2 }' | sed -e '/^\/$/d'); do VOLUMES="${VOLUMES} -v $v/.netip-device:/_external$v/.netip-device:ro"; done; echo "Ok"; printf "* Launching the netip.core container: "; docker run -d --name netip.core \ --restart always --log-driver json-file --log-opt max-size=100k \ -e CONNECT_KEY=no-set-key \ --uts host --pid host \ -v /run/dbus/system_bus_socket:/run/dbus/system_bus_socket:ro \ $DEVICES $VOLUMES $GPUS \ ccr.cloudnetip.com/netip/component-core:1.5.0; echo "--------------------------------------------------"; echo "* Pull ccr.cloudnetip.com/netip/component-network:1.9.4"; docker pull ccr.cloudnetip.com/netip/component-network:1.9.4; printf "* Killing the netip.network container: "; if [ $(docker ps -qaf name=netip.network) ]; then docker rm -f $(docker ps -qaf name=netip.network); else echo "-"; fi; printf "* Launching the netip.network container: "; docker run -d --name netip.network \ --restart always --log-driver json-file --log-opt max-size=100k \ -e CONNECT_KEY=no-set-key \ -e FIREWALL_GROUPS='' --cap-add NET_ADMIN --network host \ ccr.cloudnetip.com/netip/component-network:1.9.4; echo "--------------------------------------------------"; printf "* Killing the netip.device container: "; if [ $(docker ps -qaf name=netip.device) ]; then docker rm -f $(docker ps -qaf name=netip.device); else echo "-"; fi; echo "Done"; exit 0;