[go: up one dir, main page]

Menu

[r5]: / trunk / apkfuncs.sh  Maximize  Restore  History

Download this file

265 lines (231 with data), 6.2 kB

  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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/bin/sh
# apk functions
# if the config file exist, read it
[ -f /etc/apk.conf ] && . /etc/apk.conf
# Set some defaults
ROOT=${ROOT-/}
PKGMETA="var/lib/apkdb"
APKDB=`echo "${ROOT}/${PKGMETA}" | sed 's://:/:g'`
OLDPWD=`pwd`
# set apklibs if not alread set
[ -z "$APKLIBS" ] && APKLIBS="/lib/apk"
#listfile=${APKDB}/${pkg}.list
#sha1file=${APKDB}/${pkg}.sha1
#metaball="${APKDB}/${pkg}.meta.tar.gz"
###########################################################
# error echo. echo to stderr
eecho() {
echo $* >&2
}
beautify_path() {
echo $1 | sed 's:/\./::g; s://:/:g'
}
###########################################################
# create sha1 sum of package files
create_sha1sum() {
local sha1file listfile opwd
opwd=`pwd`
listfile=${APKDB}/${1}.list
sha1file=${APKDB}/${1}.sha1
cd ${ROOT}
rm -f ${sha1file}
while read i ; do
[ -f ${i} ] && sha1sum ${i} >> ${sha1file}
done < ${listfile}
cd $opwd
}
###########################################################
# Create sha1 sum of config files
create_config_sha1sum() {
local sha1file listfile opwd
opwd=`pwd`
listfile=${APKDB}/${1}.config
# if there is no config file, just return
[ ! -f $listfile ] && return
sha1file=${APKDB}/${1}.cfg.sha1
cd ${ROOT}
rm -f ${sha1file}
while read i ; do
[ -f ${i} ] && sha1sum ${i} >> ${sha1file}
done < ${listfile}
cd $opwd
}
###########################################################
# Get description
get_description() {
local opwd
opwd=`pwd`
local pkgv
cd ${APKDB}
pkgv=$1
tar -zxf ${pkgv}.meta.tar.gz -O ${pkgv}.control \
| grep ^Description | sed 's/^.*: //'
cd $opwd
}
###########################################################
# all installed packages with description
all_installed_with_desc() {
local opwd
opwd=`pwd`
cd ${APKDB}
for i in *.meta.tar.gz ; do
pkgv=`basename $i .meta.tar.gz`
echo -n -e "$pkgv\t"
echo `get_description ${pkgv}`
done
cd $opwd
}
##########################################################
# All installed pacages
all_installed() {
local opwd pkgv i
opwd=`pwd`
cd ${APKDB}
for i in *.meta.tar.gz ; do
pkgv=`basename $i .meta.tar.gz`
echo "$pkgv"
done
cd $opwd
}
##########################################################
# is package installed?
is_installed() {
local pkg=$1
all_installed | grep '^${pkg}-[0-9].*'
}
###########################################################
# Display the Control Meta file
get_control() {
local pkgv opwd
opwd=`pwd`
cd ${APKDB}
pkgv=$1
tar -zxf ${pkgv}.meta.tar.gz -O ${pkgv}.control
cd $opwd
}
###########################################################
# get the package name and versions
get_installed_pkgv() {
local opwd metafile
opwd=`pwd`
cd ${APKDB}
# possible bug: if there are more than one version installed,
# we might get problem here...
metafile=`ls ${1}[\-0-9]*.meta.tar.gz 2>/dev/null`
# if metafile dont exist, return empty
[ -z $metafile ] && return
echo `basename $metafile .meta.tar.gz`
cd $opwd
}
###########################################################
decompress_meta() {
local metafile
metafile=${APKDB}/${1}.meta.tar.gz
if [ ! -f $metafile ] ; then
eecho "$1 does not seem to be installed. Did you specify version? Aborting."
exit 1
fi
tar -C $APKDB -zxf $metafile
}
############################################################
compress_meta() {
local opwd metaball pkgv1
opwd=`pwd`
pkgv=$1
metaball="${APKDB}/${pkgv}.meta.tar.gz"
cd $APKDB
rm -f ${metaball}
metas=`ls ${pkgv}.*`
if [ -z "$metas" ] ; then
eecho "No meta files were found. Aborting."
exit 1
fi
tar -czf ${metaball} ${metas}
rm ${metas}
cd $opwd
}
############################################################
pkg_listfiles() {
local opwd pkgv
opwd=`pwd`
pkgv=$1
cd ${APKDB}
tar -zxf ${pkgv}.meta.tar.gz -O ${pkgv}.list
cd $opwd
}
############################################################
pkg_check() {
local pkgv opwd
opwd=`pwd`
pkgv=$1
decompress_meta $pkgv
cd ${ROOT}
sha1sum -c ${APKDB}/${pkgv}.sha1
compress_meta $pkgv
cd $opwd
}
############################################################
# funcs for mounting/umounting local media
# note that is a Method is to be classified as "local media" it has to be
# specified in /etc/fstab and have a mount point in /media/
# mounts a "cdrom:/pkgs/file" style URI and echos the "/media/cdrom/pkgs/file"
get_media_type() {
echo $1 | sed 's|:/.*||'
}
############################################################
# this func should not be called in a subshell since it sets
# some global vars.
# ideas on how to solve this better is warmly welcome. /NC
media_mount() {
MEDIA=`get_media_type $1`
MEDIA_WAS_MOUNTED=`mount | grep /media/$MEDIA`
if [ -z "$MEDIA_WAS_MOUNTED" ] ; then
mount "/media/$MEDIA" || exit 1
fi
}
############################################################
# this function depends on global var MEDIA
get_mounted_path() {
echo $1 | sed 's|^.*:/|/media/'$MEDIA'/|'
}
############################################################
# this function depends on globals MEDIA and MEDIA_WAS_MOUNTED
media_umount() {
if [ -z "$MEDIA_WAS_MOUNTED" ] ; then
umount "/media/$MEDIA" || exit 1
fi
}
############################################################
# This func examine the APK_PATH variable and loads the repository module
load_repmod() {
local reptype repmod
# just check for debugging
if [ $rflag != "on" ] ; then
eecho "-r was not specified. Contact developer of apk-tools."
exit 1
fi
if [ -z "$APK_PATH" ] ; then
eecho "Please set the APK_PATH variable."
exit 1
fi
reptype=`echo $APK_PATH | cut -f 1 -d ':'`
repmod=$APKLIBS/$reptype.repmod
if [ -f $repmod ] ; then
. $repmod
else
eecho "Repository type $reptype is not supported. Sorry..."
exit 1
fi
}
###################################################3
# get dependencies from a .apk file
get_depend() {
local pkgf opwd i ctlfile
opwd=`pwd`
pkgf=$1
pkgv=`basename $1 .apk`
for i in `tar -zxf ${pkgf} -O ./${PKGMETA}/${pkgv}.control | grep ^Depend: | cut -d : -f 2` ; do
echo $i | grep 'virtual' > /dev/null && eecho "Warning: virtual dependency: $i"
echo $i | sed 's:^.*/::' | sed 's/-[0-9].*$//'
done
}