Softether VPN Setup: Automatic Script executed from git - bash

Am kind of new to bash scripting but i was wondering if it is possible to create automatic installations script for softether vpn server on raspberry pi to be executed from git and if it is possible how do you create one as I cant find any of the tutorial online to implement what i want, I tried to create mine and I failed miserably. any help will be appreciated.Thanks
sudo su
cd /root/
wget https://www.softether-download.com/files/softether/v4.34-9745-rtm-2020.04.05-tree/Linux/SoftEther_VPN_Server/32bit_-_ARM_EABI/softether-vpnserver-v4.34-9745-rtm-2020.04.05-linux-arm_eabi-32bit.tar.gz
tar xzf softether-vpnserver-v4.34-9745-rtm-2020.04.05-linux-arm_eabi-32bit.tar.gz && rm softether-vpnserver-v4.34-9745-rtm-2020.04.05-linux-arm_eabi-32bit.tar.gz
cd vpnserver && sudo make
cd ..
sudo mv vpnserver /usr/local && cd /usr/local/vpnserver/
sudo chmod 600 *
sudo chmod 700 vpnserver vpncmd
sudo ./vpnserver start
sudo ./vpncmd
ServerPasswordSet
echo net.ipv4.ip_forward = 1 | ${SUDO} tee -a /etc/sysctl.conf
echo net.ipv6.ip_forward = 1 | ${SUDO} tee -a /etc/sysctl.conf
sudo cat >> /etc/init.d/vpnserver << EOF
#!/bin/sh
### BEGIN INIT INFO
# Provides: vpnserver
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: SoftEther VPN 1.0 RC2
# Description: Start vpnserver daemon SoftEther VPN 1.0 Server
### END INIT INFO
DAEMON=/usr/local/vpnserver/vpnserver
LOCK=/var/lock/vpnserver
. /lib/lsb/init-functions
test -x $DAEMON || exit 0
case "$1" in
start)
sleep 3
log_daemon_msg "Starting SoftEther VPN 1.0 Server" "vpnserver"
$DAEMON start >/dev/null 2>&1
touch $LOCK
log_end_msg 0
sleep 3
;;
stop)
log_daemon_msg "Stopping SoftEther VPN 1.0 Server" "vpnserver"
$DAEMON stop >/dev/null 2>&1
rm $LOCK
log_end_msg 0
sleep 2
;;
restart)
$DAEMON stop
sleep 2
$DAEMON start
sleep 5
;;
status)
if [ -e $LOCK ]
then
echo "vpnserver is running."
else
echo "vpnserver is not running."
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
EOF
sudo chmod 755 /etc/init.d/vpnserver
sudo update-rc.d vpnserver defaults
systemctl enable vpnserver
sudo /etc/init.d/vpnserver start
sudo /etc/init.d/vpnserver stop
sudo /etc/init.d/vpnserver restart
wget -qO- https://ipecho.net/plain ; echo

Related

Bash script: Installs Docker, Skaffold, Minikube, and kubectl on a Linux system

sims installation process is ok, but when i'm starting minikube i'm getting error:
Exiting due to DRV_NOT_HEALTHY: Found driver(s) but none were healthy. See above for suggestions how to fix installed drivers.
and then when i'm manually running command that i already have in script:
sudo usermod -aG docker $USER && newgrp docker
minikube starts...
any suggestions? here is whole script:
#!/bin/bash
function run_command {
local cmd="$1"
local spinner_text="$2"
echo -n "$spinner_text"
{
eval "$cmd" &>/dev/null
} &
local spinner=$!
local spin='-\|/'
local i=0
while kill -0 $spinner 2>/dev/null
do
i=$(( (i+1) %4 ))
printf "\r$spinner_text ${spin:$i:1}"
sleep .1
done
wait $spinner
local exit_code=$?
if [[ $exit_code != 0 ]]; then
echo "Error: $cmd failed with exit code $exit_code."
exit $exit_code
fi
echo "Done."
}
# Update package lists
run_command "apt-get update" "Updating package lists... "
# Install Docker
run_command "apt-get install -y docker.io" "Installing Docker... "
# Install Skaffold
run_command "curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 && chmod +x skaffold && sudo mv skaffold /usr/local/bin" "Installing Skaffold... "
# Install Minikube
run_command "curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin" "Installing Minikube... "
# Install kubectl
run_command "curl -LO https://storage.googleapis.com/kubernetes-release/release/\`curl -L https://storage.googleapis.com/kubernetes-release/release/stable.txt\`/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/" "Installing kubectl... "
# Add the current user to the Docker group
run_command "sudo usermod -aG docker $USER && newgrp docker" "Adding user to Docker group... "
# Add virtual host to /etc/hosts
run_command "echo '192.168.49.2 hcms.dev' | sudo tee -a /etc/hosts" "Adding virtual host to /etc/hosts... "
echo "Installation complete."

