if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null;then
echo -e "${YELLOW}Docker Compose is not installed. Please install Docker Compose first.${NC}"
exit1
fi
}
function get_docker_compose_cmd(){
if docker compose version &> /dev/null;then
echo"docker compose"
else
echo"docker-compose"
fi
}
function install_npm_wg(){
check_root
check_dependencies
if[ -d "$INSTALL_DIR"];then
echo -e "${YELLOW}Installation directory ($INSTALL_DIR) already exists. Do you want to update instead?${NC}"
return
fi
read -p "Enter your server's public IP or Domain for WireGuard (WG_HOST): " WG_HOST
if[ -z "$WG_HOST"];then
echo -e "${RED}WG_HOST cannot be empty. Aborting.${NC}"
return
fi
mkdir -p "$INSTALL_DIR"
# Create docker-compose.yml
cat <<EOF > "$DOCKER_COMPOSE_YML"
version: "3.8"
services:
npm-wg:
image: xtcnet/npm-wg:latest # NOTE: Update with actual Docker Hub image if pushed, or leave as npm-wg:latest if built locally. Assuming docker hub image is available or they build it.
# Wait, the README uses npm-wg:latest.
container_name: npm-wg
restart: unless-stopped
cap_add:
- NET_ADMIN
- SYS_MODULE
sysctls:
- net.ipv4.ip_forward=1
- net.ipv4.conf.all.src_valid_mark=1
ports:
- "80:80"# HTTP
- "81:81"# Admin UI
- "443:443"# HTTPS
- "51820:51820/udp"# WireGuard
volumes:
- ./data:/data
- ./letsencrypt:/etc/letsencrypt
- ./wireguard:/etc/wireguard
environment:
WG_HOST: "$WG_HOST"
EOF
# Fix the image name
sed -i 's/xtcnet\/npm-wg:latest/npm-wg:latest/g'"$DOCKER_COMPOSE_YML"
echo -e "${GREEN}Docker compose file created at $DOCKER_COMPOSE_YML${NC}"
cd"$INSTALL_DIR"||exit
localdc_cmd=$(get_docker_compose_cmd)
$dc_cmd up -d
echo -e "${GREEN}NPM-WG installed and started successfully!${NC}"