-
Notifications
You must be signed in to change notification settings - Fork 0
/
init
executable file
·152 lines (124 loc) · 3.56 KB
/
init
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
#!/bin/sh
CURWDIR="$(cd $(dirname $0) && pwd)"
ROOT=$CURWDIR
TITLE="PPTP-VPN"
PROGRAM_NAME="app-pptp"
PACKAGE="com.modouwifi.app-pptp"
APPS_CONFIG_DIR="/data/conf"
LAUNCHER_CONFIG_DIR="$APPS_CONFIG_DIR/launcher/conf.d"
LAUNCHER_CONFIG_FILE="$LAUNCHER_CONFIG_DIR/$PROGRAM_NAME.conf"
ICON="./res/normal.png"
PRESSED_ICON="./res/pressed.png"
SERVICE="$CURWDIR/sbin/service.sh"
OPTION_PPTP="$ROOT/data/option.pptp"
OPTION_USER="$ROOT/data/option.user"
OPTION_CONF="$ROOT/conf/option.conf"
PPTP_SO="$ROOT/bin/pptp.so"
TEMPLATE="$ROOT/conf/option.template"
DATA_JSON="$ROOT/conf/data.json"
PID_FILE="$CURWDIR/$PROGRAM_NAME.pid"
PKILL_BIN="/usr/bin/pkill"
INSTALL_BIN="/usr/bin/install"
REMOVE="/bin/rm -f"
usage() {
echo "ERROR: action missing"
echo "syntax: $0 <start|stop|restart|status|config|install|uninstall>"
echo "example: $0 start"
}
start() {
$SERVICE on
appInfo.sh set_status $PACKAGE ISRUNNING
json4sh.sh set $DATA_JSON state value true
}
stop() {
$SERVICE off
appInfo.sh set_status $PACKAGE NOTRUNNING
json4sh.sh set $DATA_JSON state value false
}
run() {
$SERVICE run &
}
sync_datajson_2_option_user() {
local SERVER=`json4sh.sh get $DATA_JSON server value`
local USERNAME=`json4sh.sh get $DATA_JSON user value`
local PASSWORD=`json4sh.sh get $DATA_JSON pass value`
rm $OPTION_USER
echo $SERVER > $OPTION_USER
echo $USERNAME >> $OPTION_USER
echo $PASSWORD >> $OPTION_USER
}
sync_option_user_2_datajson() {
local SERVER=`cat $OPTION_USER | head -n 1`
local USERNAME=`cat $OPTION_USER | head -n 2 | tail -n 1`
local PASSWORD=`cat $OPTION_USER | tail -n 1`
json4sh.sh set $DATA_JSON server value $SERVER
json4sh.sh set $DATA_JSON user value $USERNAME
json4sh.sh set $DATA_JSON pass value $PASSWORD
}
sync_option_user_2_option_pptp() {
local SERVER=`cat $OPTION_USER | head -n 1`
local USERNAME=`cat $OPTION_USER | head -n 2 | tail -n 1`
local PASSWORD=`cat $OPTION_USER | tail -n 1`
rm $OPTION_PPTP
echo "plugin $PPTP_SO" > $OPTION_PPTP
cat $TEMPLATE >> $OPTION_PPTP
echo -e "\n" >> $OPTION_PPTP
echo "user \"$USERNAME\"" >> $OPTION_PPTP
echo "password \"$PASSWORD\"" >> $OPTION_PPTP
echo "pptp_server $SERVER" >> $OPTION_PPTP
}
tp_config() {
$ROOT/bin/generate-config-file-2 $OPTION_CONF $OPTION_USER
if [ $? != 0 ]; then
exit 1
fi
sync_option_user_2_datajson ;
sync_option_user_2_option_pptp ;
}
set_config() {
sync_datajson_2_option_user ;
sync_option_user_2_option_pptp ;
local STATUS=`appInfo.sh get_status $PACKAGE`
}
install() {
echo "{" > "$PROGRAM_NAME.conf"
echo "\"name\" : \"$TITLE\"," >> "$PROGRAM_NAME.conf"
echo "\"icon\" : \"$CURWDIR/$ICON\"," >> "$PROGRAM_NAME.conf"
echo "\"iconPressed\" : \"$CURWDIR/$PRESSED_ICON\"," >> "$PROGRAM_NAME.conf"
echo "\"exec\" : \"$CURWDIR/init run\"," >> "$PROGRAM_NAME.conf"
echo "\"msgNum\" : 4" >> "$PROGRAM_NAME.conf"
echo "}" >> "$PROGRAM_NAME.conf"
$INSTALL_BIN -d $LAUNCHER_CONFIG_DIR
$INSTALL_BIN "$PROGRAM_NAME.conf" "$LAUNCHER_CONFIG_FILE"
sync_option_user_2_datajson ;
sync_option_user_2_option_pptp ;
}
uninstall() {
$REMOVE "$LAUNCHER_CONFIG_FILE"
}
# main
if [ $# -lt 1 ]; then
usage
exit 255
fi
case "$1" in
"start" )
start;;
"stop" )
stop;;
"restart" )
start
stop;;
"install" )
install;;
"uninstall" )
uninstall;;
"run" )
run;;
"set_config" )
set_config;;
"tp_config" )
tp_config;;
* )
usage ;;
esac