-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-pkgs
executable file
·146 lines (122 loc) · 3.03 KB
/
install-pkgs
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
#!/bin/sh -eu
. $BULB_SH_UTILS
usage() {
echo "
Usage: ${0##*/} [options] package[-]...
If a hyphen (-) is appended to the package name (with no intervening space), the identified package will not be installed.
options:
-a The package architecture
-r The installation root directory
-h Print this help and exit
"
}
fix_broken_link() {
l_link=$1
l_root_dir=$2
l_target=$(readlink $l_link)
echo $l_target |grep -q '^/' || {
bark Unable to fix link $l_link -> $l_target
return
}
l_new_target=$(echo $l_target |sed "s%^/%$l_root_dir/%g")
ln -srf $l_new_target $l_link
}
fix_broken_links() {
l_root_dir=$1
find "$l_root_dir" -xtype l -print |while read -r broken_link; do
fix_broken_link $broken_link $l_root_dir
done
}
# Usage: ignore_dependencies deb_cache_dir package...
ignore_dependencies() {
l_deb_cache=${1:-}
[ -n "$l_deb_cache" ] || croak The deb cache path parameter is missing
[ -d "$l_deb_cache" ] || croak $l_deb_cache is not a directory
shift
cd $l_deb_cache
[ -d archives ] || install -d archives
cd archives
for l_dep in $*; do
l_dep_version=$(apt-cache show $l_dep |sed -n 's/Version: \(.*\)/\1/p')
equivs-control $l_dep.control
sed -i -e "s/<package name; defaults to equivs-dummy>/$l_dep/g" \
-e "s/# Version: <enter version here; defaults to 1.0>/Version: $l_dep_version/g" $l_dep.control
equivs-build $l_dep.control >/dev/null 2>&1
dpkg -i ${l_dep}_${l_dep_version}_all.deb >/dev/null
rm $l_dep.control
done
}
root_dir=
arch=
while getopts 'a:r:h' opt; do
case $opt in
a)
arch=$OPTARG
;;
r)
root_dir=$OPTARG
;;
h)
usage
exit
;;
*)
usage
exit 1
;;
esac
done
[ -n "$arch" ] || {
usage
exit 1
}
shift $((OPTIND - 1))
[ $# -gt 0 ] || {
usage
exit 1
}
root_dir=${root_dir:-$(mktemp -d)}
root_dir=$(get_absolut_path($root_dir))
[ -d "$root_dir" ] || install -d $root_dir 2>/dev/null || echo $root_dir is not a directory
cd "$root_dir"
dpkg_backup=$(mktemp -d)
mv /var/lib/dpkg $dpkg_backup
if [ -d "$root_dir/var/lib/dpkg" ]; then
cp -r "$root_dir/var/lib/dpkg" /var/lib/dpkg
else
rm -rf /var/lib/dpkg
mkdir -p /var/lib/dpkg/info
touch /var/lib/dpkg/status
fi
echo $arch >>/var/lib/dpkg/arch
ignore=
install=
for deb in $*; do
case $deb in
*-)
ignore=${ignore:+$ignore }${deb%%-}
;;
*)
install=${install:+$install }$deb
;;
esac
done
deb_cache=$(mktemp -d)
install -d $deb_cache
ignore_dependencies $deb_cache $ignore
apt-get -q=2 update -o=APT::Architecture=$arch
apt-get -q=2 --fix-broken install -o=APT::Architecture=$arch -y --allow-remove-essential
apt-get -q=2 install --download-only -o=dir::cache=$deb_cache -o=APT::Architecture=$arch -y --no-install-recommends $install
apt-get -q=2 clean
install -d "$root_dir"
for f in $deb_cache/archives/*.deb; do
dpkg -x $f "$root_dir" >/dev/null;
done
fix_broken_links "$root_dir"
dpkg --record-avail -R $deb_cache/archives >/dev/null
rm -rf "$root_dir/var/lib/dpkg"
install -d "$root_dir/var/lib"
mv /var/lib/dpkg "$root_dir/var/lib"
mv $dpkg_backup/dpkg /var/lib
rm -rf $dpkg_backup $deb_cache
echo $root_dir