summaryrefslogtreecommitdiff
path: root/src/bootstrap.sh
blob: 7215d9b2c8706c40a4870cc651d3f5484d41ac00 (plain)
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
#!/bin/sh

DEFAULT_KEYS=$(parseconf -v bootstrap_keys)

# create necessary directories for a complete system
#
create_directories () {
    mkdir -p ${SYSROOT}
    mkdir -p ${SYSROOT}/dev
    mkdir -p ${SYSROOT}/tmp
    mkdir -p ${SYSROOT}/sys
    mkdir -p ${SYSROOT}/run
    mkdir -p ${SYSROOT}/proc
    mkdir -p ${SYSROOT}/usr
    mkdir -p ${SYSROOT}/root
    mkdir -p ${SYSROOT}/usr/bin
    mkdir -p ${SYSROOT}/usr/lib

    ln -s usr/bin ${SYSROOT}/bin
    ln -s usr/bin ${SYSROOT}/sbin
    ln -s bin ${SYSROOT}/usr/sbin

    ln -s usr/lib ${SYSROOT}/lib
    ln -s usr/lib ${SYSROOT}/lib64
    ln -s lib ${SYSROOT}/usr/lib64

    ln -s ../usr ${SYSROOT}/usr/local

    chmod 0755 ${SYSROOT}/dev
    chmod 1777 ${SYSROOT}/tmp
    chmod 0555 ${SYSROOT}/sys
    chmod 0555 ${SYSROOT}/proc
    chmod 0755 ${SYSROOT}/run
    chmod 0755 ${SYSROOT}/usr
    chmod 0750 ${SYSROOT}/root
    chmod 0755 ${SYSROOT}/usr/bin
    chmod 0755 ${SYSROOT}/usr/lib
    chmod 0755 ${SYSROOT}/
}

import_keys () {
    # import all keys
    set -o noglob
    if [ -d ${KEYCHAIN_DIR} ] && [ "$(ls ${KEYCHAIN_DIR} | wc -w)" != "0" ]; then
        keyimport *
    else
       echo "$DEFAULT_KEYS" | while read -r keypair; do 
           keyimport ${keypair%%:*} ${keypair#*:}
        done
    fi
}

bootstrap () {
    if [ "${SYSROOT}" = "/" ]; then
        printf "${RED}Error! Cannot bootstrap on existing system! Use ${LIGHT_RED}--root${RED} to specify new root filesystem\n"
        return 1
    fi

    if [ -e ${SYSROOT} ] && [ "$(ls -1 ${SYSROOT})" != "0" ]; then
        if prompt_question "${WHITE}System already exists on ${SYSROOT}, clear?"; then
            umount -r ${SYSROOT}/*
            rm -rf ${SYSROOT}/*
        fi
    fi
    
    printf "${BLUE}Creating directories..."
    create_directories
    printf "${GREEN}${CHECKMARK}\n"

    [ "$#" != "0" ] && install $@
    import_keys 
}