Skip to content

Commit

Permalink
Update : output status has been tidied up
Browse files Browse the repository at this point in the history
  • Loading branch information
baguskokow committed Oct 6, 2023
1 parent fe4c839 commit 86fe9d0
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions marimovpn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ opensslVersion=$(openssl version | awk '{print $1 " = " "v"$2}')
openvpnVersion=$(openvpn --version | head -n 1 | awk '{print $1 " = " "v"$2}')

if [ $(echo $opensslVersion | grep -Eo OpenSSL) == "OpenSSL" ] && [ $(echo $openvpnVersion | grep -Eo OpenVPN) == "OpenVPN" ]; then
echo -e "Ensuring Packages are Installed | $success | [ $opensslVersion ] & [ $openvpnVersion ]"
echo -e "Ensuring Packages are Installed\t\t\t\t| $success | [ $opensslVersion ] & [ $openvpnVersion ]"
else
echo -e "Ensuring Packages are Installed | $failed | Please Install openssl & openvpn!"
echo -e "Ensuring Packages are Installed\t\t\t\t| $failed | Please Install openssl & openvpn!"
exit
fi

Expand All @@ -41,13 +41,13 @@ ls /etc/ssl/ | grep marimocerts > /dev/null
if [ $(echo $?) != 0 ]; then
mkdir $workdir 2>> $log
if [ $(echo $?) != 0 ]; then
echo -e "Creating Certificate Directory | $failed "
echo -e "Creating Certificate Directory\t\t\t\t| $failed "
exit
else
echo -e "Creating Certificate Directory | $success "
echo -e "Creating Certificate Directory\t\t\t\t| $success "
fi
else
echo -e "Creating Certificate Directory | $skipped | Directory Already Exist"
echo -e "Creating Certificate Directory\t\t\t\t| $skipped | Directory Already Exist"
fi

### Generate Root CA
Expand All @@ -70,13 +70,13 @@ ls $workdir/ca/ | grep ca.key > /dev/null && ls $workdir/ca/ | grep ca.crt > /de
if [ $(echo $?) != 0 ]; then
openssl req -x509 -nodes -newkey rsa:2048 -keyout $caDir/${certificates[0]} -out $caDir/${certificates[1]} -subj "/C=ID/ST=Jakarta/O=marimovpn/CN=ROOT CA" 2>> $log && echo "01" | tee $caDir/${certificates[2]} > /dev/null
if [ $(echo $?) != 0 ]; then
echo -e "Generating Root CA Certificate | $failed"
echo -e "Generating Root CA Certificate\t\t\t\t| $failed"
exit
else
echo -e "Generating Root CA Certificate | $success"
echo -e "Generating Root CA Certificate\t\t\t\t| $success"
fi
else
echo -e "Generating Root CA Certificate | $skipped | Certificate Already Exist"
echo -e "Generating Root CA Certificate\t\t\t\t| $skipped | Certificate Already Exist"
fi

### Generate Diffie–Hellman Key
Expand All @@ -102,13 +102,13 @@ ls $dhDir | grep ${certificates[3]} > /dev/null
if [ $(echo $?) != 0 ]; then
openssl dhparam -out $dhDir/${certificates[3]} 2048 2> /dev/null
if [ $(echo $?) != 0 ]; then
echo -e "Generating Diffie–Hellman Key | $failed"
echo -e "Generating Diffie–Hellman Key\t\t\t\t| $failed"
exit
else
echo -e "Generating Diffie–Hellman Key | $success"
echo -e "Generating Diffie–Hellman Key\t\t\t\t| $success"
fi
else
echo -e "Generating Diffie–Hellman Key | $skipped | Key Already Exist"
echo -e "Generating Diffie–Hellman Key\t\t\t\t| $skipped | Key Already Exist"
fi

### Generate TLS Key
Expand All @@ -134,13 +134,13 @@ ls $tlsDir | grep ${certificates[4]} > /dev/null
if [ $(echo $?) != 0 ]; then
openvpn --genkey secret $tlsDir/${certificates[4]} 2> /dev/null
if [ $(echo $?) != 0 ]; then
echo -e "Generating TLS Key | $failed"
echo -e "Generating TLS Key\t\t\t\t\t| $failed"
exit
else
echo -e "Generating TLS Key | $success"
echo -e "Generating TLS Key\t\t\t\t\t| $success"
fi
else
echo -e "Generating TLS Key | $skipped | TLS Key Already Exist"
echo -e "Generating TLS Key\t\t\t\t\t| $skipped | TLS Key Already Exist"
fi

