slapos-configure.sh 21.3 KB
Newer Older
1 2
#! /bin/bash
#
3 4
# This script need root rights. Before run it, make sure you have root
# right.
5
#
6 7
# It used to configure slapos node, it could be run at anytime to
# check the configure of slapos node. The main functions:
8
#
9
#     * Install msloop network adapter, named to re6stnet-lo
10
#
Jondy Zhao's avatar
Jondy Zhao committed
11
#     * Check IPv6 protocol and install it if require
12
#
13 14
#     * Create user slaproot who owns Administrator group rights
#
Jondy Zhao's avatar
Jondy Zhao committed
15
#     * Configure and start cygwin service: cygserver, syslog-ng, sshd
16
#
Jondy Zhao's avatar
Jondy Zhao committed
17
#     * config: Create node and client configure file by parameters ca/key
18
#
Jondy Zhao's avatar
Jondy Zhao committed
19
#     * re6stnet: Install re6stnet and register to nexedi re6stnet if required
20
#
21
#     * cron: create cron configure file
22
#
23 24
#     * startup: add this script as startup item
#
25 26
# Usage:
#
Jondy Zhao's avatar
Jondy Zhao committed
27 28
#    ./slapos-configure [--install | --query | --overwrite | --uninstall]
#                       [ * | re6stnet | taps | config | cron | startup | runner]
29
#
Jondy Zhao's avatar
Jondy Zhao committed
30
#    The action option:
31
#
Jondy Zhao's avatar
Jondy Zhao committed
32 33 34 35
#        --install      Install only when the item hasn't been installed
#        --query        Interactive to install all the item
#        --overwite     Overwrite the item even it has been installed
#        --uninstall    Remove the configure item
36
#
Jondy Zhao's avatar
Jondy Zhao committed
37
#    Default is --install
38
#
Jondy Zhao's avatar
Jondy Zhao committed
39
#    The configure item option:
40
#
Jondy Zhao's avatar
Jondy Zhao committed
41 42 43 44 45 46
#        *              All the configure item
#        re6stnet       Install re6stent and dependencies
#        taps           Install OpenVPN Tap-Windows Driver for re6stnet
#        config         Generate slapos node and client configure files
#        cron           Generate cron file and start cron job
#        runner         Install web runner for this node
47
#
48
source $(/usr/bin/dirname $0)/slapos-include.sh
49

50 51 52 53
echo
echo Start slapos node configure ...
echo

Jondy Zhao's avatar
Jondy Zhao committed
54 55
if [[ ! ":$PATH" == :/opt/slapos/bin: ]] ; then
    for profile in ~/.bash_profile ~/.profile ; do
56 57
        grep -q "export PATH=/opt/slapos/bin:" $profile ||
        echo "export PATH=/opt/slapos/bin:\${PATH}" >> $profile
58
    done
Jondy Zhao's avatar
Jondy Zhao committed
59
fi
60

Jondy Zhao's avatar
Jondy Zhao committed
61
# cygrunsrv
62 63
# ssh-host-config
# syslog-ng-config
Jondy Zhao's avatar
Jondy Zhao committed
64 65
# openssl
# export WINDIR
66
# ipwin
Jondy Zhao's avatar
Jondy Zhao committed
67
# slapos_cron_config
68

Jondy Zhao's avatar
Jondy Zhao committed
69
# -----------------------------------------------------------
70
# Create paths
Jondy Zhao's avatar
Jondy Zhao committed
71
# -----------------------------------------------------------
72 73
mkdir -p /etc/opt/slapos/ssl/partition_pki
mkdir -p $slapos_client_home
Jondy Zhao's avatar
Jondy Zhao committed
74
mkdir -p /opt/slapos/log
75 76
mkdir -p /opt/download-cache
mkdir -p /opt/downloads
Jondy Zhao's avatar
Jondy Zhao committed
77 78
mkdir -p /etc/slapos/scripts
mkdir -p /etc/re6stnet
79

