not-cdn 1 year ago
commit
a060f85532
6 changed files with 262 additions and 0 deletions
  1. 15
    0
      Caddyfile
  2. 21
    0
      LICENSE
  3. 101
    0
      README.md
  4. 63
    0
      setup.sh
  5. 50
    0
      start.sh
  6. 12
    0
      stop.sh

+ 15
- 0
Caddyfile View File

@@ -0,0 +1,15 @@
0.0.0.0:2470

# forward requests from local-only rclone serve
proxy / 127.0.0.1:3018

# log requests, anonymize IP for safety
log / requests.log "{combined}" {
ipmask 255.255.255.0 ffff:ffff:ffff:ff00::
}

# not a secure site
tls off

# login
basicauth / user letmein

+ 21
- 0
LICENSE View File

@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 not-cdn

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

+ 101
- 0
README.md View File

@@ -0,0 +1,101 @@
# not-server
`not-server` is a set of scripts that gives you the ability to network install to [Tinfoil](https://github.com/digableinc/tinfoil)/[SX Installer](https://sx.xecuter.com/#download) from a remote location.

**NO USER SUPPORT IS PROVIDED**


## Features
- Can be set up in ~5 minutes
- Does not use significant local space
- Does not require FUSE support or root access (see FAQ)
- Password protected, (semi-anonymized) logging enabled


## Requirements
- **Bandwidth** (Traffic generated will be 2x the content size)
- A local or remote copy of content on a [supported backend](https://rclone.org/) (ie. Google Drive)
- SSH access to the server you will host on
- **BASIC** command line skills - current script supports Linux and macOS


## Usage
- Download and install [Tinfoil](https://github.com/digableinc/tinfoil) or [SX Installer](https://sx.xecuter.com/#download)
- Download `not-server`
- Run `git clone https://git.teknik.io/not-cdn/not-server.git && cd not-server`
- alternative, manual version: `wget https://git.teknik.io/not-cdn/not-server/archive/master.zip && unzip not-server-master.zip && rm not-server-master.zip && cd not-server`
- If the below commands error out, you'll need to run `chmod +x {script}.sh`
- Run `setup.sh` for one time setup
- Run `start.sh` to start `not-server`
- Configure a new network location via `locations.conf` (for Tinfoil) or directly on your Switch (for SX Installer)
- Download and install content
- Run `stop.sh` to stop `not-server`

#### `locations.conf` example
Replace `hostname:port` in url, `user`, and `password`.
```json
[
{
"title": "Base",
"url": "http://hostname:port/base/",
"user": "user",
"password": "letmein"
},
{
"title": "Updates",
"url": "http://hostname:port/updates/",
"user": "user",
"password": "letmein"
},
{
"title": "DLC",
"url": "http://hostname:port/dlc/",
"user": "user",
"password": "letmein"
}
]
```

#### SX installer example
```text
Protocol - http
Host - hostname
Port - port
Path - /base
Username - user
Password - letmein
repeat for updates and dlc locations, changing Path to /updates or /dlc respectively
```


## FAQ
### I don't have root, this won't work!
That's not a question.
The script can accommodate `rclone` and `caddy` executables placed in the same folder.
**If you don't have root, you'll need to manually download, unzip, and make executable those two programs.** For example, on Linux it'd look something like:

`caddy` - https://caddyserver.com/download
```
wget "https://caddyserver.com/download/linux/amd64?license=personal&telemetry=off" -O caddy.tar.gz
tar -xvf caddy.tar.gz caddy && rm caddy.tar.gz && chmod +x caddy
```

`rclone` - https://rclone.org/downloads/
```
wget "https://downloads.rclone.org/rclone-current-linux-amd64.zip" -O rclone.zip
unzip rclone.zip rclone-v1.46-linux-amd64/rclone
mv rclone-v1.46-linux-amd64/rclone . && rmdir rclone-v1.46-linux-amd64/
chmod +x rclone
```

### How do I get a nice URL instead of an IP address?
Use a free DDNS (dynamic DNS) provider ([no-ip](https://www.noip.com/sign-up), [Duck DNS](https://www.duckdns.org/), [Dynu](https://www.dynu.com/ControlPanel/AddDDNS)) or your own domain and set it as the hostname (first line) in the `Caddyfile`.

### How do I allow multiple users, each with a unique login?
You'll need to append additional lines with a format of `basicauth / {USER} {PASS}` to the `Caddyfile`. Read [this](https://caddyserver.com/docs/basicauth) for more details.

### Why and how did you make this?
Why not? Made with [`rclone`](https://rclone.org/) + [`caddy`](https://caddyserver.com/)

### Why isn't there a Windows version?
Lack of personal interest. [Pull Requests](https://git.teknik.io/not-cdn/not-server/pulls) are welcome for a Batch or PowerShell version.
A simple alternative is to run both rclone and caddy as Windows services, using something like [NSSM](https://nssm.cc/usage) and pulling the required parameters for rclone/caddy from `start.sh`.

+ 63
- 0
setup.sh View File

@@ -0,0 +1,63 @@
#!/bin/bash

cat << "EOF"
__ .___
____ _____/ !_ ____ __! _/____
/ \ / _ \ __\ ______ _/ ___\ / __ |/ \
| | ( <_> ) | /_____/ \ \___/ /_/ | | \
|___| /\____/|__| \___ >____ |___| /
\/ \/ \/ \/
PRESENTS: not-server
.:| https://git.teknik.io/not-cdn/not-server |:.
EOF

# add current directory to PATH
# shellcheck disable=SC2155
export PATH=$PATH:$(pwd)

# check for rclone and valid configuration
if ! [ -x "$(command -v rclone)" ]
then
echo "ERROR: rclone binary not found in PATH or current folder"
echo "Install with: curl https://rclone.org/install.sh | sudo bash"
echo "or go to https://rclone.org/install/"
exit 1
fi

echo "Starting rclone, please configure a remote named cdn:"
rclone config --config rclone.conf

# check for caddy
if ! [ -x "$(command -v caddy)" ]
then
echo "caddy binary not found in PATH or current folder"
echo "Install with: curl https://getcaddy.com | bash -s personal"
echo "or go to https://caddyserver.com/download"
exit 1
fi

# set login credentials
USERNAME_DEFAULT="user"
read -r -p "Desired login username [$USERNAME_DEFAULT]: " USERNAME
USERNAME="${USERNAME:-$USERNAME_DEFAULT}"

PASSWORD_DEFAULT="letmein"
read -r -p "Desired login password [$PASSWORD_DEFAULT]: " PASSWORD
PASSWORD="${PASSWORD:-$PASSWORD_DEFAULT}"

sed -i -e "s/basicauth.*$/basicauth \/ $USERNAME $PASSWORD/" Caddyfile

echo "not-server setup complete!"
echo ""

# switch setup
echo "Configure Tinfoil / SX Installer (See README):"
echo -n "Host - "; curl ifconfig.co
echo -n "Port - "; head -1 Caddyfile | cut -d: -f2
echo "Username - $USERNAME"
echo "Password - $PASSWORD"
echo ""
echo "You can now use start.sh"

+ 50
- 0
start.sh View File

@@ -0,0 +1,50 @@
#!/bin/bash

# add current directory to PATH
# shellcheck disable=SC2155
export PATH=$PATH:$(pwd)

# check if already running
if [ -f .caddy.pid ]
then
echo "not-server is already running!"
exit 0
fi

# check for rclone and valid configuration
if ! [ -x "$(command -v rclone)" ]
then
echo "ERROR: rclone binary not found in PATH or current folder"
echo "Have you run setup.sh?"
exit 1
fi

if ! rclone listremotes --config rclone.conf | grep -q 'cdn:'
then
echo "ERROR: 'cdn:' remote not found in rclone.conf"
echo "Have you run setup.sh?"
exit 1
fi

# check for caddy
if ! [ -x "$(command -v caddy)" ]
then
echo "caddy binary not found in PATH or current folder"
echo "Have you run setup.sh?"
exit 1
fi

# start rclone
nohup rclone serve http cdn: \
--config rclone.conf \
--dir-cache-time 12h \
--read-only \
--log-file rclone.log \
--addr localhost:3018 > /dev/null 2>&1 &
echo $! > .rclone.pid

# start caddy
nohup caddy > /dev/null 2>&1 &
echo $! > .caddy.pid

echo "not-server started"

+ 12
- 0
stop.sh View File

@@ -0,0 +1,12 @@
#!/bin/bash

# shellcheck disable=SC2046
kill -9 $(cat .rclone.pid)

# shellcheck disable=SC2046
kill -9 $(cat .caddy.pid)

rm .rclone.pid
rm .caddy.pid

echo "not-server stopped"

Loading…
Cancel
Save