Browse Source

fixed script for freebsd

afeiszli 3 years ago
parent
commit
39cd054521
2 changed files with 53 additions and 14 deletions
  1. 17 14
      scripts/netclient-install.sh
  2. 36 0
      scripts/netmaker-server.sh

+ 17 - 14
scripts/netclient-install.sh

@@ -32,15 +32,15 @@ set -- $dependencies
 while [ -n "$1" ]; do
 while [ -n "$1" ]; do
     echo $1
     echo $1
 	if [ "${OS}" = "FreeBSD" ]; then
 	if [ "${OS}" = "FreeBSD" ]; then
-		is_installed=$(pkg check -d $1 | grep '100%')
-		if [ "${is_installed}" = '100%' ]; then
+		is_installed=$(pkg check -d $1 | grep "Checking" | grep "done")
+		if [ "$is_installed" != "" ]; then
 			echo "    " $1 is installed
 			echo "    " $1 is installed
 		else
 		else
 			echo "    " $1 is not installed. Attempting install.
 			echo "    " $1 is not installed. Attempting install.
 			${install_cmd} $1
 			${install_cmd} $1
 			sleep 5
 			sleep 5
-			is_installed=$(pkg check -d $1 | grep '100%')
-			if [ "${is_installed}" = '100%' ]; then
+			is_installed=$(pkg check -d $1 | grep "Checking" | grep "done")
+			if [ "$is_installed" != "" ]; then
 				echo "    " $1 is installed
 				echo "    " $1 is installed
 			elif [ -x "$(command -v $1)" ]; then
 			elif [ -x "$(command -v $1)" ]; then
 				echo "    " $1 is installed
 				echo "    " $1 is installed
@@ -159,30 +159,29 @@ else
 	echo "Downloading $dist latest"
 	echo "Downloading $dist latest"
 	wget -nv -O netclient https://github.com/gravitl/netmaker/releases/download/latest/$dist
 	wget -nv -O netclient https://github.com/gravitl/netmaker/releases/download/latest/$dist
 fi
 fi
+
 chmod +x netclient
 chmod +x netclient
 
 
 EXTRA_ARGS=""
 EXTRA_ARGS=""
 if [ "${OS}" = "FreeBSD" ]; then
 if [ "${OS}" = "FreeBSD" ]; then
-	EXTRA_ARGS = "--daemon=off"
+	EXTRA_ARGS="--daemon=off"
 fi
 fi
 
 
 if [ -z "${NAME}" ]; then
 if [ -z "${NAME}" ]; then
-sudo ./netclient join -t $KEY $EXTRA_ARGS
+  ./netclient join -t $KEY $EXTRA_ARGS
 else
 else
-sudo ./netclient join -t $KEY --name $NAME $EXTRA_ARGS
+  ./netclient join -t $KEY --name $NAME $EXTRA_ARGS
 fi
 fi
 
 
-rm -f netclient
-
 if [ "${OS}" = "FreeBSD" ]; then
 if [ "${OS}" = "FreeBSD" ]; then
-	tee /usr/local/etc/rc.d/netclient <<'EOF' >/dev/null
+	mv ./netclient /etc/netclient/netclient
+	cat << 'END_OF_FILE' > ./netclient.service.tmp
 #!/bin/sh
 #!/bin/sh
 
 
 # PROVIDE: netclient
 # PROVIDE: netclient
 # REQUIRE: LOGIN DAEMON NETWORKING SERVERS FILESYSTEM
 # REQUIRE: LOGIN DAEMON NETWORKING SERVERS FILESYSTEM
 # BEFORE:  
 # BEFORE:  
 # KEYWORD: shutdown
 # KEYWORD: shutdown
-
 . /etc/rc.subr
 . /etc/rc.subr
 
 
 name="netclient"
 name="netclient"
@@ -194,7 +193,11 @@ command_args="-c -f -P ${pidfile} -R 10 -t "Netclient" -u root -o /etc/netclient
 load_rc_config $name
 load_rc_config $name
 run_rc_command "$1"
 run_rc_command "$1"
 
 
-EOF
-	/usr/local/etc/rc.d/netclient enable
-	/usr/local/etc/rc.d/netclient start
+END_OF_FILE
+	sudo mv ./netclient.service.tmp /usr/local/etc/rc.d/netclient
+	sudo chmod +x /usr/local/etc/rc.d/netclient
+	sudo /usr/local/etc/rc.d/netclient enable
+	sudo /usr/local/etc/rc.d/netclient start
+else
+	rm -f netclient
 fi
 fi

+ 36 - 0
scripts/netmaker-server.sh

@@ -0,0 +1,36 @@
+#!/bin/sh
+set -e
+
+mkdir -p /etc/netmaker/config/environments
+wget -O /etc/netmaker/netmaker https://github.com/gravitl/netmaker/releases/download/latest/netmaker
+chmod +x /etc/netmaker/netmaker
+
+cat >/etc/netmaker/config/environments/dev.yaml<<EOL
+server:
+  host:
+  apiport: "8081"
+  grpcport: "50051"
+  masterkey: "secretkey"
+  allowedorigin: "*"
+  restbackend: true            
+  agentbackend: true
+  dnsmode: "on"
+EOL
+
+cat >/etc/systemd/system/netmaker.service<<EOL
+[Unit]
+Description=Netmaker Server
+After=network.target
+
+[Service]
+Type=simple
+Restart=on-failure
+
+WorkingDirectory=/etc/netmaker
+ExecStart=/etc/netmaker/netmaker
+
+[Install]
+WantedBy=multi-user.target
+EOL
+systemctl daemon-reload
+systemctl start netmaker.service