-
Notifications
You must be signed in to change notification settings - Fork 2
/
server-make
executable file
·57 lines (48 loc) · 1.48 KB
/
server-make
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
set -x
if [ $# -ne 1 ]
then
echo "Usage: ./server-make NAME"
echo
exit 1
fi
NAME="$1"
UUID="`uuid`"
ID="`echo "[content-hash $UUID]" | ./run -q`"
# TODO: random does only seem to yield values up to 250???
PORT=`random -e 500 ; echo "8000+$?" | bc`
URL="http://localhost:$PORT/"
TIME="`date -Ins`"
STATE="Servers/$ID-$NAME.state"
echo "NAME : $NAME"
echo "TIME : $TIME"
echo "UUID : $UUID"
echo "ID : $ID"
echo "PORT : $PORT"
echo "URL : $URL"
echo "STATE: $STATE"
grep -h data-route- Servers/* > tmp-all-routes.state
if [ -n "$(ls -A Servers)" ]
then
PARENT="`echo "[third [route-data $ID]]" | ./jml -q tmp-all-routes.state`"
PARENT_ID="`echo "[third [split - [route-id $ID]]]" | ./jml -q tmp-all-routes.state`"
PARENT_STATE="Servers/$PARENT_ID-$PARENT.state"
else
echo "-- %% NO parent - creating first, self routing! --"
PARENT=$NAME
PARENT_STATE=$STATE
fi
echo "PARENT : $PARENT"
echo "PARENT_STATE: $PARENT_STATE"
# - add yourself to your PARENT
touch $PARENT_STATE
echo "[macro data-route-$ID]$URL $TIME $NAME ...[/macro]" >> $PARENT_STATE
# - add to the new server
touch $STATE
echo "[-- $TIME @ `hostname`: Server $NAME created based on $PARENT--]" >> $STATE
echo "[macro /jml-id]$ID[/macro]" >> $STATE
echo "[macro /jml-name]$NAME[/macro]" >> $STATE
echo "[macro /jml-url]$URL[/macro]" >> $STATE
# - inherit routes from PARENT, including our own route/id
grep -h data-route- $PARENT_STATE | cat >> $STATE
echo "-- STATE OF SERVER: $NAME WITH ID: $ID --"
cat $STATE