summaryrefslogtreecommitdiff
path: root/make
blob: 6d150bac94c174bac1422509cb135df6d172b0fa (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
#!/bin/sh

set -e

scriptloc=${BASH_SOURCE:-$0}
scriptdir=${scriptloc%/*}

gen_cpio_list() {
    cat << EOF
dir /dev 0755 0 0
dir /mnt 0755 0 0
dir /proc 0755 0 0
dir /run 0755 0 0
dir /run/cryptsetup 0755 0 0
dir /sys 0755 0 0

nod /dev/console 0600 0 0 c 5 1

slink /bin/sh busybox 0755 0 0
slink /etc/mtab /proc/self/mounts 0755 0 0

slink /usr/lib64/libgcc_s.so libgcc_s.so.1 0755 0 0
file /usr/lib64/libgcc_s.so.1 /usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/libgcc_s.so.1 0755 0 0

file /bin/busybox /bin/busybox 0755 0 0
file /etc/passwd $scriptdir/passwd 0644 0 0
file /etc/dropbear/dropbear_rsa_host_key $scriptdir/dropbear_rsa_host_key 0600 0 0
file /etc/dropbear/dropbear_ecdsa_host_key $scriptdir/dropbear_ecdsa_host_key 0600 0 0
file /init $scriptdir/init 0755 0 0
file /lib/firmware/radeon/CAYMAN_mc.bin /lib/firmware/radeon/CAYMAN_mc.bin 0644 0 0
file /lib/firmware/radeon/CAYMAN_me.bin /lib/firmware/radeon/CAYMAN_me.bin 0644 0 0
file /lib/firmware/radeon/CAYMAN_pfp.bin /lib/firmware/radeon/CAYMAN_pfp.bin 0644 0 0
file /lib/firmware/radeon/CAYMAN_rlc.bin /lib/firmware/radeon/CAYMAN_rlc.bin 0644 0 0
file /lib/firmware/radeon/CAYMAN_smc.bin /lib/firmware/radeon/CAYMAN_smc.bin 0644 0 0
file /lib/firmware/radeon/SUMO_uvd.bin /lib/firmware/radeon/SUMO_uvd.bin 0644 0 0
file /lib/firmware/rtl_nic/rtl8168h-2.fw /lib/firmware/rtl_nic/rtl8168h-2.fw 0644 0 0
file /lib64/libnss_files.so.2 /lib64/libnss_files.so.2 0755 0 0
file /root/.ssh/authorized_keys $scriptdir/authorized_keys 0600 0 0
file /unlock $scriptdir/unlock 0755 0 0
file /usr/share/alsa/cards/HDA-Intel.conf /usr/share/alsa/cards/HDA-Intel.conf 0644 0 0
file /usr/share/alsa/cards/USB-Audio.conf /usr/share/alsa/cards/USB-Audio.conf 0644 0 0
file /usr/share/sounds/ding.wav $scriptdir/ding.wav 0644 0 0
EOF
    find /usr/share/alsa \
        \( -name cards -o -name speaker-test -o -name ucm -o -name topology \) -prune -o \
        -type f -print | while read f; do
        printf 'file %s %s 0644 0 0\n' "$f" "$f"
    done
    for cmd in cryptsetup e2fsck aplay amixer dropbear; do
        cmdp="$(command -v "$cmd")"
        # builtin
        if [ "$cmd" = "$cmdp" ]; then
            continue
        fi
        ldd "$cmdp" | while read a b c d; do
            if [ "$b" = '=>' ]; then
                printf 'file /lib64/%s %s 0755 0 0\n' "${c##*/}" "$c"
            else
                # interpreter
                case "$a" in
                    /*) printf 'file %s %s 0755 0 0\n' "$a" "$a" ;;
                esac
            fi
        done
        printf 'file %s %s 0755 0 0\n' "$cmdp" "$cmdp"
    done
}

gen_dir_ents() {
    while read type target args; do
        printf '%s %s %s\n' "$type" "$target" "$args"
        while [ "${target%/*}" != '' ]; do
            target=${target%/*}
            printf 'dir %s 0755 0 0\n' "$target"
        done
    done
}

gen_depfile() {
    echo "initramfs.img: make" >&3
    while read type target source args; do
        printf '%s %s %s %s\n' "$type" "$target" "$source" "$args"
        if [ "$type" = file ]; then
            echo "initramfs.img: $source" >&3
        fi
    done
}

gen_cpio_list | gen_dir_ents | sort -u | gen_depfile 3>initramfs.d | "${scriptdir}"/gen_init_cpio -t 0 - | xz --x86 --lzma2=preset=9e --check=crc32 -c > initramfs.img

# vim:ft=sh: