This repository has been archived by the owner on May 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·128 lines (119 loc) · 3.26 KB
/
build.sh
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
#!/bin/bash
# minimal-initramfs by owenthewizard
# build.sh - copy files and directory structure for initramfs
source initramfs.conf
copy_files()
{
local counter=0
declare -a needed
while read -r line; do
copy_prog "${line}" || needed[$counter]="${line}"
((counter++))
done < hooks/"${1}".files
if [[ -n "${needed[*]}" ]]; then
printf "These files need to be supplied to initramfs/ manually:\n"
echo "${needed[@]}" | tr ' ' '\n'
echo
fi
}
copy_prog()
{
path="${1#usr/}"
path="${path%/*}"
prog="${1##*/}"
if ( ldd "/${1}" &> /dev/null ); then
for lib in $(ldd "/${1}" | grep -F /lib | cut -d'(' -f1 | cut -d'>' -f2); do
cp -Ln "${lib}" "initramfs/lib64/"
#chmod 755 "initramfs${lib}"
done
fi
cp -L "/${1}" "initramfs/${path}/${prog}" 2> /dev/null || return 1
#chmod 755 "initramfs/${path}/${prog}"
}
printf "Creating directories...\n"
echo
mkdir -p initramfs/{bin,dev,etc/terminfo/l,lib64,mnt/root,proc,root,sbin,sys}
for hook in ${hooks[@]}; do
case "${hook}" in
base) printf "Adding hook: base\n\n"
cp -r hooks/base/* initramfs/
copy_files "base";;
extra) printf "Adding hook: extra\n\n"
copy_files "extra";;
luks) printf "Adding hook: luks\n\n"
header_uuid=""
if [[ -f "${detached_header}" ]]; then
cp "${detached_header}" initramfs/luks.header
echo 'detached_header=/luks.header' >> initramfs/functions.sh
elif [[ -b "${detached_header}" ]]; then
header_uuid="$(blkid ${detached_header} -o export -s UUID | grep -Eo '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}')"
echo 'detached_header="$(findfs UUID='"${header_uuid}"')"' >> initramfs/functions.sh
fi
copy_files "luks";;
fsck) printf "Adding hook: fsck\n\n"
copy_files "fsck"
(cd initramfs/sbin/ && ln -s e2fsck fsck.ext2
ln -s e2fsck fsck.ext3
ln -s e2fsck fsck.ext4);;
mdev) printf "Adding hook: mdev\n\n"
copy_files "mdev";;
colors) printf "Adding hook: colors\n\n"
copy_files "colors"
if [[ -n "${font}" ]]; then
cp "${font}" initramfs/etc/font
fi;;
esac
printf "Regenerating init functions...\n"
echo
grep -Ev '^$|^#' hooks/"${hook}.hook" >> initramfs/functions.sh 2> /dev/null
done
printf "Adding missing functions to init...\n"
if [[ ! " ${hooks[*]} " =~ " colors " ]]; then
cat >> initramfs/functions.sh <<EOF
print_info()
{
printf "${1}\n"
}
print_error()
{
printf "${1}\n"
}
print_warn()
{
printf "${1}\n"
}
EOF
fi
if [[ ! " ${hooks[*]} " =~ " mdev " ]]; then
cat >> initramfs/functions.sh <<EOF
task_mdev()
{
return 0
}
EOF
fi
if [[ ! " ${hooks[*]} " =~ " luks " ]]; then
cat >> initramfs/functions.sh <<EOF
task_luks()
{
return 0
}
EOF
fi
if [[ ! " ${hooks[*]} " =~ " fsck " ]]; then
cat >> initramfs/functions.sh <<EOF
task_fsck()
{
return 0
}
EOF
fi
if [[ ! " ${hooks[*]} " =~ " colors " ]]; then
cat >> initramfs/functions.sh << EOF
set_font()
{
return 0
}
EOF
fi
printf "To finish generating your initramfs run package.sh\n"