Jondy Zhao's avatar
Jondy Zhao committed
80
# -----------------------------------------------------------
81 82
# Create account: slaproot
# -----------------------------------------------------------
83
# Start seclogon service in the Windows XP
84 85 86 87
if csih_is_xp ; then
    echo "Set start property of seclogon to auto"
    sc config seclogon start= auto || 
    csih_warning "Warning: failed to set seclogon to auto start."
88
# In the later, it's RunAs service, and will start by default
89
fi
90

Jondy Zhao's avatar
Jondy Zhao committed
91 92
# echo Checking slapos account $slapos_admin ...
slapos_check_and_create_privileged_user $slapos_admin ||
93
csih_error "Failed to create account $slapos_admin."
Jondy Zhao's avatar
Jondy Zhao committed
94

95
# -----------------------------------------------------------
Jondy Zhao's avatar
Jondy Zhao committed
96 97 98 99 100
# Configure cygwin services: cygserver syslog-ng sshd
# -----------------------------------------------------------
echo
echo Starting configure cygwin services ...
echo
101
if ! cygrunsrv --query cygserver > /dev/null 2>&1 ; then
102 103
    echo Run cygserver-config ...
    /usr/bin/cygserver-config --yes || \
104
        csih_error "Failed to run cygserver-config"
105 106 107
else
    echo The cygserver service has been installed.
fi
108
check_cygwin_service cygserver
109

110
if ! cygrunsrv --query syslog-ng > /dev/null 2>&1 ; then
111 112
    echo Run syslog-ng-config ...
    /usr/bin/syslog-ng-config --yes || \
113
        csih_error "Failed to run syslog-ng-config"
114 115 116
else
    echo The syslog-ng service has been installed.
fi
117 118
check_cygwin_service syslog-ng

119
if ! cygrunsrv --query sshd > /dev/null 2>&1 ; then
120
    if csih_is_xp && [[ -z "${csih_PRIVILEGED_PASSWORD}" ]] ; then
Jondy Zhao's avatar
Jondy Zhao committed
121 122
        slapos_request_password $slapos_admin "Install sshd service need the password of $slapos_admin."
    fi
123
    echo Run ssh-host-config ...
124
    /usr/bin/ssh-host-config --yes --cygwin ntsec \
125 126
        --user $slapos_admin --pwd ${csih_PRIVILEGED_PASSWORD} ||
    csih_error "Failed to run ssh-host-config"
127 128 129 130 131
else
    echo The sshd service has been installed.
fi
check_cygwin_service sshd

Jondy Zhao's avatar
Jondy Zhao committed
132
# Use slapos-cron-config to configure slapos cron service. 
133
if ! cygrunsrv --query cron > /dev/null 2>&1 ; then
Jondy Zhao's avatar
Jondy Zhao committed
134
    [[ -x $slapos_cron_config ]] ||
135
    csih_error "Couldn't find slapos cron config script: $slapos_cron_config"
Jondy Zhao's avatar
Jondy Zhao committed
136

137
    if [[ -z "${csih_PRIVILEGED_PASSWORD}" ]] ; then
Jondy Zhao's avatar
Jondy Zhao committed
138
        slapos_request_password $slapos_admin "Install cron service need the password of $slapos_admin."
139
    fi
Jondy Zhao's avatar
Jondy Zhao committed
140 141

    echo Run slapos-cron-config ...
142 143
    $slapos_cron_config $slapos_admin ${csih_PRIVILEGED_PASSWORD} ||
    csih_error "Failed to run $slapos_cron_config"
144 145 146 147 148
else
    echo The cron service has been installed.
fi
check_cygwin_service cron

Jondy Zhao's avatar
Jondy Zhao committed
149 150 151
echo
echo Configure cygwin services OK.
echo
152

Jondy Zhao's avatar
Jondy Zhao committed
153 154 155 156 157 158
# -----------------------------------------------------------
# Install network connection used by slapos node
# -----------------------------------------------------------
echo
echo Starting configure slapos network ...
echo
159
if ! netsh interface ipv6 show interface | grep -q "\\b$slapos_ifname\\b" ; then
160
    echo Installing slapos network adapter ...
