Skip to content

Commit

Permalink
Rename scripts for better consistancy (#866)
Browse files Browse the repository at this point in the history
* Address shellcheck concerns with n2n_gateway.sh script

* Rename n2n_gateway.sh to live with all the other scripts (and update docs)

* Rename hack_fakeautoconf to make it clearly a shell script

* Address shellcheck concerns with hack_fakeautoconf.sh

* Rename python scripts to match other n2n tools

* Fix windows compile - when streamlining the use of hack_fakeautoconf.sh, I forgot to update all uses of this script
  • Loading branch information
hamishcoleman authored Oct 23, 2021
1 parent 80b33cd commit 7eb3f2c
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 30 deletions.
17 changes: 5 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,16 @@ jobs:
steps:
- uses: actions/checkout@v2

# This is a pretty big hammer, but gets the windows compile moving
- name: Hack up a fake autoconf
run: |
echo true >autogen.sh
cp scripts/hack_fakeautoconf configure
shell: bash

- name: generate a makefile and use it to install more packages
run: |
./autogen.sh
./configure
# This is a pretty big hammer, but gets the windows compile moving
./scripts/hack_fakeautoconf.sh
make build-dep
shell: bash

- name: Run the real configure step
- name: Run a configure step
run: |
CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="--coverage" ./configure --with-zstd
CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="--coverage" ./scripts/hack_fakeautoconf.sh
shell: bash

- name: Run embedded tests
Expand Down Expand Up @@ -325,7 +318,7 @@ jobs:
- name: Configure and Build
shell: bash
run: |
./scripts/hack_fakeautoconf
./scripts/hack_fakeautoconf.sh
make
- name: Create binary dir
Expand Down
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ test: tools
lint: lint.python lint.ccode lint.shell

lint.python:
flake8 scripts/n2nctl scripts/n2nhttpd
flake8 scripts/n2n-ctl scripts/n2n-httpd

lint.ccode:
scripts/indent.sh $(LINT_CCODE)
Expand Down
2 changes: 1 addition & 1 deletion doc/Building.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ applied as of 2021-09-29.
- All the remaining commands must be run from inside a bash shell ("C:\Program Files\Git\usr\bin\bash.exe")
- git clone $THIS_REPO
- cd n2n
- ./scripts/hack_fakeautoconf
- ./scripts/hack_fakeautoconf.sh
- make
- make test

Expand Down
2 changes: 1 addition & 1 deletion doc/Routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ On the client side, the easiest way to configure routing is via the `-n` option.

10.0.0.1 is the IP address of the gateway to use to route the specified network. It should correspond to the IP address of the `server` within n2n. Multiple `-n` options can be specified.

As an alternative to the `-n` option, the `ip route` linux command can be manually used. See the [n2n_gateway.sh](doc/n2n_gateway.sh) script for an example. See also the following description of other use cases and in depth explanation.
As an alternative to the `-n` option, the `ip route` linux command can be manually used. See the [n2n-gateway.sh](scripts/n2n-gateway.sh) script for an example. See also the following description of other use cases and in depth explanation.

## Special Scenarios

Expand Down
19 changes: 12 additions & 7 deletions doc/Scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ may be installed with n2n as part of your operating system package.

Short descriptions of these scripts are below.

## `scripts/hack_fakeautoconf`
## `scripts/hack_fakeautoconf.sh`

This shell script is used during development to help build on Windows
systems. An example of how to use it is shown in
Expand All @@ -23,18 +23,18 @@ the automated lint checks.

This shell script is used to run automated tests during development.

## `scripts/n2nctl`
## `scripts/n2n-ctl`

This python script provides an easy command line interface to the running
n2n processes. It uses UDP communications to talk to the Management API.
By specifying the right UDP port, it can talk to both the edge and the
supernode daemons.

Example:
- `scripts/n2nctl --help`
- `scripts/n2nctl help`
- `scripts/n2n-ctl --help`
- `scripts/n2n-ctl help`

## `scripts/n2nhttpd`
## `scripts/n2n-httpd`

This python script is a simple http gateway to the running edge. It provides
a proxy for REST-like HTTP requests to talk to the Management API.
Expand All @@ -46,5 +46,10 @@ run with default settings can be seen at http://localhost:8080/ (Also
a http://localhost:8080/supernode.html page for the supernode)

Example:
- `scripts/n2nhttpd --help`
- `scripts/n2nhttpd 8087`
- `scripts/n2n-httpd --help`
- `scripts/n2n-httpd 8087`

## `scripts/n2n-gateway.sh`

A sample script to route all the host traffic towards a remote gateway,
which is reachable via the n2n virtual interface.
8 changes: 4 additions & 4 deletions scripts/hack_fakeautoconf → scripts/hack_fakeautoconf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
# Specifically for windows, where installing autoconf looks suspiciously
# like boiling the ocean.

cat Makefile.in | sed \
sed \
-e "s%@N2N_VERSION_SHORT@%FIXME%g" \
-e "s%@GIT_COMMITS@%FIXME%g" \
-e "s%@CC@%gcc%g" \
-e "s%@AR@%ar%g" \
-e "s%@CFLAGS@%$CFLAGS%g" \
-e "s%@LDFLAGS@%$LDFLAGS%g" \
-e "s%@N2N_LIBS@%$LDLIBS%g" \
> Makefile
< Makefile.in > Makefile

cat tools/Makefile.in | sed \
sed \
-e "s%@ADDITIONAL_TOOLS@%%g" \
> tools/Makefile
< tools/Makefile.in > tools/Makefile

cat <<EOF >include/config.h
#define PACKAGE_VERSION "FIXME"
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions doc/n2n_gateway.sh → scripts/n2n-gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if ! ip route get $N2N_GATEWAY | grep -q $N2N_INTERFACE ; then
fi

# Determine the current internet gateway
internet_gateway=`ip route get 8.8.8.8 | head -n1 | awk '{ print $3 }'`
internet_gateway=$(ip route get 8.8.8.8 | head -n1 | awk '{ print $3 }')

# Backup the DNS resolver configuration and use the specified server
cp /etc/resolv.conf /etc/resolv.conf.my_bak
Expand All @@ -49,18 +49,18 @@ echo "nameserver $DNS_SERVER" > /etc/resolv.conf

# The public IP of the supernode must be reachable via the internet gateway
# Whereas all the other traffic will go through the new VPN gateway.
ip route add $N2N_SUPERNODE via $internet_gateway
ip route add $N2N_SUPERNODE via "$internet_gateway"
ip route del default
echo "Forwarding traffic via $N2N_GATEWAY"
ip route add default via $N2N_GATEWAY

function stopService {
echo "Deleting custom routes"
ip route del default
ip route del $N2N_SUPERNODE via $internet_gateway
ip route del $N2N_SUPERNODE via "$internet_gateway"

echo "Restoring original gateway $internet_gateway"
ip route add default via $internet_gateway
ip route add default via "$internet_gateway"

echo "Restoring original DNS"
mv /etc/resolv.conf.my_bak /etc/resolv.conf
Expand Down
File renamed without changes.

0 comments on commit 7eb3f2c

Please sign in to comment.