ryanniehaus / useful_scripts

A repository for keeping useful utility scripts
MIT License
20 stars 16 forks source link

Make the working directory configurable for the openvpn script #8

Open ryanniehaus opened 8 years ago

ryanniehaus commented 8 years ago

Per Issue #1:

@famewolf made the following comment: "I guess the only addition I would request is a method to overwrite what directory to use as when ran from cron.daily it tries to put the zip files in the /etc/cron.daily dir.....I hardcoded the dir in the previous version."

I think this is a good idea, and should be done when I have time.

ryanniehaus commented 8 years ago

@famewolf: This is implemented now

famewolf commented 8 years ago

IN Readme it says if the temp dir is not specified it falls back on script dir. What if the output dir is specified? It could also be used for temp files. I would think it would fall back to output dir first and then script. Or do you have to do it as ./script /home/famewolf/vpn /home/famewolf/vpn ?

ryanniehaus commented 8 years ago

You would have to specify it as script /home/famewolf/vpn /home/famewolf/vpn That way you could specify the output directory and it could still use the script directory as a temp directory

famewolf commented 8 years ago

I think I'll just stick with the hardcoded one I have. I have the script symbolically linked to /etc/cron.daily so it runs on a schedule...as far as the script would be concerned it's "working dir" would be /etc/cron.daily which is not somewhere I want it writing.

ryanniehaus commented 8 years ago

If you just repeat directories, it won't try to write in the cron folder. You'd just have to have a another script that calls this one with the arguments you'd need. Or would you rather it look for an environment variable?

famewolf commented 8 years ago

No..I guess I had tunnel vision...I was so focused on the symbolic link to the script it never even occurred to me to do something simple like make a one line script to do the proper call. I'm sure there's an amusing acronym for that type of user error somewhere on the 'net. ;)

I tried simplifying things by having the script run directly on my freenas server which is also where the folder is shared from via smb but was unable to get the script to run correctly from the freebsd jail even after installing bash and the required tools. I'm currently playing around with freenas's virtualbox implementation and have created a ubuntu minimal VM...seems like a whole lot of work to try and have 1 machine keep 1 script updated. Maybe I need to rethink my approach...my end desire is to have the vpn folder sync'd to cloud storage so my android devices can pull in the folder with current user/pass since they can't run the script themselves.

famewolf commented 8 years ago

Just tried new version...would still stick with old one. Where before each different vpn got it's own unique subfolder of www.vpnname.com now they all end up lumped into the same folder?

While I do like being able to specify the output folder so the script could be put into a /bin dir and the output could be kept in a vpn folder I still would want each vpn separated.

ryanniehaus commented 8 years ago

Yeah, I've started using OpenVPN on Windows, and I don't think it searches subdirectories. Maybe I'm mistaken.

The temp folder still has the subfolders. The output directory does not. However temp=output, you'll have both.

On Wed, Dec 30, 2015, 6:58 PM famewolf notifications@github.com wrote:

Just tried new version...would still stick with old one. Where before each different vpn got it's own unique subfolder of www.vpnname.com now they all end up lumped into the same folder?

— Reply to this email directly or view it on GitHub https://github.com/ryanniehaus/useful_scripts/issues/8#issuecomment-168101704 .

ryanniehaus commented 8 years ago

Do you get any errors in the script when running from Freebsd?

On Thu, Dec 31, 2015, 6:11 AM Ryan Niehaus ryan.niehaus@gmail.com wrote:

Yeah, I've started using OpenVPN on Windows, and I don't think it searches subdirectories. Maybe I'm mistaken.

The temp folder still has the subfolders. The output directory does not. However temp=output, you'll have both.

On Wed, Dec 30, 2015, 6:58 PM famewolf notifications@github.com wrote:

Just tried new version...would still stick with old one. Where before each different vpn got it's own unique subfolder of www.vpnname.com now they all end up lumped into the same folder?

— Reply to this email directly or view it on GitHub https://github.com/ryanniehaus/useful_scripts/issues/8#issuecomment-168101704 .

famewolf commented 8 years ago

When I ran the script to test I didn't specify a path at all...I just let it default to the script dir for both temp and output and that's when it dumped everything in one dir.

Yeah when I ran it, it had some errors I corrected...for instance it wanted "iconv -c -s -f" as opposed to "iconv -csf " but even after fixing obvious errors it still was going wrong....on the old version that did create subdir's it was still writing everything to the script dir so something was failing with the "domain_url" part (going from memory).

ryanniehaus commented 8 years ago

Have you tried the latest version? The iconv -c -s -f change I made because cygwin iconv didn't like the iconv -csf simplification.

I'm wondering if you still have issues on freebsd with it. (I'd like to make my script compatible with as many platforms as possible)

