summaryrefslogtreecommitdiff
path: root/libre-testing/uboot4extlinux-sunxi/generate-uboot4extlinux-sunxi-install-text.sh
blob: e8c9c29a9f0c9839cf6503898065f00bf85ead28 (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
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
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0+
# Copyright (C) 2020 Denis 'GNUtoo' Carikli

line_length=81

printchar()
{
    char="$1"
    nr_chars="$2"

    if [ -z "${nr_chars}" ] ; then
        echo -n "${char}"
    else
        i=0
        while [ $i -lt ${nr_chars} ] ; do
            echo -n "${char}"
            i=$(expr $i + 1)
        done
    fi
}

print_separation_line()
{
    echo -n "+"
    printchar "-" $(expr ${line_length} - 2)
    echo  "+"
}

strlen()
{
    echo $(expr $(echo "$1" | wc -c) - 1)
}

print_header()
{
    pkgname="$1"

    # ${line_length}
    # - '| '
    # - ${pkgname}
    # - ' '
    # - 'installation instructions:'
    # - ' |'
    extra_spaces=$(expr ${line_length} - 2 - $(strlen "${pkgname}") - 1)
    extra_spaces=$(expr ${extra_spaces} - \
                $(strlen "installation instructions:") - 2)

    print_separation_line
    echo -n "| "
    echo -n "${pkgname} installation instructions:"
    printchar " " "${extra_spaces}"
    echo " |"
    print_separation_line
}

print_line()
{
    line="$1"

    # ${line_length} - '| ' - ${line} -  ' |'
    extra_spaces=$(expr ${line_length} - 2 - $(strlen "${line}") - 2)
    echo -n '| '
    echo -n "${line}"
    printchar " " "${extra_spaces}"
    echo ' |'
}

print_text()
{
    for line in "$@" ; do
        print_line "${line}"
    done
}

print_introduction()
{
    print_text \
        "To boot with u-boot you will need to do two things:" \
        "- First you will need to install u-boot to the storage device (like" \
        "  a microSD) you will be booting from. You can consult the Parabola" \
        "  installation instructions to know which storage devices are" \
        "  supported." \
        "- Then you will need to read and potentially modify the" \
        "  /boot/extlinux/extlinux.conf configuration file to tell u-boot" \
        "  from which kernel to boot, and various other settings related to" \
        "  booting (like LVM or disk encryption settings)."
}

print_uboot_install_instructions()
{
    pkgname="$1"
    install_script="$2"

    print_text \
           "To install or upgrade u-boot you can use similar commands:" \
           "    cd $(dirname ${script})" \
           "    sudo ./$(basename ${script}) <path/to/block-device>"

    print_line ""

    print_text \
       "For instance if the microSD you (will) boot from is available at" \
       "/dev/mmcblk0 you can use the following commands:" \
           "    cd $(dirname ${script})" \
           "    sudo ./$(basename ${script}) /dev/mmcblk0"

    print_line ""

    print_text \
       "Instead if the microSD is available at /dev/sdb you can use the" \
       "following commands:" \
           "    cd $(dirname ${script})" \
           "    sudo ./$(basename ${script}) /dev/sdb"
}

print_extlinux_config_remainder()
{
    pkgbase="$1"

    print_text \
       "When this is done you'll need to create and/or modify the" \
       "/boot/extlinux/extlinux.conf configuration file."
    print_line ""

    print_text \
        "There is an example file for that at" \
        "/usr/lib/u-boot/${pkgbase}/extlinux.conf"
}

pkgname="$1"
pkgbase="$2"
script="$3"

print_header "${pkgname}"
print_introduction
print_line " "
print_uboot_install_instructions "${pkgname}" "${script}"
print_line " "
print_extlinux_config_remainder "${pkgbase}"
print_separation_line