161
    ipwin install $WINDIR\\inf\\netloop.inf *msloop re6stnet-lo
162
fi
163
ip -4 addr add $ipv4_local_network dev $slapos_ifname
164
# reset_connection $slapos_ifname
Jondy Zhao's avatar
Jondy Zhao committed
165 166 167 168 169 170 171 172 173 174 175 176
echo
echo Configure slapos network OK.
echo

# -----------------------------------------------------------
# Check IPv6 protocol, install it if it isn't installed
# -----------------------------------------------------------
echo
echo Starting configure IPv6 protocol ...
echo
netsh interface ipv6 show interface > /dev/null || \
    netsh interface ipv6 install || \
177
    csih_error "Failed to install IPv6 protocol."
Jondy Zhao's avatar
Jondy Zhao committed
178 179 180
echo
echo Configure IPv6 protocol OK.
echo
181

Jondy Zhao's avatar
Jondy Zhao committed
182 183 184 185 186 187 188 189
# -----------------------------------------------------------
# config: Generate slapos node and client configure file
# -----------------------------------------------------------
echo
echo Starting configure section config ...
echo
[[ -r $node_template_file && -r $client_template_file ]] || \
    create_template_configure_file || \
190
    csih_error "Failed to create template configure file."
191 192

if [[ ! -f $node_certificate_file ]] ; then
193
    read -p "Where is computer certificate file $(cygpath -w /computer.crt): " filename
194
    [[ -z "$filename" ]] && filename="/computer.crt"
Jondy Zhao's avatar
Jondy Zhao committed
195
    [[ ! -r "$filename" ]] && \
196
        csih_error "Computer certificate file $filename doesn't exists."
Jondy Zhao's avatar
Jondy Zhao committed
197 198 199
    echo "Copy certificate from $filename to $node_certificate_file"
    filename=$(cygpath -u $filename)
    cp $filename $node_certificate_file
200
else
Jondy Zhao's avatar
Jondy Zhao committed
201
    echo "Found computer certificate file: $node_certificate_file"
202
fi
203
openssl x509 -noout -in $node_certificate_file || \
204
    csih_error "Invalid computer certificate: $node_certificate_file."
205 206

if [[ ! -f $node_key_file ]] ; then
207
    read -p "Where is computer key file $(cygpath -w /computer.key): " filename
208
    [[ -z "$filename" ]] && filename="/computer.key"
Jondy Zhao's avatar
Jondy Zhao committed
209
    [[ ! -f "$filename" ]] && \
210
        csih_error "Key file $filename doesn't exists."
Jondy Zhao's avatar
Jondy Zhao committed
211 212 213
    echo "Copy key from $filename to $node_key_file"
    filename=$(cygpath -u $filename)
    cp $filename $node_key_file
214
else
Jondy Zhao's avatar
Jondy Zhao committed
215
    echo "Found computer key file: $node_key_file"
216
fi
217
openssl rsa -noout -in $node_key_file -check ||
218
csih_error "Invalid node key: $node_key_file."
219

220 221 222
if [[ ! -f $node_configure_file ]] ; then
    echo "Copy computer configure file from $node_template_file to $node_configure_file"
    cp $node_template_file $node_configure_file
223 224
fi

225
interface_guid=$(ipwin guid *msloop $slapos_ifname) ||
226
csih_error "Failed to get guid of interface: $slapos_ifname."
227
[[ "$interface_guid" == {*-*-*-*} ]] ||
228
csih_error "Invalid interface guid $interface_guid specified."
229

Jondy Zhao's avatar
Jondy Zhao committed
230 231
computer_guid=$(grep "CN=COMP" $node_certificate_file | \
    sed -e "s/^.*, CN=//g" | sed -e "s%/emailAddress.*\$%%g")