famewolf commented 8 years ago

I'll see about rebuilding the freebsd jail and try it again. I did finally get it working in a ubuntu minimal vm but the freebsd one would use far less resources. I wonder if freebsd has live usb images with persistence so you could install the necessary packages..would make testing easier.

famewolf commented 8 years ago

One change would be changing the first line to " #!/usr/bin/env bash" as bash is in /bin for linux and /usr/local/bin for freebsd. Using the env version makes it work in both places as documented here: https://news.ycombinator.com/item?id=7596191 or use #!/bin/sh which is universal if bash is not specifically needed.

famewolf commented 8 years ago

I've installed nano, bash, wget, and unix2dos to the shell...here is the output and it obviously goes south right from the beginning.

[root@FBSD /media/work]# ./vpnwork Using OUTPUT_DIR=/media/work Using TEMPORARY_DIR=/media/work Processing http://www.vpnbook.com/freevpn Domain http://www.vpnbook.com/freevpn mkdir: http://www.vpnbook.com: No such file or directory ./vpnwork: line 73: pushd: http://www.vpnbook.com/freevpn: No such file or directory --2016-01-01 20:19:29-- http://www.vpnbook.com/freevpn Resolving www.vpnbook.com (www.vpnbook.com)... 176.126.252.71 Connecting to www.vpnbook.com (www.vpnbook.com)|176.126.252.71|:80... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [text/html] Saving to: 'index.html' index.html [ <=> ] 11.22K --.-KB/s in 0.1s 2016-01-01 20:19:30 (79.0 KB/s) - 'index.html' saved [11491] ./vpnwork: line 85: http://www.vpnbook.com/freevpn_username_password.txt: No such file or directory ./vpnwork: line 86: http://www.vpnbook.com/freevpn_username_password.txt: No such file or directory cat: http://www.vpnbook.com/freevpn_username_password.txt: No such file or directory rm: http://www.vpnbook.com/freevpn_username_password.txt: No such file or directory head: illegal line count -- -1 ./vpnwork: line 104: _http://www.vpnbook.com/freevpn_username_password.txt: No such file or directory ./vpnwork: line 105: _http://www.vpnbook.com/freevpn_username_password.txt: No such file or directory _http://www.vpnbook.com/freevpn_username_password.txt: No such file or directory ./vpnwork: line 104: _http://www.vpnbook.com/freevpn_username_password.txt: No such file or directory ./vpnwork: line 105: _http://www.vpnbook.com/freevpn_username_password.txt: No such file or directory _http://www.vpnbook.com/freevpn_username_password.txt: No such file or directory --2016-01-01 20:19:33-- http://%3Cli%3E%3Ca/ Resolving
  • (optimized (class="red">(optimized)... failed: hostname nor servname provided, or not known. wget: unable to resolve host address 'class="red">(optimized' --2016-01-01 20:19:42-- http://for/ Resolving for (for)... failed: hostname nor servname provided, or not known. wget: unable to resolve host address 'for' --2016-01-01 20:19:42-- http://fast/ Resolving fast (fast)... 127.0.53.53 Connecting to fast (fast)|127.0.53.53|:80... failed: Can't assign requested address. Retrying. --2016-01-01 20:19:44-- (try: 2) http://fast/ Connecting to fast (fast)|127.0.53.53|:80... failed: Can't assign requested address. Retrying. --2016-01-01 20:19:46-- (try: 3) http://fast/ Connecting to fast (fast)|127.0.53.53|:80... failed: Can't assign requested address. Retrying. --2016-01-01 20:19:49-- (try: 4) http://fast/ Connecting to fast (fast)|127.0.53.53|:80... failed: Can't assign requested address. Retrying. --2016-01-01 20:19:53-- (try: 5) http://fast/ Connecting to fast (fast)|127.0.53.53|:80... failed: Can't assign requested address. Retrying. --2016-01-01 20:19:58-- (try: 6) http://fast/ Connecting to fast (fast)|127.0.53.53|:80... failed: Can't assign requested address. Retrying. --2016-01-01 20:20:04-- (try: 7) http://fast/ Connecting to fast (fast)|127.0.53.53|:80... failed: Can't assign requested address. Retrying. ^C [root@FBSD /media/work]#
  • ryanniehaus commented 8 years ago

    @famewolf: Some reason your version of sed doesn't find a match with my sed expression. I've broken it up into three separate sed commands to simplify the expression and still accomplish the same goal. Hopefully this just works. I'm not sure why your sed works so differently from mine.

    ryanniehaus commented 8 years ago

    Oh... it looks like there are still going to be issues with the zip file downloads. I see the zip file parsing isn't working either