Since the bootstrap file is small, just generate it directly

This commit is contained in:
Bob Mottram 2018-04-10 10:24:59 +01:00
parent 0dcf17b375
commit 33ae6d4444
1 changed files with 28 additions and 51 deletions

View File

@ -46,12 +46,12 @@ DATSERVER_PORT=3282
# bootstrap servers are specified here # bootstrap servers are specified here
DATSERVER_BOOTSTRAP_FILE=$DATSERVER_DIRECTORY/node_modules/datland-swarm-defaults/index.js DATSERVER_BOOTSTRAP_FILE=$DATSERVER_DIRECTORY/node_modules/datland-swarm-defaults/index.js
DATSERVER_DISCOVERY1= DATSERVER_DISCOVERY1='discovery1.publicbits.org'
DATSERVER_DISCOVERY2= DATSERVER_DISCOVERY2='discovery2.publicbits.org'
DATSERVER_BOOTSTRAP1= DATSERVER_BOOTSTRAP1='bootstrap1.publicbits.org:6881'
DATSERVER_BOOTSTRAP2= DATSERVER_BOOTSTRAP2='bootstrap2.publicbits.org:6881'
DATSERVER_BOOTSTRAP3= DATSERVER_BOOTSTRAP3='bootstrap3.publicbits.org:6881'
DATSERVER_BOOTSTRAP4= DATSERVER_BOOTSTRAP4='bootstrap4.publicbits.org:6881'
datserver_variables=(MY_USERNAME datserver_variables=(MY_USERNAME
DATSERVER_DISCOVERY1 DATSERVER_DISCOVERY1
@ -61,52 +61,29 @@ datserver_variables=(MY_USERNAME
DATSERVER_BOOTSTRAP3 DATSERVER_BOOTSTRAP3
DATSERVER_BOOTSTRAP4) DATSERVER_BOOTSTRAP4)
function datserver_add_discovery_domain {
server_domain="$1"
if [ ! "$server_domain" ]; then
return
fi
if [ ${#server_domain} -lt 4 ]; then
return
fi
if grep -q "$server_domain" $DATSERVER_BOOTSTRAP_FILE; then
return
fi
sed -i "/var DEFAULT_DISCOVERY/a '$server_domain'," $DATSERVER_BOOTSTRAP_FILE
sed -i "s|'$server_domain',| '$server_domain',|g" $DATSERVER_BOOTSTRAP_FILE
}
function datserver_add_bootstrap {
boostrap_server="$1"
if [ ! "$boostrap_server" ]; then
return
fi
if [ ${#boostrap_server} -lt 4 ]; then
return
fi
if grep -q "$boostrap_server" $DATSERVER_BOOTSTRAP_FILE; then
return
fi
sed -i "/var DEFAULT_BOOTSTRAP/a '$boostrap_server'," $DATSERVER_BOOTSTRAP_FILE
sed -i "s|'$boostrap_server',| '$boostrap_server',|g" $DATSERVER_BOOTSTRAP_FILE
}
function datserver_generate_bootstraps { function datserver_generate_bootstraps {
datserver_add_discovery_domain "$DATSERVER_DISCOVERY1" { echo "var extend = require('xtend')";
datserver_add_discovery_domain "$DATSERVER_DISCOVERY2" echo '';
echo "var DAT_DOMAIN = 'dat.local'";
datserver_add_bootstrap "$DATSERVER_BOOTSTRAP1" echo 'var DEFAULT_DISCOVERY = [';
datserver_add_bootstrap "$DATSERVER_BOOTSTRAP2" echo " '$DATSERVER_DISCOVERY1',";
datserver_add_bootstrap "$DATSERVER_BOOTSTRAP3" echo " '$DATSERVER_DISCOVERY2'";
datserver_add_bootstrap "$DATSERVER_BOOTSTRAP4" echo ']';
echo 'var DEFAULT_BOOTSTRAP = [';
echo " '$DATSERVER_BOOTSTRAP1',";
echo " '$DATSERVER_BOOTSTRAP2',";
echo " '$DATSERVER_BOOTSTRAP3',";
echo " '$DATSERVER_BOOTSTRAP4'";
echo ']';
echo '';
echo 'var DEFAULT_OPTS = {';
echo ' dns: {server: DEFAULT_DISCOVERY, domain: DAT_DOMAIN},';
echo ' dht: {bootstrap: DEFAULT_BOOTSTRAP}';
echo '}';
echo '';
echo 'module.exports = function (opts) {';
echo ' return extend(DEFAULT_OPTS, opts) // opts takes priority';
echo '}'; } > $DATSERVER_BOOTSTRAP_FILE
} }
function logging_on_datserver { function logging_on_datserver {