232
[[ "$computer_guid" == COMP-+([0-9]) ]] ||
233
csih_error "Invalid computer id '$computer_guid' specified."
Jondy Zhao's avatar
Jondy Zhao committed
234

235 236 237 238
echo "Computer configuration information:"
echo "  interface name:     $slapos_ifname"
echo "  GUID:               $interface_guid"
echo "  ipv4_local_network: $ipv4_local_network"
Jondy Zhao's avatar
Jondy Zhao committed
239
echo "  computer_id:        $computer_guid"
240
echo
241 242 243 244 245
echo "  If ipv4_local_network confilcts with your local network, change it"
echo "  in the file: $node_configure_file "
echo "  Or change it in the $(dirname $0)/slapos-include.sh"
echo "  and run Configure SlapOS again."

246 247 248
sed -i  -e "s%^\\s*interface_name.*$%interface_name = $interface_guid%" \
        -e "s%^#\?\\s*ipv6_interface.*$%# ipv6_interface =%g" \
        -e "s%^ipv4_local_network.*$%ipv4_local_network = $ipv4_local_network%" \
Jondy Zhao's avatar
Jondy Zhao committed
249
        -e "s%^computer_id.*$%computer_id = $computer_guid%" \
250
        $node_configure_file
251 252

if [[ ! -f $client_certificate_file ]] ; then
253
    read -p "Where is client certificate file $(cygpath -w /certificate): " filename
254
    [[ -z "$filename" ]] && filename="/certificate"
Jondy Zhao's avatar
Jondy Zhao committed
255
    [[ ! -f "$filename" ]] && \
256
        csih_error "Client certificate file $filename doesn't exists."
Jondy Zhao's avatar
Jondy Zhao committed
257
    echo "Copy client certificate from $filename to $client_certificate_file"
258
    filename=$(cygpath -u $filename)
Jondy Zhao's avatar
Jondy Zhao committed
259
    cp $filename $client_certificate_file
260
fi
261
openssl x509 -noout -in $client_certificate_file || \
262
    csih_error "Invalid client certificate: $client_certificate_file."
263 264

if [[ ! -f $client_key_file ]] ; then
265
    read -p "Where is client key file $(cygpath -w /key): " filename
266
    [[ -z "$filename" ]] && filename="/key"
Jondy Zhao's avatar
Jondy Zhao committed
267
    [[ ! -f "$filename" ]] && \
268
        csih_error "Key file $filename doesn't exists."
Jondy Zhao's avatar
Jondy Zhao committed
269
    echo "Copy client key from $filename to $client_key_file"
270
    filename=$(cygpath -u $filename)
Jondy Zhao's avatar
Jondy Zhao committed
271
    cp $filename $client_key_file
272
fi
273
openssl rsa -noout -in $client_key_file -check || \
274
    csih_error "Invalid client key: $client_key_file."
275 276

if [[ ! -f $client_configure_file ]] ; then
277 278
    echo "Copy client configure file from $client_template_file to $client_configure_file"
    cp $client_template_file $client_configure_file
279 280
fi

Jondy Zhao's avatar
Jondy Zhao committed
281 282 283
echo "Client configuration information:"
echo "   client certificate file: $client_certificate_file"
echo "   client key file:         $client_key_file"
284 285 286
sed -i -e "s%^cert_file.*$%cert_file = $client_certificate_file%" \
       -e "s%^key_file.*$%key_file = $client_key_file%" \
       $client_configure_file
Jondy Zhao's avatar
Jondy Zhao committed
287 288 289
echo
echo Configure section config OK.
echo
290

Jondy Zhao's avatar
Jondy Zhao committed
291 292 293 294 295 296
# -----------------------------------------------------------
# re6stnet: Install required packages and register to nexedi
# -----------------------------------------------------------
echo
echo Starting configure section re6stnet ...
echo
297

298
echo Checking miniupnpc ...
299
if [[ ! -d /opt/miniupnpc ]] ; then
300
    package=/opt/downloads/miniupnpc.tar.gz
