chroot_deps 1.21 KB
Newer Older
HUC Stéphane's avatar
HUC Stéphane committed
1
2
3
4
#!/bin/sh
#set -x
set -e -u

HUC Stéphane's avatar
HUC Stéphane committed
5
### 2020/05/25 18:35
HUC Stéphane's avatar
HUC Stéphane committed
6
# chroot_deps: cmp needed binaries between sys and chroot web. 
HUC Stéphane's avatar
HUC Stéphane committed
7
8
#  v6.7: libc.so.96.0
#  v6.6: libc.so.95.1
HUC Stéphane's avatar
HUC Stéphane committed
9
10
11
12
13
14
15
##
# find /var/www/usr/ -type f | while read ligne ; do cmp ${ligne##/var/www} ${ligne} || cp ${ligne##/var/www} ${ligne} ; done
#
###
chroot="/var/www"

bins='cat date sh sha256'
HUC Stéphane's avatar
HUC Stéphane committed
16
usrbins='basename logger stat'
HUC Stéphane's avatar
HUC Stéphane committed
17
libs='libc.so.96.0'
HUC Stéphane's avatar
HUC Stéphane committed
18
19
20
21
22
23
libexecs='ld.so'

check_file() {
	local dir="$1"
	local file="${chroot}${dir}/${bin}"
	if [ ! -f "${file}" ]; then 
HUC Stéphane's avatar
HUC Stéphane committed
24
		logger "$0: file '$file' not exists, do a copy into chroot: '$chroot'!"
HUC Stéphane's avatar
HUC Stéphane committed
25
26
		_cp "${dir}/${bin}"
	else
HUC Stéphane's avatar
HUC Stéphane committed
27
		if cmp -s "${dir}/${bin}" "${file}"; then _cp "${dir}/${bin}"; fi
HUC Stéphane's avatar
HUC Stéphane committed
28
29
30
31
32
33
	fi
}

_cp() {
	local src="$1"
	local dest="${chroot}${src}"
HUC Stéphane's avatar
HUC Stéphane committed
34
35
	if [ -n "${src:+bin}" ]; then mode=555; fi
	if [ -n "${src:+lib}" ]; then mode=444; fi
HUC Stéphane's avatar
HUC Stéphane committed
36
	if install -o root -g bin -m "${mode}" "${src}" "${dest}"; then 
HUC Stéphane's avatar
HUC Stéphane committed
37
		logger "$0: copied dependency '$src' to '$dest'!"
HUC Stéphane's avatar
HUC Stéphane committed
38
	else
HUC Stéphane's avatar
HUC Stéphane committed
39
		logger "$0: Can not copy dependency '$src' to '$chroot'!"
HUC Stéphane's avatar
HUC Stéphane committed
40
41
42
43
44
45
46
47
48
49
50
51
52
	fi
}

main() {
	
	for bin in $bins; do check_file "/bin"; done
	for bin in $usrbins; do check_file "/usr/bin"; done
	for bin in $libs; do check_file "/usr/lib"; done
	for bin in $libexecs; do check_file "/usr/libexec"; done
	
}

main