summaryrefslogtreecommitdiff
path: root/archiso2dual/archiso2dual
blob: e3b49adb0344a1c24b072024e7d0084c47311f3f (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#!/bin/bash

#
# Join two Arch Linux iso images of i686 and x86_64 architecture.
# Contributed for archiso by Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar>
#

set -e -u

publisher="Arch Linux <http://www.archlinux.org>"
application="Arch Linux Live/Rescue disk"
label="ARCH_$(date +%Y%m)"
isofile_i686=""
isofile_x86_64=""
imgname=""
quiet="y"
profile_type="basic"
work_dir="/tmp/archiso2dual"
isomounts_file="/usr/share/archiso2dual/isomounts"
isolinuxcfg_file="/usr/share/archiso2dual/isolinux.cfg"
removefiles_file="/usr/share/archiso2dual/removefiles.lst"
appname=${0##*/}
_error="0"
_confirm="n"
_v=""
_iscoreiso=n

iso_umount() {
    echo "Executing: ${FUNCNAME}"
    trap - 0 1 2 15
    umount ${_v} ${work_dir}/i686/mnt
    umount ${_v} ${work_dir}/x86_64/mnt
}

iso_mount() {
    echo "Executing: ${FUNCNAME}"
    trap 'iso_umount' 0 1 2 15
    mount ${_v} -t udf -o ro,loop ${isofile_i686} ${work_dir}/i686/mnt
    mount ${_v} -t udf -o ro,loop ${isofile_x86_64} ${work_dir}/x86_64/mnt
}

kernel_copy() {
    echo "Executing: ${FUNCNAME}"
    for _arch in i686 x86_64; do
        cp ${_v} $work_dir/${_arch}/mnt/boot/archiso.img $work_dir/iso/boot/${_arch}/archiso.img
        cp ${_v} $work_dir/${_arch}/mnt/boot/vmlinuz26 $work_dir/iso/boot/${_arch}/vmlinuz26
    done
}

isolinux_copy() {
    echo "Executing: ${FUNCNAME}"
    cp ${_v} $work_dir/i686/mnt/boot/{memtest*,releasenotes.txt,splash.png,x86test*} $work_dir/iso/boot/
    cp ${_v} $work_dir/i686/mnt/boot/isolinux/*.c32 $work_dir/iso/boot/isolinux/
    cp ${_v} $work_dir/i686/mnt/boot/isolinux/memdisk $work_dir/iso/boot/isolinux/
    cp ${_v} $work_dir/i686/mnt/boot/isolinux/isolinux.bin $work_dir/iso/boot/isolinux/
    cp ${_v} $work_dir/i686/mnt/boot/isolinux/pxelinux.0 $work_dir/iso/boot/isolinux/
    cp ${_v} $work_dir/i686/mnt/boot/isolinux/gpxelinux.0 $work_dir/iso/boot/isolinux/
}

isolinuxcfg_copy() {
    echo "Executing: ${FUNCNAME}"
    sed "s|XXX|${label}|g" ${isolinuxcfg_file} > $work_dir/iso/boot/isolinux/isolinux.cfg
}

isomounts_copy() {
    echo "Executing: ${FUNCNAME}"
    cp ${_v} ${isomounts_file} $work_dir/iso/
}

squashfs_copy() {
    echo "Executing: ${FUNCNAME}"
    for _arch in i686 x86_64; do
        cp ${_v} $work_dir/${_arch}/mnt/*.sqfs $work_dir/iso/${_arch}/
    done
}

make_iso() {
    echo "Executing: ${FUNCNAME}"
    if [ "${quiet}" = "y" ]; then
        _qflag="-quiet"
    else
        _qflag=""
    fi
    mkisofs ${_v} ${_qflag} -r -l \
        -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat \
        -uid 0 -gid 0 \
        -udf -allow-limited-size -iso-level 3 \
        -input-charset utf-8 -p "prepared by archiso2dual" \
        -no-emul-boot -boot-load-size 4 -boot-info-table \
        -publisher "${publisher}" \
        -A "${application}" \
        -V "${label}" \
        -o "${imgname}" "${work_dir}/iso/"
    isohybrid "${imgname}"
}

unsquashfs_image() {
    echo "Executing: ${FUNCNAME}"
    img=${1}
    arch=${2}
    rm -rf ${work_dir}/tmp/${arch}/${img}
    if [ "${quiet}" = "y" ]; then
        unsquashfs -d ${work_dir}/tmp/${arch}/${img} $work_dir/iso/${arch}/${img}.sqfs > /dev/null
    else
        unsquashfs -d ${work_dir}/tmp/${arch}/${img} $work_dir/iso/${arch}/${img}.sqfs
    fi
}

mksquashfs_image() {
    echo "Executing: ${FUNCNAME}"
    img=${1}
    arch=${2}
    rm -f ${work_dir}/iso/${arch}/${img}.sqfs
    if [ "${quiet}" = "y" ]; then
        mksquashfs ${work_dir}/tmp/${arch}/${img} ${work_dir}/iso/${arch}/${img}.sqfs > /dev/null
    else
        mksquashfs ${work_dir}/tmp/${arch}/${img} ${work_dir}/iso/${arch}/${img}.sqfs
    fi
}

usrshare_make_image() {
    echo "Executing: ${FUNCNAME}"
    mkdir -p ${work_dir}/tmp/any/usrshare/usr
    cp -a ${work_dir}/tmp/i686/root-image/usr/share ${work_dir}/tmp/any/usrshare/usr
    mksquashfs_image usrshare any
}

libmodules_make_image() {
    echo "Executing: ${FUNCNAME}"
    for _arch in i686 x86_64; do
        mkdir -p ${work_dir}/tmp/${_arch}/libmodules/lib
        cp -a ${work_dir}/tmp/${_arch}/root-image/lib/modules ${work_dir}/tmp/${_arch}/libmodules/lib
        mksquashfs_image libmodules ${_arch}
    done
}

core_pkgs_make_image() {
    echo "Executing: ${FUNCNAME}"
    mkdir -p ${work_dir}/tmp/any/core-any-pkgs/src/core/pkg
    cp -a ${work_dir}/tmp/i686/core-pkgs/src/core/pkg/*-any.pkg.* ${work_dir}/tmp/any/core-any-pkgs/src/core/pkg
    for _arch in i686 x86_64; do
        rm -rf ${work_dir}/tmp/${_arch}/core-pkgs/src/core/pkg/*-any.pkg.*
        mksquashfs_image core-pkgs ${_arch}
    done
    mksquashfs_image core-any-pkgs any
}

core_pkgs_extract() {
    echo "Executing: ${FUNCNAME}"
    for _arch in i686 x86_64; do
        unsquashfs_image core-pkgs ${_arch}
    done
}

check_if_core_medium() {
    echo "Executing: ${FUNCNAME}"
    if [ -f ${work_dir}/iso/i686/core-pkgs.sqfs ] && [ -f ${work_dir}/iso/x86_64/core-pkgs.sqfs ]; then
        _iscoreiso=y
    fi
}

root_image_extract() {
    echo "Executing: ${FUNCNAME}"
    for _arch in i686 x86_64; do
        unsquashfs_image root-image ${_arch}
    done
}

root_image_purge() {
    echo "Executing: ${FUNCNAME}"
    while read _file; do
        [ "${_file#"#"}" != "${_file}" ] && continue
        for _arch in i686 x86_64; do
            rm -rf "${work_dir}/tmp/${_arch}/root-image/${_file}"
        done
    done < "${removefiles_file}"
}

root_image_list_purge() {
    while read _file; do
        [ "${_file#"#"}" != "${_file}" ] && continue
        for _arch in i686 x86_64; do
            echo "${work_dir}/tmp/${_arch}/root-image/${_file}"
        done
    done < "${removefiles_file}"
}

root_image_make_image() {
    echo "Executing: ${FUNCNAME}"
    for _arch in i686 x86_64; do
        rm -rf ${work_dir}/tmp/${_arch}/root-image/usr/share
        rm -rf ${work_dir}/tmp/${_arch}/root-image/lib/modules
        mksquashfs_image root-image ${_arch}
    done
}

make_workspace() {
    echo "Executing: ${FUNCNAME}"
    for _arch in i686 x86_64; do
        mkdir ${_v} -p ${work_dir}/iso/${_arch}
        mkdir ${_v} -p ${work_dir}/iso/boot/${_arch}
        mkdir ${_v} -p ${work_dir}/${_arch}/mnt
        mkdir ${_v} -p ${work_dir}/tmp/${_arch}
    done
    mkdir ${_v} -p ${work_dir}/iso/boot/isolinux
    mkdir ${_v} -p ${work_dir}/iso/any
    mkdir ${_v} -p ${work_dir}/tmp/any
}

show_help()
{
    exitvalue=${1}
    echo
    echo "${appname} [options] -3 <i686.iso> -6 <x86_64.iso> -o <output.iso>"
    echo
    echo " needed options:"
    echo "    -3 <i686.iso>    Path to i686 source iso image"
    echo "    -6 <x86_64.iso>  Path to x86_64 source iso image"
    echo "    -o <output.iso>  Path to dual target iso image"
    echo
    echo " general options:"
    echo "    -M <isomounts>   Path to isomounts file
                     (default to '${isomounts_file}'"
    echo "    -S <isolinux>    Path to isolinux.cfg file
                     (default to '${isolinuxcfg_file}'"
    echo "    -R <removefiles> Path to removefiles file
                     (default to '${removefiles_file}'"
    echo "    -w <workdir>     Set work directory
                     (default to '${work_dir}')"
    echo "    -T <profile>     Type of target image (work is done on root-image.sqfs):
                     basic:    join both images, no changes in root-image
                     split:    'basic' + split out usr/share/ and lib/modules/ from root-image
                     full:     'split' + remove specified directories (with -R) from root-image
                     (default to '${profile_type}')"
    echo "    -L <label>       Set a label for the disk [max 11 chars]
                     (default to '${label}')"
    echo "    -P <publisher>   Set a publisher for the disk
                     (default to '${publisher}')"
    echo "    -A <application> Set an application name for the disk
                     (default to '${application}')"
    echo "    -y               Confirm execution (otherwise only show configuration)"
    echo "    -v               Enable verbose output"
    echo "    -h               This message"
    exit ${exitvalue}
}

show_config() {
    echo
    echo "${appname} : Configuration settings"
    echo "    source iso i686 image:   ${isofile_i686}"
    echo "  source iso x86_64 image:   ${isofile_x86_64}"
    echo "         target iso image:   ${imgname}"
    echo "           isomounts file:   ${isomounts_file}"
    echo "        isolinux.cfg file:   ${isolinuxcfg_file}"
    echo "     removefiles.lst file:   ${removefiles_file}"
    echo "        working directory:   ${work_dir}"
    echo "                  profile:   ${profile_type}"
    echo "                    label:   ${label}"
    echo "                publisher:   ${publisher}"
    echo "              application:   ${application}"
    echo
    if [ "${profile_type}" = "full" ]; then
        echo "These files will be deleted (selected via -R option)"
        root_image_list_purge
    fi
}

options_check() {
    if [ "x${isofile_i686}" = "x" ]; then
        echo "*ERROR*: -3 <i686.iso> must be specified"
        _error="1"
    fi

    if [ "x${isofile_x86_64}" = "x" ]; then
        echo "*ERROR*: -6 <x86_64.iso> must be specified"
        _error="1"
    fi

    if [ "x${imgname}" = "x" ]; then
        echo "*ERROR*: -o <output.iso> must be specified"
        _error="1"
    fi

    if [ ${_error} = "1" ]; then
        show_help 1
    fi
}

sanity_check() {
    echo
    if [ ! -f "${isofile_i686}" ]; then
      echo "*ERROR*: ${isofile_i686} does not exist"
        _error="1"
    fi

    if [ ! -f "${isofile_x86_64}" ]; then
      echo "*ERROR*: ${isofile_x86_64} does not exist"
        _error="1"
    fi

    if [ -f "${imgname}" ]; then
      echo "*ERROR*: ${imgname} already exists, aborting"
        _error="1"
    fi

    if [ ! -f "${isomounts_file}" ]; then
      echo "*ERROR*: ${isomounts_file} does not exist, , specify one with -M option"
        _error="1"
    fi

    if [ ! -f "${isolinuxcfg_file}" ]; then
      echo "*ERROR*: ${isolinuxcfg_file} does not exist, specify one with -S option"
        _error="1"
    fi

    if [ ! -f "${removefiles_file}" ]; then
      echo "*ERROR*: ${removefiles_file} does not exist, specify one with -R option"
        _error="1"
    fi

    if [ -d "${work_dir}" ]; then
      echo "*ERROR*: work directory ${work_dir} is present, first delete it"
        _error="1"
    fi

    if [ ${_error} = "1" ]; then
        exit 1
    fi
}

if [ "$EUID" != "0" ]; then
    echo "*ERROR*: This script must be run as root."
    exit 1
fi

while getopts '3:6:o:T:M:S:R:L:P:A:yvh' arg; do
    case "${arg}" in
        3) isofile_i686="${OPTARG}" ;;
        6) isofile_x86_64="${OPTARG}" ;;
        o) imgname="${OPTARG}" ;;
        T) case "${OPTARG}" in
               "basic"|"split"|"full") profile_type="${OPTARG}" ;;
               *) echo; echo "*ERROR*: invalid argument in -T option: ${profile_type}"; show_help 1 ;;
           esac
           ;;
        M) isomounts_file="${OPTARG}" ;;
        S) isolinuxcfg_file="${OPTARG}" ;;
        R) removefiles_file="${OPTARG}" ;;
        L) label="${OPTARG}" ;;
        P) publisher="${OPTARG}" ;;
        A) application="${OPTARG}" ;;
        w) work_dir="${OPTARG}" ;;
        y) _confirm="y" ;;
        v) quiet="n"; _v="-v" ;;
        h|?) show_help 0 ;;
        *) echo; echo "*ERROR*: invalid argument '${arg}'"; show_help 1 ;;
    esac
done

options_check
sanity_check
show_config

if [ "${_confirm}" != "y" ]; then
   echo
   echo "If configuration is correct, re-execute with -y"
   exit 1
fi
make_workspace
iso_mount
kernel_copy
isolinux_copy
squashfs_copy
check_if_core_medium
iso_umount
isolinuxcfg_copy
isomounts_copy
if [ ${profile_type} = "full" ] || [ ${profile_type} = "split" ]; then
    root_image_extract
    if [ ${profile_type} = "full" ]; then
        root_image_purge
    fi
    if [ ${_iscoreiso} = "y" ]; then
        core_pkgs_extract
    fi
    usrshare_make_image
    libmodules_make_image
    root_image_make_image
    if [ ${_iscoreiso} = "y" ]; then
       core_pkgs_make_image
    fi
fi
make_iso