301
    [[ -r $package ]] || csih_error "No package found: $package"
302 303
    echo "Installing miniupnpc ..."
    cd /opt
304
    tar xzf $package --no-same-owner
305 306 307
    mv $(ls -d miniupnpc-*) miniupnpc
    cd miniupnpc
    make
308
    python setup.py install || csih_error "Failed to install miniupnpc."
309 310 311
    echo "Install miniupnpc OK."
else
    echo Check miniupnpc OK.
312 313
fi

314
echo Checking pyOpenSSL ...
315
if [[ ! -d /opt/pyOpenSSL ]] ; then
316
    package=/opt/downloads/pyOpenSSL.tar.gz
317
    [[ -r $package ]] || csih_error "No package found: $package"
318 319
    echo "Installing pyOpenSSL ..."
    cd /opt
320
    tar xzf $package --no-same-owner
321 322
    mv $(ls -d pyOpenSSL-*) pyOpenSSL
    cd pyOpenSSL
323
    python setup.py install ||  csih_error "Failed ot install pyOpenSSL."
324 325 326
    echo "Install pyOpenSSL OK."
else
    echo Check pyOpenSSL OK.
327 328
fi

329
echo Checking re6stnet ...
330 331
if [[ ! -d /opt/re6stnet ]] ; then
    echo "Installing re6stnet ..."
332
    package=/opt/downloads/re6stnet.tar.gz
333
    cd /opt
334 335
    if [[ -r $package ]] ; then
        tar xzf $package --no-same-owner
336 337 338
        mv $(ls -d re6stnet-*) re6stnet
    else
        echo "Clone re6stnet from http://git.erp5.org/repos/re6stnet.git"
339
	git clone -b cygwin http://git.erp5.org/repos/re6stnet.git ||
340
        csih_error "Failed to clone re6stnet.git"
341 342
    fi
    cd re6stnet
343
    python setup.py install || csih_error "Failed to install re6stnet."
344 345 346
    echo "Install re6stnet OK."
else
    echo Check re6stnet OK.
347 348
fi

Jondy Zhao's avatar
Jondy Zhao committed
349 350 351 352
echo Checking re6stnet configuration ...
if [[ ! -r $re6stnet_configure_file ]] ; then
    echo "Registering to http://re6stnet.nexedi.com ..."
    cd $(dirname $re6stnet_configure_file)
353
    # Your subnet: 2001:67c:1254:e:19::/80 (CN=917529/32)
Jondy Zhao's avatar
Jondy Zhao committed
354 355
    subnet=$(re6st-conf --registry http://re6stnet.nexedi.com/ --anonymous | \
        grep "^Your subnet:") || \
356
        csih_error "Register to nexedi re6stnet failed"
Jondy Zhao's avatar
Jondy Zhao committed
357
    [[ -r re6stnet.conf ]] || \
358
        csih_error "No $re6stnet_configure_file found."
Jondy Zhao's avatar
Jondy Zhao committed
359 360 361 362 363 364 365 366 367 368 369 370
    echo Register re6stnet OK.

    echo "Write information to re6stnet.conf:"
    echo "  # $subnet"
    echo "  table 0"
    echo "  ovpnlog"
    echo "  main-interface $slapos_ifname"
    echo "  interface $slapos_ifname"
    echo -e "# $subnet\ntable 0\novpnlog" \
        "\nmain-interface $slapos_ifname\ninterface $slapos_ifname" \
        >> $re6stnet_configure_file
fi
371

372 373 374 375 376 377 378 379 380 381 382 383 384 385
echo
echo Configure section re6stnet OK.
echo

# -----------------------------------------------------------
# taps: Install openvpn tap-windows drivers used by re6stnet
# -----------------------------------------------------------
#
# Adding tap-windows driver will break others, so we add all drivers
# here. Get re6stnet client count, then remove extra drivers and add
# required drivers.
echo
echo Starting configure section taps ...
echo
Jondy Zhao's avatar
Jondy Zhao committed
386
if check_re6stnet_needed ; then
387 388
    client_count=$(sed -n -e "s/^client-count *//p" $re6stnet_configure_file)
    [[ -z "$client_count" ]] && client_count=10
