aboutsummaryrefslogtreecommitdiffstats
path: root/platforms/freebox-delta/specialFunctions.sh
blob: 3a15863ec338a10e672824ac479620a954904938 (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash

# Copyright (C) 2017-2018 Daniel Tartavel-jeannot   <contact@librepc.com>
# Copyright (C) 2019-2020 Jean-Baptiste Biernacki   <j.biernacki@free.fr>
#

# 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.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

p1_Start_sector="${DEFAULT}"
p1_Size="128M"
p1_Type="uefi"
#p1_Bootable="*"
p1_Bootable="${DEFAULT}"
p2_Start_sector="${DEFAULT}"
p2_Size="${DEFAULT}"
p2_Type="linux"
p2_Bootable="${DEFAULT}"

SFDISK_SCRIPT="label: gpt
${p1_Start_sector}, ${p1_Size}, ${p1_Type}, ${p1_Bootable}
${p2_Start_sector}, ${p2_Size}, ${p2_Type}, ${p2_Bootable}
write
"


function createImageWrap() {
    title "Wrap image creation"
    preImgCreation
    if [ ${?} -ne 0 ]; then
        error "line ${LINENO} error in the process ${CONFIG_PATH}/specialFunctions.sh ."
        cleanExit ${ERR_1}
    fi
    createimage
    
    partitionningimage
    
    loopingImage
    
    BOOTFS=${BOOTFS:="ext4"}
    formatpartitions ${BOOTFS} ext4
    unloopingImage
    loopingImage

    return 0
}


function loopingImage() {
    title "Looping image ..."

    # Mettre en place et contrôler des périphériques boucle.
    # -f, --find                    trouver le premier périphérique inutilisé
    # --show                    afficher le nom du périphérique après configuration (avec -f)
#     DEVICE=$(/usr/sbin/losetup -f --show "${INSTALL_PATH}/${IMAGE}")
    DEVICE=$(/usr/bin/udisksctl loop-setup -f ${INSTALL_PATH}/${IMAGE} | sed -e 's|^.*\/dev\/|\/dev\/|' -e 's|\.$||')
    if [ -z "${DEVICE}" ]; then
        error "Error, device missing from udisksctl loop-setup output."
        cleanExit ${ERR_1}
    fi

    print_info "Image looped on ${DEVICE}"
    
    
    #Previous function give us a list of partition. It is easy to get it and define prior this list the partition.
    #But... How to distinguish between the boot p1 and the root p2 if both are empty and ext4 ? ...

    if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
        BOOTP="${DEVICE}p1"
        ROOTP="${DEVICE}p2"
        
#         BOOT_UUID=$(/usr/sbin/blkid -s UUID -o value UUID "${BOOTP}")
        BOOT_UUID=$(/usr/bin/lsblk -n -o UUID "${BOOTP}")
        print_info "Boot UUID: ${BOOT_UUID}"
    else
        ROOTP="${DEVICE}p1"
    fi
    
#     ROOT_UUID=$(/usr/sbin/blkid -s UUID -o value UUID "${ROOTP}")
    ROOT_UUID=$(/usr/bin/lsblk -n -o UUID "${ROOTP}")
    print_info "Root UUID: ${ROOT_UUID}"
    
    return 0
}


function formatpartitions() {
    print_info "Formatting partitions"
    if [ 1 -eq ${SEPARATE_BOOT_PARTITION} ]; then
        print_info "Boot : ${BOOTP} as ${1}"
        if [ "vfat" = ${1} ]; then
            FSINFO=$(/usr/sbin/mkfs.vfat ${BOOTP} )
            BOOT_UUID=$(echo "${FSINFO}" | grep 'Volume ID is' | sed 's/Volume ID is \([[:alnum:]]*\),.*$/\1/')
            print_info "Boot UUID = ${BOOT_UUID}"
            rm -f ${temporary}
        else
            FSINFO=$(yes | /usr/sbin/mkfs.ext4 -E offset=${BOOT_OFFSET_B} ${INSTALL_PATH}/${IMAGE} $((${BOOT_SIZE_KB}))k)
            BOOT_UUID=$(echo "${FSINFO}" | grep 'Filesystem UUID' | sed 's/Filesystem UUID: //')
        fi
#         "/sbin/mkfs.${1}" "${BOOTP}"
        if [ ${?} -ne 0 ]; then
            error "line ${LINENO} error formating ${BOOTP} : exiting"
#             /usr/sbin/losetup -d "${DEVICE}"
            udisksctl unmount -b ${BOOTP}
            cleanExit ${ERR_1}
        fi
#         BOOT_UUID=$(/usr/sbin/blkid -s UUID -o value UUID "${BOOTP}")
#         print_info "Boot UUID: ${BOOT_UUID}"
    fi

    print_info "Root : ${ROOTP} as ${2}"
    FSINFO=$(yes | /sbin/mkfs.${2} "${ROOTP}" )
    if [ ${?} -ne 0 ]; then
        error "line ${LINENO} error formating ${ROOTP} : exiting"
        cleanExit ${ERR_1}
    fi
    ROOT_UUID=$(echo "${FSINFO}" | grep 'Filesystem UUID' | sed 's/Filesystem UUID: //')
#     ROOT_UUID=$(/usr/sbin/blkid -s UUID -o value UUID "${ROOTP}")
    print_info "Root UUID: ${ROOT_UUID}"

    /usr/bin/sync
    
    return 0
}


function imageConversion()
{
    title "Converting image into a qcow2 file"
    
    qemu-img convert -O qcow2 ${INSTALL_PATH}/${IMAGE} ${INSTALL_PATH}/${IMAGE}.qcow2
    return 0
}


function preImgCreation()
{
#     title "Creating Banana Pro image"
    #Nothing to download.
    return 0
}


function postPrepareChroot()
{
    #Nothing to do.
    return 0
}


function burningBootloader()
{
    # DEVICE is set just before this function and looped.
    return 0
}


function copyingCustomSystem()
{
#     installpkg ${CONFIG_PATH}/package.mga7.aarch64.rpm
#     installpkg package
    return 0
}