Cannot start AEM as a service on Ubuntu 18.04

I'm trying to setup AEM (Adobe Experience Manager) Author as a Service on Ubuntu 18.04 on an AWS EC2 instance.
Script file "aem" at /usr/bin/aem (file permissions to "root")
#!/bin/bash
#
# description: This service manages the Adobe Experience Manager java process.
# processname: aem6
. /lib/lsb/init-functions
SCRIPT_NAME=`basename $0`
AEM_ROOT=/opt/aem/author
AEM_USER=root
########
BIN=${AEM_ROOT}/crx-quickstart/bin
START=${BIN}/start
STOP=${BIN}/stop
STATUS=${BIN}/status
case "$1" in
start)
if [ -f $START ]; then
echo "Starting AEM Service.."
/bin/su -l $AEM_USER -c $START
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/${SCRIPT_NAME}
fi
;;
stop)
if [ -f $STOP ]; then
echo "Stopping AEM Service.."
/bin/su -l $AEM_USER -c $STOP
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/${SCRIPT_NAME}
fi
;;
status)
if [ -f $STATUS ]; then
echo -s "Checking status of $SCRIPT_NAME: "
/bin/su -l $AEM_USER -c $STATUS
RETVAL=$?
[ $RETVAL -eq 0 ] && echo "$SCRIPT_NAME is running"
fi
;;
restart)
/bin/su -l ${AEM_USER} -c ${STOP}
/bin/su -l ${AEM_USER} -c ${START}
;;
reload)
;;
*)
echo "Usage: $0 {start|stop|status|reload}"
RETVAL=1
;;
esac
exit $RETVAL
Service file at /etc/systemd/system/aem.service (file permissions to "root")
[Unit]
Description=Adobe Experience Manager
[Service]
Type=simple
ExecStart=/usr/bin/aem start
ExecStop=/usr/bin/aem stop
ExecReload=/usr/bin/aem restart
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
when checking the service status:
ubuntu#ip-109:~$ sudo systemctl status aem
aem.service - Adobe Experience Manager
Loaded: loaded (/etc/systemd/system/aem.service; enabled; vendor preset: enabled)
Active: active (exited) since Wed 2019-10-23 20:25:21 UTC; 3min 24s ago
Process: 20106 ExecStart=/usr/bin/aem start (code=exited, status=0/SUCCESS)
Main PID: 20106 (code=exited, status=0/SUCCESS)
Oct 23 20:25:21 ip-172-31-14-109 systemd[1]: Started Adobe Experience Manager.
Oct 23 20:25:21 ip-172-31-14-109 aem[20106]: Starting AEM Service..
Oct 23 20:25:21 ip-172-31-14-109 su[20122]: Successful su for root by root
Oct 23 20:25:21 ip-172-31-14-109 su[20122]: + ??? root:root
Oct 23 20:25:21 ip-172-31-14-109 su[20122]: pam_unix(su:session): session opened for user root by (uid=0)
Oct 23 20:25:21 ip-172-31-14-109 aem[20106]: mesg: ttyname failed: Inappropriate ioctl for device
Oct 23 20:25:21 ip-172-31-14-109 su[20122]: pam_unix(su:session): session closed for user root
But cannot see "java" process (using ps -ef | grep java ) or port "4502" being used (using sudo lsof -i -P -n | grep LISTEN).
What am i missing?
Was able to resolve the issue. The problem was with "java" not being available to all users. Installed Oracle Java using default (ubuntu) user, while the aem script was running as root.
Steps to install custom Java.. not the Ubuntu default:
Download the tar.gz file "https://download.oracle.com/otn/java/jdk/8u231-b11/5b13a193868b4bf28bcb45c792fce896/jdk-8u 231-linux-x64.tar.gz"
Copy the file to the server using SCP
Make a directory mkdir /opt/java
Install and copy sudo tar -zxf jdk-8u231-linux-x64.tar.gz -C /opt/java/
Update your environment to allow Java for all users. Run this command
sudo update-alternatives --install /usr/bin/java java /opt/java/jdk1.8.0_231/bin/java 1
Add path to ".bashrc". Open to edit sudo nano ~/.bashrc
Add these lines to the end of the file:
export JAVA_HOME=/opt/java/jdk1.8.0_231
export PATH=${PATH}:${JAVA_HOME}/bin
After this.. start the "aem" service again. It should be working!