Jondy Zhao's avatar
Jondy Zhao committed
389
    echo "Re6stnet client-count: $client_count"
390 391 392 393 394 395 396 397 398
    re6stnet_name_list="re6stnet-tcp re6stnet-udp"
    for (( i=1; i<=client_count; i=i+1 )) ; do
        re6stnet_name_list="$re6stnet_name_list re6stnet$i"
    done
    filename=$(cygpath -w $openvpn_tap_driver_inf)
    for name in $re6stnet_name_list ; do
        echo "Checking interface $name ..."
        if ! netsh interface ipv6 show interface | grep -q "\\b$name\\b" ; then
            [[ -r $openvpn_tap_driver_inf ]] ||
399
            csih_error "Failed to install OpenVPN Tap-Windows Driver, missing driver inf file: $filename"
400 401

            echo "Installing  interface $name ..."
Jondy Zhao's avatar
Jondy Zhao committed
402
            # ipwin install \"$filename\" $openvpn_tap_driver_hwid $name; ||
403
            ip vpntap add dev $name ||
404
            csih_error "Failed to install OpenVPN Tap-Windows Driver."
405 406 407 408 409 410 411
            echo "Interface $name installed."
        else
            echo "$name has been installed."
        fi
    done

    # Run re6stnet if no native ipv6
412 413
    check_re6stnet_configure ||
    csih_error "Failed to configure re6stnet."
Jondy Zhao's avatar
Jondy Zhao committed
414
    if ! cygrunsrv --query $re6stnet_service_name >/dev/null 2>&1 ; then
415
        if [[ -z "${csih_PRIVILEGED_PASSWORD}" ]] ; then
Jondy Zhao's avatar
Jondy Zhao committed
416
            slapos_request_password $slapos_admin "Install re6stnet service need the password of $slapos_admin."
417
        fi
Jondy Zhao's avatar
Jondy Zhao committed
418
        cygrunsrv -I $re6stnet_service_name -c $(dirname $re6stnet_configure_file) \
419
            -p $(which re6stnet) -a "@re6stnet.conf" -d "CYGWIN re6stnet" \
420 421
            -u $slapos_admin -w ${csih_PRIVILEGED_PASSWORD} ||
        csih_error "Failed to install $re6stnet_service_name service."
Jondy Zhao's avatar
Jondy Zhao committed
422 423
    fi
    echo "You can check log files in the /var/log/re6stnet/*.log"
424 425 426 427 428 429 430 431 432 433
    if ! check_cygwin_service $re6stnet_service_name ; then
        csih_error_multi "Failed to start $re6stnet_service_name service. " \
            "One possible case is that re6stnet service is shutdown in unusual ways, " \
            "and in this case, you can fix it by removing '/var/lib/re6stnet'."
        if csih_request "Do you want to let me remove '/var/lib/re6stnet' for you?" ; then
            rm -rf /var/lib/re6stnet
            check_cygwin_service $re6stnet_service_name ||
            csih_error "Failed to start $re6stnet_service_name service."
        fi
    fi
Jondy Zhao's avatar
Jondy Zhao committed
434
else
435
    echo "Native IPv6 found, no taps required."
436
fi
437

Jondy Zhao's avatar
Jondy Zhao committed
438
echo
439
echo Configure section taps OK.
Jondy Zhao's avatar
Jondy Zhao committed
440
echo
441