### Generate Server Certificate
Expand All @@ -167,13 +167,13 @@ if [ $(echo $?) != 0 ]; then
openssl x509 -req -in $serverDir/server.csr -out $serverDir/${certificates[6]} -CA $caDir/${certificates[1]} -CAkey $caDir/${certificates[0]} -CAserial $caDir/${certificates[2]} -days 365 2> /dev/null
openssl verify -CAfile $caDir/${certificates[1]} $serverDir/${certificates[6]} > /dev/null
if [ $(echo $?) != 0 ]; then
echo -e "Generating Server Certificate | $failed"
echo -e "Generating Server Certificate\t\t\t\t| $failed"
exit
else
echo -e "Generating Server Certificate | $success"
echo -e "Generating Server Certificate\t\t\t\t| $success"
fi
else
echo -e "Generating Server Certificate | $skipped | Certificate Already Exist"
echo -e "Generating Server Certificate\t\t\t\t| $skipped | Certificate Already Exist"
fi

### Generate Client Certificate
Expand All @@ -200,26 +200,26 @@ if [ $(echo $?) != 0 ]; then
openssl x509 -req -in $clientDir/client.csr -out $clientDir/${certificates[8]} -CA $caDir/${certificates[1]} -CAkey $caDir/${certificates[0]} -CAserial $caDir/${certificates[2]} -days 365 2> /dev/null
openssl verify -CAfile $caDir/${certificates[1]} $clientDir/${certificates[8]} > /dev/null
if [ $(echo $?) != 0 ]; then
echo -e "Generating Client Certificate | $failed"
echo -e "Generating Client Certificate\t\t\t\t| $failed"
exit
else
echo -e "Generating Client Certificate | $success"
echo -e "Generating Client Certificate\t\t\t\t| $success"
fi
else
echo -e "Generating Client Certificate | $skipped | Certificate Already Exist"
echo -e "Generating Client Certificate\t\t\t\t| $skipped | Certificate Already Exist"
fi

### Ensuring config file is created

ls | grep config.txt > /dev/null

if [ $(echo $?) != 0 ]; then
echo -e "Ensuring config file is created | $failed"
echo -e "Ensuring config file is created\t\t\t\t| $failed"
echo "Exited"
echo "Configuration File not yet created. Please create the config file!" >> $log
exit
else
echo -e "Ensuring config file is created | $success"
echo -e "Ensuring config file is created\t\t\t\t| $success"
fi

# To do : Buat gimana caranya agar mendeteksi confignya itu benar atau salah
Expand Down Expand Up @@ -301,21 +301,21 @@ ls /etc/openvpn/ | grep server.conf > /dev/null
if [ $(echo $?) != 0 ]; then
$(serverConfiguration)
if [ $(echo $?) != 0 ]; then
echo -e "Generating Configuration File for Server | $failed"
echo -e "Generating Configuration File for Server\t\t| $failed"
echo "Exited"
exit
else
echo -e "Generating Configuration File for Server | $success"
echo -e "Generating Configuration File for Server\t\t| $success"
fi
else
echo -e "Generating Configuration File for Server | $skipped | Configuration Server is exist\n"
echo -e "Generating Configuration File for Server\t\t| $skipped | Configuration Server is exist\n"
declare userInput
read -p "You want to replace it with a new server configuration file? (y/n) " userInput
if [ $userInput == 'y' ]; then
$(serverConfiguration)
echo -e "\nReplacing Configuration File for Server | $success"
echo -e "\nReplacing Configuration File for Server\t\t\t| $success"
else
echo -e "\nReplacing Configuration File for Server | $skipped"
echo -e "\nReplacing Configuration File for Server\t\t\t| $skipped"
fi
fi

Expand All @@ -326,21 +326,21 @@ ls /etc/openvpn/client | grep client.ovpn > /dev/null
if [ $(echo $?) != 0 ]; then
$(clientConfiguration)
if [ $(echo $?) != 0 ]; then
echo -e "Generating Configuration File for Client | $failed"
echo -e "Generating Configuration File for Client\t\t| $failed"
echo "Exited"
exit
else
echo -e "Generating Configuration File for Client | $success"
echo -e "Generating Configuration File for Client\t\t| $success"
fi
else
echo -e "Generating Configuration File for Client | $skipped | Configuration Client is exist\n"
echo -e "Generating Configuration File for Client\t\t| $skipped | Configuration Client is exist\n"
declare userInput
read -p "You want to replace it with a new client configuration file? (y/n) " userInput
if [ $userInput == 'y' ]; then
$(serverConfiguration)
echo -e "\nReplacing Configuration File for Client | $success"
echo -e "\nReplacing Configuration File for Client\t\t\t| $success"
else
echo -e "\nReplacing Configuration File for Client | $skipped"
echo -e "\nReplacing Configuration File for Client\t\t\t| $skipped"
fi
fi

Expand Down

0 comments on commit 86fe9d0

Please sign in to comment.