Bash Script with Several Nested elif Statements Not Working

I am trying to create a script I can provide to those who will use an academic game I am making. I am trying to do the following:
Verify that Apache2 is installed and Running
If Apache2 is installed, move a folder containing the website files to /var/www/html while backing up apache's original index.html
The code is as follows:
#!/bin/sh
acm=[]
cnn=[]
gnu=[]
ieee=[]
if [pgrep -x "apache2" > /dev/null]; then
echo "Apache 2 Installed and Running!"
if [ -d "$HOME/acmDL" ]; then
sudo mkdir /var/www/bak
sudo mv /var/www/html/index.html /var/www/bak
sudo mv acmDL /var/www/html/
cd /var/www/html/
sudo mv acmDL/* .
exit
elif [ -d "$HOME/cnnDL" ]; then
sudo mkdir /var/www/bak
sudo mv /var/www/html/index.html /var/www/bak
sudo mv cnnDL /var/www/html/
cd /var/www/html/
sudo mv cnnDL/* .
exit
elif [ -d "$HOME/gnuDL" ]; then
sudo mkdir /var/www/bak
sudo mv /var/www/html/index.html /var/www/bak
sudo mv gnuDL /var/www/html/
cd /var/www/html/
sudo mv gnuDL/* .
exit
elif [ -d "$HOME/ieeeDL" ]; then
sudo mkdir /var/www/bak
sudo mv /var/www/html/index.html /var/www/bak
sudo mv ieeeDL /var/www/html/
cd /var/www/html/
sudo mv ieeeDL/* .
exit
else
echo "Provided websites not found... Are you using a custom website?"
fi
else
echo "Please check apache2... It may not have installed correctly"
fi
The error I keep getting is syntax error near unexpected token `elif' on line 15.
As you can see, I even tried moving the boolean expression [ - d "$HOME/site" ] to their own variables, but then the error becomes : -d: command not found and the error on line 15.
Is what I am trying to do impossible, or am I missing something undocumented and yet completely obvious (like a handful of my previous posts)?
This is being run on a minimal installation of Ubuntu 18 on a Virtual Machine. The site directories are shared by Filezilla. Script written in Notepad++ on Windows 7 x64.
First of all, can you rewrite it like this?
Please tell me the execution result.
This is wrong.
if [pgrep -x "apache2" > /dev/null]; then
This is correct.
pgrep -x "apache2" > /dev/null
if [ $? -eq 0 ]; then

Boot to shell with Ubuntu MATE 15.04 on Raspberry PI 2

Is it possible to boot to the terminal? I've tried to look for a grub file but I could not find it. Also /boot/firmware/config.txt does not seem to have such option.
Thanks to Rohith Madhavan and AceFace on Ubuntu-mate bitbucket issues:
You can boot to shell using the following commands:
systemctl set-default multi-user.target --force
systemctl disable lightdm.service --force
systemctl disable graphical.target --force
systemctl disable plymouth.service --force
Replace disable with enable to boot with GUI again.
The proposed solution doesn't work on Ubuntu MATE 16.04 and the "Welcome" application mentions a non-existent "graphical" command. The following worked for me :
#!/bin/bash
if [[ "$1" == 'enable' || "$1" == 'disable' ]]; then
if [ "$1" == 'disable' ]; then
systemctl set-default multi-user.target --force
fi
systemctl $1 lightdm.service --force
systemctl $1 graphical.target --force
systemctl $1 plymouth.service --force
if [ "$1" == 'enable' ]; then
if [ ! -h /etc/systemd/system/display-manager.service ]; then
ln -s /lib/systemd/system/lightdm.service /etc/systemd/system/display-manager.service
fi
systemctl set-default graphical.target --force
fi
else
echo 'Enables or disables GUI at boot.'
echo "Usage : $(basename) {enable | disable}"
fi

How to run some programs which require `source ~/.bashrc` and to be launched inside tmux with upstart?

I have some programs which require source ~/.bashrc and should be launched inside tmux with upstart.
So I've wrote the following test programs and it works when I manually start these daemons by initctl start xxx, but it doesn't at boot-time.
I'm using Ubuntu 12.04.
Does anyone have a solution?
test programs
3 test conf scripts
eisoku#server:~$ cat /etc/init/start-tmux.conf
description "tmux daemon"
start on started network-manager
stop on runlevel [!2345]
umask 022
nice -5
script
sudo -iu eisoku /bin/bash -i -c 'source ~/.bashrc && bash ~/Desktop/util/start-tmux.bash' &
watch -n 100 ls
end script
eisoku#server:~$ cat /etc/init/test-a.conf
description "test a daemon"
start on started start-tmux
stop on stopped start-tmux
umask 022
script
sudo -iu eisoku /bin/bash -i -c "source ~/Desktop/util/tmux-patch.bash && tmux-newwindow test-a htop" &
watch -n 100 ls
end script
eisoku#server:~$ cat /etc/init/test-b.conf
description "test b daemon"
start on started start-tmux
stop on stopped start-tmux
umask 022
script
sudo -iu eisoku /bin/bash -i -c "source ~/Desktop/util/tmux-patch.bash && tmux-newwindow test-b top" &
watch -n 100 ls
end script
util scripts
eisoku#server:~$ cat ~/Desktop/util/start-tmux.bash
#!/bin/bash
SESSION_NAME=`hostname`
tmux new-session -d -s $SESSION_NAME -n tmp
eisoku#server:~$ cat ~/Desktop/util/tmux-patch.bash
#!/bin/bash
tmux-newwindow() {
if [ `tmux list-windows | grep " $1 " | cut -d' ' -f2` ]; then
echo $1 "already exists"
else
tmux new-window -k -n $1 -t `hostname`
tmux send-keys -t `hostname`:$1 ${#:2} C-m
fi
}
tmux-killwindow() {
if [ `tmux list-windows | grep " $1 " | cut -d' ' -f2` ]; then
tmux kill-window -t $1
else
echo $i "not exists"
fi
}
result
eisoku#local-PC:~$ ssh eisoku#server
Welcome to Ubuntu 12.04.5 LTS (GNU/Linux 3.11.0-26-generic x86_64)
eisoku#server:~$ sudo reboot
After reboot,
eisoku#local-PC:~$ ssh eisoku#server
Welcome to Ubuntu 12.04.5 LTS (GNU/Linux 3.11.0-26-generic x86_64)
eisoku#server:~$ tmux list-windows
0: tmp [80x23] [layout b85e,80x23,0,0] (active)
eisoku#server:~$
eisoku#server:~$ initctl status start-tmux
start-tmux start/running, process 1030
eisoku#server:~$ initctl status test-a
test-a start/running, process 1033
eisoku#server:~$ initctl status test-b
test-b start/running, process 1031
test-a and test-b seem not to be worked as I had expected while the status of the daemons is running.
However, it works when I manually start these daemons
eisoku#server:~$ sudo initctl restart test-a
test-a start/running, process 3369
eisoku#server:~$ sudo initctl restart test-b
test-b start/running, process 3461
eisoku#server:~$ tmux list-windows
0: tmp [80x23] [layout b85e,80x23,0,0]
1: test-a [80x23] [layout b85e,80x23,0,0]
2: test-b [80x23] [layout b85e,80x23,0,0] (active)
I've solved my own problem. It is because Upstart run jobs in parallel and Upstart tries to start test-a job just after upstart starts start-tmux job so that tmux, which is launched by start-tmux job in this case, is not completely launched.
I can solve it by using pre-start to wait for tmux to be launched and letting test-b job chain to test-a like this.
eisoku#server:~$ cat /etc/init/test-a.conf
description "test a daemon"
start on started start-tmux
stop on stopped start-tmux
umask 022
pre-start script
/bin/sleep 1
end script
script
sudo -iu eisoku /bin/bash -i -c "source ~/Desktop/util/tmux-patch.bash && tmux-newwindow test-a htop" &
watch -n 100 ls
end script
eisoku#server:~$ cat /etc/init/test-b.conf
description "test b daemon"
start on started test-a
stop on stopped start-tmux
umask 022
pre-start script
/bin/sleep 1
end script
script
sudo -iu eisoku /bin/bash -i -c "source ~/Desktop/util/tmux-patch.bash && tmux-newwindow test-b top" &
watch -n 100 ls
end script

Resources