Jondy Zhao's avatar
Jondy Zhao committed
442 443 444 445 446 447 448 449
# -----------------------------------------------------------
# runner: Create instance of slap web runner
# -----------------------------------------------------------
echo
echo Starting configure section runner ...
echo
slaprunner_title="SlapOS-Node-Runner-In-$computer_guid"
feature_code="#-*- SlapOS Web Runner JavaScript Boot Code -*-#"
450
if ! grep -q -F "$feature_code" $slaprunner_startup_file ; then
Jondy Zhao's avatar
Jondy Zhao committed
451 452 453 454 455
    echo Installing SlapOS Web Runner ...

    if [[ -r $re6stnet_configure_file ]] ; then
        re6stnet_ipv6=$(grep "Your subnet" $re6stnet_configure_file| \
            sed -e "s/^.*subnet: //g" -e "s/\/80 (CN.*\$/1/g")
456
        if [[ ! -z "$re6stnet_ipv6" ]] ; then
Jondy Zhao's avatar
Jondy Zhao committed
457 458 459 460 461
            echo "Re6stnet address in this computer: $re6stnet_ipv6"
            netsh interface ipv6 show addr $slapos_ifname level=normal | \
                grep -q $re6stnet_ipv6 || \
                netsh interface ipv6 add addr $slapos_ifname $re6stnet_ipv6
        fi
462
    fi
463

Jondy Zhao's avatar
Jondy Zhao committed
464
    /opt/slapos/bin/slapos node format -cv --now || \
465
        csih_error "Failed to run slapos format."
466

467 468
    echo "Supply slapwebrunner in the computer $computer_guid"
    /opt/slapos/bin/slapos supply slaposwebrunner $computer_guid
Jondy Zhao's avatar
Jondy Zhao committed
469

470
    echo "Request an instance $slaprunner_title ..."
471
    patch_file=/etc/slapos/patches/slapos-cookbook-inotifyx.patch
472
    while true ; do
473
        /opt/slapos/bin/slapos node software --verbose
474
        # Apply patches to slapos.cookbook for inotifix
Jondy Zhao's avatar
Jondy Zhao committed
475
        if [[ -r $patch_file ]] ; then
476 477 478
            for x in $(find /opt/slapgrid/ -name slapos.cookbook-*.egg) ; do
                echo Apply patch $patch_file at $x
                cd $x
Jondy Zhao's avatar
Jondy Zhao committed
479 480
                patch -f --dry-run -p1 < $patch_file > /dev/null && \
                    patch -p1 < $patch_file
481
            done
482
        fi
483 484
        /opt/slapos/bin/slapos node instance --verbose
        /opt/slapos/bin/slapos node report --verbose
Jondy Zhao's avatar
Jondy Zhao committed
485
        /opt/slapos/bin/slapos request $client_config_file $slaprunner_title \
486
            slaposwebrunner --node computer_guid=$computer_guid && break
Jondy Zhao's avatar
Jondy Zhao committed
487
        sleep 3
488 489 490 491 492 493 494
    done
    # Connection parameters of instance are:
    #  {'backend_url': 'http://[2001:67c:1254:45::c5d5]:50000',
    #  'cloud9-url': 'http://localhost:9999',
    #  'password_recovery_code': 'e2d01c14',
    #  'ssh_command': 'ssh 2001:67c:1254:45::c5d5 -p 2222',
    #  'url': 'http://softinst39090.host.vifib.net/'}
Jondy Zhao's avatar
Jondy Zhao committed
495
    slaprunner_url=$(/opt/slapos/bin/slapos request $client_config_file \
496
        $slaprunner_title slaposwebrunner --node computer_guid=$computer_guid | \
497
        grep backend_url | sed -e "s/^.*': '//g" -e "s/',.*$//g")
Jondy Zhao's avatar
Jondy Zhao committed
498
    echo "SlapOS Web Runner URL: $slaprunner_url"
499
    [[ -z "$slaprunner_url" ]] && \
500
        csih_error "Failed to create instance of SlapOS Web Runner."
501

502
    cat <<EOF > $slaprunner_startup_file
503 504 505 506 507
<html>
<head><title>SlapOS Web Runner</title>
<script LANGUAGE="JavaScript">
<!--
function openwin() {
508
  window.location.href = "$slaprunner_url"
509 510 511 512 513
}
//-->
</script>
</head>
<body onload="openwin()"/>
Jondy Zhao's avatar
Jondy Zhao committed
514
<!-- $feature_code -->
515 516
</html>
EOF
517
    echo SlapOS Web Runner boot file $slaprunner_startup_file generated.
