summaryrefslogtreecommitdiff
path: root/xibuild/build_all.sh
blob: ffa6c03dcc3619a6d03751948c89f234ffa5716f (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
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
#!/bin/sh

ERROR="\033[0;31m"
INFO="\033[0;34m"
PASS="\033[0;32m"
NEUTRAL="\033[0;33m"
EXTRA="\033[0;30m"
RESET="\033[0m"

XIPKG_INSTALL=/usr/lib/xipkg/install.sh
[ -f $XIPKG_INSTALL ] && . $XIPKG_INSTALL

# scan and run all postinstall scripts
#
run_postinstall () {
    postinstall="$XIB_CHROOT/var/lib/xipkg/postinstall"
    if [ -d $postinstall ]; then
        printf "${EXTRA}(postinstall " 
        for file in $(ls $postinstall); do
            file=$postinstall/$file
            f=$(basename $file)

            # run the postinstall file
            #
            chmod 755 $file
            xichroot "$XIB_CHROOT" "/var/lib/xipkg/postinstall/$f"
            if [ "$?" = "0" ]; then
                rm $file
                printf "${PASS}${CHECKMARK}"
            else
                printf "${EXTRA}x"
            fi
        done
        printf ")\n"

        [ "$(ls $postinstall | wc -w)" = 0 ] && \
            rmdir $postinstall
    fi
}

extract () {
    tar -h -p -vvxf $1 -C ${SYSROOT} 2>${LOG_FILE} | grep ^- | tr -s " " | cut -d" " -f6 | cut -c2- 
}


# build a package by its name
# 
build_package () {

    local name=$(echo $1 | cut -d"+" -f1)
    local install=$(echo $line | grep -q '+' && echo "true" || echo "false")
    local buildfile=$(find $XIB_BUILDFILES/repo/ -wholename "*/$name.xibuild" | head -1)
    
    if [ -f "$buildfile" ]; then
        printf "${INFO}%s\n${RESET}" $name 
        ./build_package.sh $buildfile || return 1

        # install the package it exists
        local exported_pkg=$(find $XIB_EXPORT -wholename "*/$name.xipkg" | head -1 | xargs realpath)
        if $install && [ -f $exported_pkg ] ; then
            printf "${INFO}${TABCHAR}install " 
            INSTALLED_DIR="$XIB_CHROOT/var/lib/xipkg/installed/"
            SYSROOT=$XIB_CHROOT
            VERBOSE=false
            install_package $exported_pkg $name && printf "${PASS}${CHECKMARK}\n" || printf "${NEUTRAL}${CHECKMARK}\n"
            run_postinstall
        fi

        return 0
    fi

    printf "${ERROR}${CROSSMARK} ${name}\n"
}

# build all of the packages
#
build_all () {
    all="$(perl build_order.pm)"
    echo "Building $(echo "$all" | wc -l )"
    for line in $all; do
        build_package $line || return 1
    done
}

while true; do
    if build_all; then 
        printf "\n${PASS}Built all packages!\n${RESET}"
        exit 0
    else
        printf "${ERROR} Something went wrong!${NEUTRAL} Press enter to view recent log"
        read out;

        less $(ls -t1 $XIB_EXPORT/repo/*/*.log | head -1 | xargs realpath)

        read -p "Retry build? [Y/n]" response
        if [ "$response" = "n" ]; then
            exit 1
        fi
    fi
done