forked from bolidozor/js9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkhelper
executable file
·157 lines (133 loc) · 3.95 KB
/
mkhelper
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
# set -x
# get helper type
if [ x"$1" != x ]; then
HELPER="$1"
shift
else
echo "no helper type specified"
exit 1
fi
case "$HELPER" in
none)
# js9Prefs.json: preference file
IPREFS=js9Prefs.json
OPREFS=js9Prefs-none.json
echo "Editing $IPREFS for no helper ..."
sed 's#\("helperType" *:.*"\)[^"]*\("\)#\1none\2#' < $IPREFS > $OPREFS && mv $IPREFS{,-orig} && mv $OPREFS $IPREFS
;;
nodejs|socket.io)
# js9Prefs.json: preference file
IPREFS=js9Prefs.json
OPREFS=js9Prefs-nodejs.json
echo "Editing $IPREFS for Node.js helper ..."
sed 's#\("helperType" *:.*"\)[^"]*\("\)#\1nodejs\2#' < $IPREFS > $OPREFS && mv $IPREFS{,-orig} && mv $OPREFS $IPREFS
;;
get|post)
if [ x"$1" != x ]; then
CGIDIR="$1"
shift
else
echo "CGI install directory not configured"
exit 1
fi
if [ x"$1" != x ]; then
CGIURL="$1"
shift
fi
if [ x"$1" != x ]; then
CGIXPATH="$1"
shift
fi
# js9Prefs.json: preference file
if [ x"$1" != x ]; then
IPREFS="$1"
shift
else
IPREFS=js9Prefs.json
fi
OPREFS=js9Prefs-cgi.json
# js9Prefs.cgi: CGI helper script
ICGISCR="js9Helper-default.cgi"
OCGISCR="js9Helper.cgi"
# temp
myplugins="./analysis-plugins"
echo "Editing $IPREFS for CGI ($HELPER) helper ..."
jroot=`egrep "WEBDIR *=" Makefile | awk '{print $3}' | sed 's/^[ ]*//;s/[ ]*$//'`
if [ x"$jroot" != x ]; then
X="$X;s#^JROOT=\".*\"#JROOT=\"$jroot\"#"
fi
jprefix=`egrep "^prefix *=" Makefile | awk '{print $3}' | sed 's/^[ ]*//;s/[ ]*$//'`
if [ x"$jprefix" != x ]; then
jbin="$jprefix/bin"
fi
if [ x"$jbin" != x ]; then
X="$X;s#^JBIN=\".*\"#JBIN=\"$jbin\"#"
fi
jworkdir=`egrep '"workDir" *:' $IPREFS | awk -F: '{print $NF}' |sed 's/"//g' | sed 's/^[ ]*//;s/[,} ]*$//'`
if [ x"$jworkdir" != x ]; then
X="$X;s#^JWORKDIR=\".*\"#JWORKDIR=\"$jworkdir\"#"
fi
jloadproxy=`egrep '"loadProxy" *:' $IPREFS | awk -F: '{print $NF}' |sed 's/"//g' | sed 's/^[ ]*//;s/[,} ]*$//'`
if [ x"$jloadproxy" != x ]; then
X="$X;s#^JLOADPROXY=\".*\"#JLOADPROXY=\"$jloadproxy\"#"
fi
jwrappers=`egrep '"analysisWrappers" *:' $IPREFS | awk -F: '{print $NF}' |sed 's/"//g' | sed 's/^[ ]*//;s/[,} ]*$//'`
if [ x"$jwrappers" != x ]; then
if [ x${jwrappers:0:1} != "x/" ]; then
jwrappers="${jroot}/${jwrappers}"
fi
X="$X;s#^JWRAPPERS=\".*\"#JWRAPPERS=\"$jwrappers\"#"
fi
jplugins=`egrep '"analysisPlugins" *:' $IPREFS | awk -F: '{print $NF}' | sed 's/"//g' | sed 's/^[ ]*//;s/[,} ]*$//'`
if [ x"$jplugins" != x ]; then
if [ x${jplugins:0:1} != "x/" ]; then
jplugins="${jroot}/${jplugins}"
fi
X="$X;s#^JPLUGINS=\".*\"#JPLUGINS=\"$jplugins\"#"
if [ -d "$myplugins" -a -f "$myplugins/fits2png.json" ]; then
jfits2png=`egrep '"action" *:' $myplugins/fits2png.json | awk -F: '{print $NF}' | sed 's/"//g' | sed 's/^[ ]*//;s/[,} ]*$//'`
if [ x"$jfits2png" != x ]; then
X="$X;s#^JFITS2PNG=\".*\"#JFITS2PNG=\"$jfits2png\"#"
fi
fi
fi
jdatapath=`egrep '"dataPath" *:' $IPREFS | \
awk -F: '
{
for(i=2; i<=NF; i++){
if( X != "" ){
X = X ":"
}
X = X $i
}
}
END{
print X
}' | \
sed 's/"//g' | sed 's/^[ ]*//;s/[,} ]*$//'`
if [ x"$jdatapath" != x ]; then
# expand $HOME so that we can specify $HOME/Desktop, etc.
jdatapath=`echo $jdatapath | sed 's#\$HOME#'$HOME'#g'`
X="$X;s#^JDATAPATH=\".*\"#JDATAPATH=\"$jdatapath\"#"
fi
if [ x"$CGIXPATH" != x ]; then
X="$X;s#^JXPATH=\".*\"#JXPATH=\"$CGIXPATH\"#"
fi
echo "Creating $OCGISCR ..."
sed "$X" < $ICGISCR > $OCGISCR
chmod +x $OCGISCR
# if CGIURL was not specified or was specified as the default, use the prefs val
if [ x"$CGIURL" = x ]; then
CGIURL=`egrep '"helperCGI" *:' $IPREFS | awk -F: '{print $NF}' | sed 's/"//g' | sed 's/^[ ]*//;s/[,} ]*$//'`
if [ x"$CGIURL" != x ]; then
if [ x${CGIURL:0:1} != "x/" ]; then
CGIURL="${jroot}/${CGIURL}"
fi
fi
fi
echo "Editing $IPREFS for CGI ..."
sed 's#\("helperCGI" *:.*"\)[^"]*\("\)#\1'"$CGIURL"'/js9Helper.cgi\2#;s#\("helperType":.*"\)[^"]*\("\)#\1get\2#' < $IPREFS > $OPREFS && mv $IPREFS{,-orig} && mv $OPREFS $IPREFS
;;
esac
exit 0