518 519 520 521 522

    echo
    echo Install Web Runner OK.
    echo
fi
Jondy Zhao's avatar
Jondy Zhao committed
523 524 525
echo
echo Configure section runner OK.
echo
526

Jondy Zhao's avatar
Jondy Zhao committed
527 528 529 530 531 532
# -----------------------------------------------------------
# tab: Install cron service and create crontab
# -----------------------------------------------------------
echo
echo Starting configure section cron ...
echo
Jondy Zhao's avatar
Jondy Zhao committed
533 534 535 536
cron_user=$slapos_admin
slapos_crontab_file="/var/cron/tabs/$cron_user"
if [[ ! -f $slapos_crontab_file ]] ; then
    cat <<EOF  > $slapos_crontab_file
537 538
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
539 540 541
MAILTO=""

# Run "Installation/Destruction of Software Releases" and "Deploy/Start/Stop Partitions" once per minute
Jondy Zhao's avatar
Jondy Zhao committed
542 543
* * * * * /opt/slapos/bin/slapos node software --verbose --logfile=/opt/slapos/log/slapos-node-software.log > /dev/null 2>&1
* * * * * /opt/slapos/bin/slapos node instance --verbose --logfile=/opt/slapos/log/slapos-node-instance.log > /dev/null 2>&1
544 545

# Run "Destroy Partitions to be destroyed" once per hour
Jondy Zhao's avatar
Jondy Zhao committed
546
0 * * * * /opt/slapos/bin/slapos node report --maximal_delay=3600 --verbose --logfile=/opt/slapos/log/slapos-node-report.log > /dev/null 2>&1
547 548

# Run "Check/add IPs and so on" once per hour
Jondy Zhao's avatar
Jondy Zhao committed
549
0 * * * * /opt/slapos/bin/slapos node format >> /opt/slapos/log/slapos-node-format.log 2>&1
550 551
EOF
fi
552 553 554 555 556 557
echo Change owner of $slapos_crontab_file to $cron_user
chown $cron_user $slapos_crontab_file
echo Change mode of $slapos_crontab_file to 644
chmod 644 $slapos_crontab_file
ls -l $slapos_crontab_file

Jondy Zhao's avatar
Jondy Zhao committed
558
echo
559 560
echo Begin of crontab of $slapos_admin:
echo ------------------------------------------------------------
561
cat $slapos_crontab_file || csih_error "No crob tab found."
562 563 564 565
echo ------------------------------------------------------------
echo End of crontab of $slapos_admin.

echo 
Jondy Zhao's avatar
Jondy Zhao committed
566 567
echo Configure section cron OK.
echo
568

Jondy Zhao's avatar
Jondy Zhao committed
569 570 571
# -----------------------------------------------------------
# startup: Start slapos-configure when windows startup
# -----------------------------------------------------------
572 573 574 575 576 577 578
# echo
# echo Starting configure section startup ...
# echo
# slapos_run_script=$(cygpath -a $0)
# regtool -q get "$slapos_run_key\\$slapos_run_entry" || \
#     regtool -q set "$slapos_run_key\\$slapos_run_entry" \
#     "\"$(cygpath -w /usr/bin/bash)\" --login -i $slapos_run_script" || \
579
#     csih_error "Failed to add slapos-configure.sh as windows startup item."
580 581 582 583 584 585
# echo "Windows startup item:"
# echo "  $slapos_run_key\\$slapos_run_entry = " \
#      $(regtool get "$slapos_run_key\\$slapos_run_entry")
# echo
# echo Configure section startup OK.
# echo
586

Jondy Zhao's avatar
Jondy Zhao committed
587
echo Configure SlapOS successfully.
588
read -n 1 -t 60 -p "Press any key to exit..."
589
exit 0