forked from aix27249/mkpkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkpkg_32to64
executable file
·178 lines (160 loc) · 5.07 KB
/
mkpkg_32to64
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
#!/bin/bash
# This script converts i686 package to x86_64 compat32 package by stripping unneeded files
if [ -z "${MKPKG_DIR}" ]; then
echo "The script starts mkpkg -c64 [package]"
exit
fi
mpkg_cache_dir="/var/mpkg/cache"
# Load global configuration
. /etc/mkpkg.conf
if [ -f "${MKPKG_DIR}/mkpkg_shared_functions" ]; then
. "${MKPKG_DIR}/mkpkg_shared_functions"
else
echo "Error loading shared functions block ${MKPKG_DIR}/mkpkg_shared_functions"
exit 1
fi
PKGLIST="$@"
make_compat32() {
set -e
local pkg_file=$1
if ! [ -f "${pkg_file}" ]; then
show_message FILE_NOT_FOUND "${pkg_file}"
exit 1
fi
PKG_FULLPATH="$(readlink -f ${pkg_file})"
PKGNAME=$(basename "${PKG_FULLPATH}")
# Create working directory
wd=${bt_working_dir}.${USER}/32to64/${PKGNAME}
orig_dir=${wd}/orig
dest_dir=${wd}/dest
rm -rf "${wd}"
mkdir -p "${orig_dir}"
mkdir -p "${dest_dir}"
( cd "${orig_dir}" ; tar -xf "${PKG_FULLPATH}" )
# Copy metadata
mkdir ${dest_dir}/install
cp ${orig_dir}/install/data.xml ${dest_dir}/install/data.xml
pkginfo="$(mkpkg_xml_parser ${dest_dir}/install/data.xml -p)"
tpkgname=`echo ${pkginfo} | cut -d ' ' -f 1`
tpkgver=`echo ${pkginfo} | cut -d ' ' -f 2`
tpkgbuild=`echo ${pkginfo} | cut -d ' ' -f 4`
tpkgarch=`echo ${pkginfo} | cut -d ' ' -f 3`
if [ ${tpkgarch} != "i686" ]; then
show_message INCORRECT_ARCH_PACKAGE "${tpkgarch}" "${PKGNAME}"
exit
fi
# Copy libs
( cd ${orig_dir}
copied_once=0
for i in $(find . -name '*.so') $(find . -name '*.so.*') ; do
dirname=$(dirname $i)
check_dir_whitelist ${dirname} || continue
show_message MOVING "${i}"
mkdir -p ${dest_dir}/$(dirname ${i})
cp -a $i ${dest_dir}/${i}
copied_once=1
done
if [ "${copied_once}" == "0" ] ; then
show_message ERROR_PACKAGE_NO_LIBS
exit 1
fi
)
# Copy ABUILD
orig_abuild=$(basename ${orig_dir}/usr/src/BuildTrees/${tpkgname}-*.build_tree.tar.xz)
dest_abuild=$(echo ${orig_abuild} | sed s/${tpkgname}/${tpkgname}32/g)
if ! [ -f "${orig_dir}/usr/src/BuildTrees/${orig_abuild}" ]; then
show_message FILE_NOT_FOUND "${orig_dir}/usr/src/BuildTrees/${orig_abuild}"
#echo "WARNING: No ABUILD in package"
exit 1
fi
install -Dm0644 "${orig_dir}/usr/src/BuildTrees/${orig_abuild}" "${dest_dir}/usr/src/BuildTrees/${dest_abuild}"
# Check ABUILD
mkdir -p "${wd}/build_tree"
( cd "${wd}/build_tree" ; tar -xf "${orig_dir}/usr/src/BuildTrees/${tpkgname}-${tpkgver}.build_tree.tar.xz" )
. "${wd}/build_tree/ABUILD"
if [ -z "$(echo ${tags} | grep -w 'compat32')" ]; then
show_message ABUILD_NOT_TAG «compat32»
fi
# Do data.xml magic
show_message REPLACING_TAGS
replace_tags
show_message MODIFYING_METADATA
modify_meta
show_message MODIFYING_DEPS
modify_deps
show_message PACKING_BACK
# Package it and move to packages directory
( cd ${dest_dir} ; buildpkg ${package_out_dir}/ )
if [ "${NOT_CLEAR_SOURCE}" != "1" ]; then
show_message DELETE_TEMPORARY_FILES
rm -fr "${wd}"
fi
set +e
}
replace_tags() {
# Modify metadata tags
pkgtags="$(mkpkg_xml_parser ${dest_dir}/install/data.xml -t)"
taglist=
found=0
tagstring="--cleartags "
for tag in ${pkgtags} ; do
#Не понятно зачем вместо первого тега compat32, а не добавляется?
local result="$(echo ${tag} | grep '-' || true)"
if [ -z "${result}" -a "${found}" == 0 ]; then
taglist+=" --add-tag=compat32 "
found=1
else
taglist+=" --add-tag=${tag} "
taglist+=" --add-tag=x86 "
fi
done
tagstring+="${taglist} "
mpkg-setmeta ${dest_dir} ${tagstring}
return 0
}
modify_meta() {
# Set package name
mpkg-setmeta "${dest_dir}" --arch=x86_64 --name=${tpkgname}32
# Clear config files
mpkg-setmeta "${dest_dir}" -F
# Check if provides value exists
provides="$(mkpkg_xml_parser ${dest_dir}/install/data.xml -P)"
if [ "${provides}" != "" ] ; then
mpkg-setmeta "${dest_dir}" --provides=${provides}32
fi
# Check if conflicts value exists
conflicts="$(mkpkg_xml_parser ${dest_dir}/install/data.xml -C)"
if [ "${conflicts}" != "" ] ; then
mpkg-setmeta "${dest_dir}" --conflicts=${conflicts}32
fi
# Add maintainer name and email
mpkg-setmeta "${dest_dir}" --maintainer-name=${mn} --maintainer-email=${me}
return 0
}
modify_deps() {
deps="$(mkpkg_xml_parser ${dest_dir}/install/data.xml -d)"
local depstring="-Z "
for d in ${deps} ; do
newdep_name="$(echo $d | sed 's/[>=<!].*//g')"
newdep_tail="$(echo $d | sed 's/^[^>=<!]*//g')"
set +e
check_deps
local res_check_deps=$?
if [ ${res_check_deps} = 2 ]; then
show_message NOT_ADDED_PACKAGE_DEPS "«${newdep_name}»"
continue
fi
set -e
if [ ${res_check_deps} = 1 ]; then
local depstring+="-d ${newdep_name}${newdep_tail} "
else
local depstring+="-d ${newdep_name}32${newdep_tail} "
fi
done
mpkg-setmeta "${dest_dir}" ${depstring}
return 0
}
# Run stuff
for i in ${PKGLIST} ; do
make_compat32 ${i}
done