Last active
December 17, 2015 04:09
-
-
Save pads/5548896 to your computer and use it in GitHub Desktop.
A script to automate the bringing of one's domain over to tiddlyspace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This script writes a domain name to the Nginx aliases file | |
# and adds the corresponding tiddler to the MAPSPACE bag. | |
# Run ./byod.sh without any arguments for usage. | |
DOMAIN=$1 | |
TARGET_SPACE=$2 | |
WWW_DOMAIN=$3 | |
if [ "$TS_USER" = "" ]; then | |
TS_USER=tiddlyweb | |
fi | |
if [ "$NGINX_ALIASES_FILE" = "" ]; then | |
NGINX_ALIASES_FILE=/etc/nginx/tiddlyspace-aliases.conf | |
fi | |
if [ "$TS_HOME" = "" ]; then | |
TS_HOME=/home/tiddlyweb/tiddlywebs/tiddlyspace.com | |
fi | |
if [ $# -lt 2 ]; then | |
echo "Usage: `basename $0` domain target_space [www_domain]" | |
echo "* Override TS_USER to set the tiddlyspace user" | |
echo "** default: tiddlyweb" | |
echo "* Override NGINX_ALIAS_FILE to set the aliases configuration file" | |
echo "** default: /etc/nginx/tiddlyspace-aliases.conf" | |
echo "* Override TS_HOME to set the location of the tiddlyspace instance" | |
echo "** default: /home/tiddlyweb/tiddlywebs/tiddlyspace.com" | |
exit 1 | |
fi | |
create_tiddler() { | |
TITLE=$1 | |
SPACE=$2 | |
su $TS_USER -c "twanager tiddler MAPSPACE $TITLE <<EOF | |
mapped_space: $SPACE | |
EOF" | |
} | |
echo "Adding server alias to Nginx" | |
if [ "$WWW_DOMAIN" = "" ]; then | |
echo "server_name $DOMAIN;" >> $NGINX_ALIASES_FILE | |
else | |
echo "server_name $DOMAIN $WWW_DOMAIN;" >> $NGINX_ALIASES_FILE | |
fi | |
echo "Creating domain tiddler" | |
cd $TS_HOME | |
create_tiddler $DOMAIN $TARGET_SPACE | |
echo "Done" |
You neither need or want to create a WWW_DOMAIN tiddler, the rewrite rule at the top of the aliases file canonicalizes to a single hostname.
And you must have a ;
at the end of the server_name line.
Oh, also the mapped_space
field's attribute is the name of the target space. So if you're mapping thisispads.me.uk
to the pads
space then you want pads
in mapped space. As you've done it there is no mapping to any actual space.
Oh how embarrassing 😱 I totally didn't see that.
I saw in the aliases file that some domains had www additions so thought it might be useful but I'll drop it.
Hopefully the latest push should solve TiddlySpace/tiddlyspace#1037
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage:
./byod.sh thisispads.me.uk www.thisispads.me.uk
You will probably need to run it via
sudo
to write changes to the Nginx aliases file.