diff --git a/INSTALL.md b/INSTALL.md index cf5c950..c633d69 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -19,18 +19,19 @@ Pre-requisites: * You own a domain * through Daplie Domains * or you understand domains and DNS and all that stuff +* Install bower `npm install -g bower` Choose a domain --------------- -For the purpose of this instruction we'll assume that your domain is `example.com`, +For the purpose of this instruction we'll assume that your domain is `foo.com`, but you can use, say, `johndoe.daplie.me` for testing through Daplie Domains. Anyway, go ahead and set the bash variable `$my_domain` for the purposes of the rest of this tutorial: ``` -my_domain=example.com +my_domain=foo.com ``` You can purchase a domain with daplie tools @@ -47,17 +48,17 @@ Subdomains Auth will be loaded with the following domains ``` -provider.example.com -api.provider.example.com +provider.foo.com +api.provider.foo.com ``` The Hello World app will be loaded with the following domains ``` -example.com -www.example.com -api.example.com -assets.example.com +foo.com +www.foo.com +api.foo.com +assets.foo.com ``` The domains can be setup through the Daplie Desktop App or with daplie-tools @@ -69,6 +70,9 @@ Replace `foodevice` with whatever you like to call this device my_device=foodevice # curl https://api.oauth3.org/api/tunnel@oauth3.org/checkip +# READ THIS: localhost is being used as an example. +# Your IP address should be public facing (i.e. port-forwarding is enabled on your router). +# If it isn't, then you need something like goldilocks providing a tunnel. my_address=127.0.0.1 # set device address and attach primary domain @@ -92,7 +96,7 @@ Walnut must sit behind a proxy that properly terminates https and sets the `X-Fo Goldilocks can do this, as well as manage daplie domains, tunneling, etc. ```bash -curl https://daplie.me/install-scripts | bash +curl https://git.daplie.com/Daplie/daplie-snippets/raw/master/install.sh | bash daplie-install-goldilocks ``` @@ -101,16 +105,16 @@ daplie-install-goldilocks Example `/etc/goldilocks/goldilocks.yml`: ```yml tls: - email: domains@example.com + email: user@mailservice.com servernames: - - example.com - - www.example.com - - api.example.com - - assets.example.com - - cloud.example.com - - api.cloud.example.com - - provider.example.com - - api.provider.example.com + - foo.com + - www.foo.com + - api.foo.com + - assets.foo.com + - cloud.foo.com + - api.cloud.foo.com + - provider.foo.com + - api.provider.foo.com http: trust_proxy: true @@ -125,7 +129,7 @@ Basic Walnut Install -------------------- ```bash -curl https://daplie.me/install-scripts | bash +curl https://git.daplie.com/Daplie/daplie-snippets/raw/master/install.sh | bash daplie-install-walnut ``` @@ -162,8 +166,8 @@ Resetting the Initialization Once you run the app the initialization files will appear in these locations ``` -/srv/walnut/var/com.daplie.walnut.config.sqlite3 -/srv/walnut/config//config.json +/srv/walnut/var/walnut+config@daplie.com.sqlite3 +/srv/walnut/config/foo.com.json ``` Deleting those files and restarting walnut will reset it to its bootstrap state. @@ -188,7 +192,7 @@ For the APIs for that we'll install the `issuer@oauth3.org` API package and enab ```bash # API packaged for walnut -git clone https://git.daplie.com/OAuth3/org.oauth3.provider.git /srv/walnut/packages/rest/issuer@oauth3.org +git clone https://git.daplie.com/OAuth3/issuer_oauth3.org.git /srv/walnut/packages/rest/issuer@oauth3.org pushd /srv/walnut/packages/rest/issuer@oauth3.org/ git checkout v1.2 npm install @@ -224,13 +228,13 @@ It is intended to provide a way to use various mail services in the future, just bear with us for the time being (or open a Merge Request). ```bash -vim /srv/walnut/var/$my_domain/config.json +mkdir -p /srv/walnut/var/provider.$my_domain +vim /srv/walnut/var/provider.$my_domain/config.json ``` ```json { "mailgun.org": { "apiKey": "key-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - , "apiPublicKey": "pubkey-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" , "auth": { "user": "robtherobot@example.com" , "pass": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" @@ -266,8 +270,9 @@ What it should look like: models.js rest.js -/srv/walnut/packages/client-api-grants/example.com +/srv/walnut/packages/client-api-grants/provider.foo.com ''' + issuer@oauth3.org hello@example.com ''' ``` diff --git a/README.md b/README.md index a9d1172..1a7abff 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,19 @@ We're still in a stage where the installation generally requires many manual ste See [INSTALL.md](/INSTALL.md) +Usage +----- + +Here's how you run the thing, once installed: + +``` +/opt/walnut/bin/node /srv/walnut/core/bin/walnut.js +``` + +It listens on all addresses, port 3000. + +TODO: Add config to restrict listening to localhost. + API --- diff --git a/dist/etc/systemd/system/walnut.service b/dist/etc/systemd/system/walnut.service index 5f20e71..517da9c 100644 --- a/dist/etc/systemd/system/walnut.service +++ b/dist/etc/systemd/system/walnut.service @@ -27,7 +27,7 @@ Group=www-data # Set a sane working directory, sane flags, and specify how to reload the config file WorkingDirectory=/srv/www -ExecStart=/usr/local/bin/node /srv/walnut/core/bin/walnut.js --config=/etc/walnut/walnut.yml +ExecStart=/opt/walnut/bin/node /srv/walnut/core/bin/walnut.js --config=/etc/walnut/walnut.yml ExecReload=/bin/kill -USR1 $MAINPID # Limit the number of file descriptors and processes; see `man systemd.exec` for more limit settings. diff --git a/install-helper.sh b/install-helper.sh index 2008c61..3d64f46 100755 --- a/install-helper.sh +++ b/install-helper.sh @@ -249,7 +249,6 @@ install_my_app() ln -sf ../node_modules /srv/walnut/core/node_modules mkdir -p /srv/walnut/var/sites mkdir -p /srv/walnut/etc/org.oauth3.consumer - mkdir -p /srv/walnut/etc/org.oauth3.provider mkdir -p /srv/walnut/etc/client-api-grants mkdir -p /srv/walnut/packages/{rest,api,pages,services} @@ -264,11 +263,13 @@ install_my_app() if [ ! -d "./.git/" ]; then echo "'/srv/walnut/core/lib/walnut@daplie.com/setup' exists but is not a git repository... not sure what to do here..." fi - git checkout v1 + git checkout master git pull popd pushd /srv/walnut/core + export NODE_PATH=/opt/walnut/lib/node_modules + export NPM_CONFIG_PREFIX=/opt/walnut /opt/walnut/bin/npm install popd } diff --git a/install.sh b/install.sh index 33d8948..aad12e6 100644 --- a/install.sh +++ b/install.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Not every platform has or needs sudo, gotta save them O(1)s... +sudo_cmd="" +((EUID)) && [[ -z "$ANDROID_ROOT" ]] && sudo_cmd="sudo" + set -e set -u @@ -54,9 +58,9 @@ detect_http_get install_walnut() { - sudo mkdir -p /srv/walnut/{var,etc,packages,node_modules} + $sudo_cmd mkdir -p /srv/walnut/{var,etc,packages,node_modules} # www-data exists on linux, _www exists on mac OS - sudo chown -R $(whoami):www-data /srv/walnut || sudo chown -R $(whoami):_www /srv/walnut + $sudo_cmd chown -R $(whoami):www-data /srv/walnut || $sudo_cmd chown -R $(whoami):_www /srv/walnut if [ ! -d "/srv/walnut/core/" ]; then git clone https://git.daplie.com/Daplie/walnut.js.git /srv/walnut/core fi @@ -64,7 +68,7 @@ install_walnut() if [ ! -d "./.git/" ]; then echo "'/srv/walnut/core' exists but is not a git repository... not sure what to do here..." fi - git checkout v1 + git checkout master git pull popd rm -rf /srv/walnut/core/node_modules @@ -72,20 +76,37 @@ install_walnut() /srv/walnut/core/install-helper.sh /srv/walnut # Now that the install is finished we need to set the owner to the user that will actually # be running the walnut server. - sudo chown -R www-data:www-data /srv/walnut || sudo chown -R _www:_www /srv/walnut -} + $sudo_cmd chown -R www-data:www-data /srv/walnut || $sudo_cmd chown -R _www:_www /srv/walnut +} # Install node +echo "----Installing Nodejs and NPM----" echo "v8.2.1" > /tmp/NODEJS_VER daplie-install-node-dev npm install -g npm@4 # Install goldilocks +echo "----Installing goldilocks.js----" daplie-install-goldilocks +echo "----Installing walnut.js----" +#$sudo_cmd mkdir -p /opt/goldilocks/{lib,bin,etc} +#export NODE_PATH=/opt/walnut/lib/node_modules +#export NPM_CONFIG_PREFIX=/opt/walnut +old_PATH=$PATH +export PATH=/opt/walnut/bin:$PATH + # Install walnut install_walnut +# Install bower, some systems may be missing it, and it is a dependency +/opt/walnut/bin/npm install -g bower +touch /.bowerrc +echo '{ "allow_root": true }' > /.bowerrc + +# Restore PATH to original value +export PATH=$old_PATH + echo "" echo "You must have some set of domain set up to properly use goldilocks+walnut:" echo "" diff --git a/package.json b/package.json index 7f8f644..8cfb406 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "connect-cors": "0.5.x", "connect-recase": "^1.0.2", "connect-send-error": "1.x", + "cookie-parser": "^1.4.3", "escape-html": "^1.0.2", "escape-string-regexp": "1.x", "express": "4.x", @@ -62,7 +63,9 @@ "nodemailer": "^1.4.0", "nodemailer-mailgun-transport": "1.x", "oauth3.js": "git+https://git.daplie.com/OAuth3/oauth3.js.git", + "recase": "^1.0.4", "request": "^2.81.0", + "scmp": "^2.0.0", "serve-static": "1.x", "sqlite3-cluster": "git+https://git.daplie.com/coolaj86/sqlite3-cluster.git#v2", "stripe": "^4.22.0",