File: __init__.py

package info (click to toggle)
libreswan 5.2-2.3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 81,644 kB
  • sloc: ansic: 129,988; sh: 32,018; xml: 20,646; python: 10,303; makefile: 3,022; javascript: 1,506; sed: 574; yacc: 511; perl: 264; awk: 52
file content (79 lines) | stat: -rwxr-xr-x 2,535 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python3

# pexpect script to Install OpenBSD base Domain
#
# Copyright (C) 2020 Ravi Teja <hello@rtcms.dev>
# Copyright (C) 2021-2023 Andrew Cagney
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.  See <https://www.gnu.org/licenses/gpl2.txt>.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.

import pexpect
import sys
import time
import os

FILTER_OUTPUT = False

def es(child, expect, send, t=60):
    try:
        print("expecting", expect);
        child.expect(expect,timeout=t)
        print("sending", send);
        child.send(send+'\n')
    except:
        print("==> Error Executing >>"+send+"<< Command <==")
        print("==> Error <==\n"+child.before+"\n ==========")
        sys.exit(1)

def install_base(child, param):

    print("waiting for boot");
    child.expect('boot>', timeout=180)

    #sleep for 10 seconds so that all those initial boot log loads
    time.sleep(10)
    #REGx for Installation prompt
    #To enter Shell mode
    es(child,'.*hell?','S')

    #Mounting of drive where install.conf file is located
    es(child,'# ','mount /dev/cd0c /mnt')
    #Copying of install.conf file
    es(child,'# ','cp /mnt/base.conf /')
    es(child,'# ','cp /mnt/base.sh /')
    es(child,'# ','cp /mnt/base.disk /')
    #Unmounting the drive
    es(child,'# ','umount /mnt')

    #Installing by taking answers from install.conf file
    es(child,'# ','install -af /base.conf')
    #This is to check if all the installation files got copied(it's slow on some systems)
    while child.expect([".*install has been successfully completed!",
                        pexpect.EOF,
                        pexpect.TIMEOUT], timeout=10) != 0:
        continue

    # customize the install
    es(child,'# ','/bin/sh -x /base.sh')

    #child.logfile = None
    #child.interact()
    #exit(0)

    #To shutdown the base domain
    es(child,'openbsd# ','sync ; sync ; sync\n')
    es(child,'openbsd# ','halt -p\n')

    print("Waiting for shutdown...")
    time.sleep(20)
    child.close()
    #To force shutdown the base domain via virt manager
    os.system('sudo virsh destroy ' + param.domain + ' > /dev/null')