Mar 26, 2018 06:46 AM
(This post was last modified: Mar 26, 2018 07:44 PM by antmatt.)
Im tired of the effort it takes to script new clients for my vpn server, and since my ip changes weekly and i have a lot of people to make clients for, i need an easier way to do this.
Essentially i need my script to accept an input, so like “./myscript XXX” and have it do the following things
$ cd openvpn-ca/
$ source vars
$ ./build-key XXX
$ cd ~client-configs/
$ ./makeconfig.sh XXX
$ cd files/
$ sudo cp XXX /home/ftpserver/ftp/files/
(That last location is where i pull the client files from on my phone so i can send them to people by email and such)
It should be simple but im new to scripting so i dont know how to go about this... i can do the
echo “mypassword” | sudo -S cp
Too to make it easier but whatever works. Thanks for reading if you did lol
___________________________________________________________
update since none of you helped ya boy out
this is what I did and it worked and i couldnt find any tutorials on google for what I needed specifically I just got lucky with some educated guesses but here it is
I was amazed when i did the .../files/$clientname.ovpn and it works and actually creates the ovpn file and copies it to the directory I need so i can use the ftp app on my phone and send it to people through airdrop and email and such.
the echo mypassword | sudo -S line lets you run commands that require sudo privileges without having to enter your password, since it echos your password for you. this is unsecure and a bad idea since it stores your password in plain text in the script, but if you leave your computer locked and secure and such then you will be fine. the average user wont know what theyre looking for and as long as nobody hacks you then there is no worries. I know im secure on my network and computer end so its safe for me to do that, but keep the risk in mind.
Essentially i need my script to accept an input, so like “./myscript XXX” and have it do the following things
$ cd openvpn-ca/
$ source vars
$ ./build-key XXX
$ cd ~client-configs/
$ ./makeconfig.sh XXX
$ cd files/
$ sudo cp XXX /home/ftpserver/ftp/files/
(That last location is where i pull the client files from on my phone so i can send them to people by email and such)
It should be simple but im new to scripting so i dont know how to go about this... i can do the
echo “mypassword” | sudo -S cp
Too to make it easier but whatever works. Thanks for reading if you did lol
___________________________________________________________
update since none of you helped ya boy out
this is what I did and it worked and i couldnt find any tutorials on google for what I needed specifically I just got lucky with some educated guesses but here it is
Code
#!/bin/bash
echo "Client name: "
read clientname
cd openvpn-ca/
source vars
~/openvpn-ca/./build-key $clientname
~/client-configs/./make_config.sh $clientname
echo mypassword | sudo -S cp ~/client-configs/files/$clientname.ovpn /home/ftpserver/ftp/files/the echo mypassword | sudo -S line lets you run commands that require sudo privileges without having to enter your password, since it echos your password for you. this is unsecure and a bad idea since it stores your password in plain text in the script, but if you leave your computer locked and secure and such then you will be fine. the average user wont know what theyre looking for and as long as nobody hacks you then there is no worries. I know im secure on my network and computer end so its safe for me to do that, but keep the risk in mind.

