Magellan Linux

Annotation of /trunk/mage/usr/lib/mage/meta-generator.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2367 - (hide annotations) (download) (as text)
Mon Jan 6 13:28:00 2014 UTC (10 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 4721 byte(s)
-split meta data and content data to seperate files into a dir named PKGMETADIR
1 niro 2287 #!/bin/bash
2     # meta generator
3    
4     # metafile matrix
5    
6     # Common infos -> meta
7     # ----------------------------
8     # lineno description example
9     # 01 PNAME glibc-nptl
10     # 02 PCATEGORIE sys-libs
11     # 03 PVER 2.5.0
12     # 04 PBUILD 7
13     # 05 STATE unstable
14     # 06 DESCRIPTION GNU libc6 (also called glibc2) C library with NPTL Threads.
15     # 07 HOMEPAGE http://www.gnu.org/software/libc/libc.html
16     # 08 PKGTYPE
17     # 09 SPLIT_PACKAGE_BASE
18     # 10 INHERITS mtools
19     #
20     # # Arch specific -> ${arch}/desc
21     # ----------------------------
22     # lineno description example
23     # 1 MD5 7ba206976e312a456dc29cea4bb283ea
24     # 2 SIZE
25     # 3 MTIME 1187714117
26     #
27     # Dependencies
28     # ---------------------------------
29     # DEPEND -> ${ARCH}/depend
30     # SDEPEND -> ${ARCH}/sdepend
31     # PROVIDE -> ${ARCH}/provide
32     #
33     # # Content
34     # ---------------------------------
35     # CHAR -> ${ARCH}/char
36     # DIRS -> ${ARCH}/dirs
37     # FILES -> ${ARCH}/files
38     # PIPES -> ${ARCH}/pipes
39     # SYMLINKS -> ${ARCH}/symlinks
40    
41     # --extract -> extract info from given package
42     # no params given/smage2, it uses the current build environment
43    
44    
45     # default die function
46     die()
47     {
48     echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT}
49     echo -e ${COLRED}"$@"${COLDEFAULT}
50     exit 1
51     }
52    
53     add2meta()
54     {
55     local var="$1"
56     local value="$2"
57    
58 niro 2366 echo "${var}=\"${value}\"" >> ${PKGMETAFILE}
59 niro 2287 }
60    
61     ## only for tests -> normally in /etc/rc.d/init.d/functions
62     COLRED="\033[1;6m\033[31m"
63     COLGREEN="\033[1;6m\033[32m"
64     COLYELLOW="\033[1;6m\033[33m"
65     COLBLUE="\033[1;6m\033[34m"
66     COLMAGENTA="\033[1;6m\033[35m"
67     COLWHITE="\033[1;6m\033[37m"
68     COLGRAY="\033[0;6m\033[37m"
69     COLBOLD="\033[1m"
70     COLDEFAULT="\033[0m"
71    
72     # get mage environment
73     [ -f /etc/mage.rc.global ] && source /etc/mage.rc.global || die "/etc/mage.rc.global missing"
74     [ -f ${MAGERC} ] && source ${MAGERC} || die "Your ${MAGERC} is missing. Aborting."
75     [ -f ${MLIBDIR}/mage4.functions.sh ] && source ${MLIBDIR}/mage4.functions.sh || die "mage functions missing"
76 niro 2290 [ -f ${MLIBDIR}/smage2.functions.sh ] && source ${MLIBDIR}/smage2.functions.sh || die "mage functions missing"
77 niro 2287
78     # default variables
79     PKGTARBALL=""
80     SMAGEFILE=""
81     METADIR="${PKGDIR}/meta"
82     METASUFFIX="meta"
83 niro 2367 PKGMETADIR=""
84 niro 2366 PKGMETAFILE=""
85 niro 2287
86     # very basic getops
87     for i in $*
88     do
89     case $1 in
90     --extract|-c) shift; PKGTARBALL="$1" ;;
91     esac
92     # shift
93     done
94    
95     SMAGEFILE="$1"
96 niro 2288 [ -z ${SMAGEFILE} ] && die "No smage file given."
97     [ -e ${SMAGEFILE} ] || die "Smage file '${SMAGEFILE}' does not exist."
98 niro 2287
99 niro 2296 # load mage-features
100     load_mage_features
101    
102 niro 2287 if [[ -n ${PKGTARBALL} ]]
103     then
104     # abort if given file is not a pkg
105     [[ ${PKGTARBALL##*.} != ${PKGSUFFIX} ]] && die "${PKGTARBALL} is not a valid pkg file."
106    
107     [[ ! -d ${SOURCEDIR} ]] && install -d ${SOURCEDIR}
108    
109     # unpack srctarball
110     [[ ! -f ${PKGTARBALL} ]] && die "Error: ${PKGTARBALL} does not exist. Aborting."
111    
112     # set correct SMAGENAME; use the one that the src_pkg provide
113     # /path/to/SOURCEDIR/PNAME/SMAGENAME
114     SMAGEFILE="${SOURCEDIR}/$(basename ${PKGTARBALL%-*-*})/$(basename ${PKGTARBALL} .${PKGSUFFIX}).${SMAGESUFFIX}"
115    
116     tar xvjf ${SRCPKGTARBALL} -C ${SOURCEDIR} || die "Error unpackung src-tarball ${SRCPKGTARBALL}"
117     fi
118    
119     # get generic package information from smage file
120 niro 2289 smagesource ${SMAGEFILE}
121 niro 2287
122 niro 2295 PKGNAME="${PNAME}-${PVER}-${PBUILD}"
123     ARCHPKGNAME="${PNAME}-${PVER}-${ARCH}$(print_distrotag)-${PBUILD}"
124    
125 niro 2287 # set the right meta-location
126 niro 2367 PKGMETADIR="${METADIR}/${ARCHPKGNAME}"
127     PKGMETAFILE="${METADIR}/${ARCHPKGNAME}/${METASUFFIX}"
128    
129 niro 2287 [[ ! -d ${METADIR} ]] && install -d ${METADIR}
130 niro 2367 [[ ! -d ${PKGMETADIR} ]] && install -d ${PKGMETADIR}
131 niro 2287
132     # create a clean metafile
133 niro 2366 :> ${PKGMETAFILE}
134 niro 2287
135     # basic packages information
136     add2meta PNAME "${PNAME}"
137 niro 2292 if [[ -n ${PCATEGORIE} ]]
138     then
139     PCAT="${PCATEGORIE}"
140     fi
141     add2meta PCAT "${PCAT}"
142 niro 2287 add2meta PVER "${PVER}"
143     add2meta PBUILD "${PBUILD}"
144     #add2meta STATE "${STATE}"
145     add2meta DESCRIPTION "${DESCRIPTION}"
146     add2meta HOMEPAGE "${HOMEPAGE}"
147     add2meta PKGTYPE "${PKGTYPE}"
148 niro 2293 add2meta SPLIT_PACKAGE_BASE "${SPLIT_PACKAGE_BASE}"
149     add2meta INHERITS "${INHERITS}"
150 niro 2287
151     # arch specific
152     add2meta ARCH "${ARCH}"
153 niro 2291 add2meta SIZE "$(du -Ds ${BUILDDIR}/${ARCHPKGNAME}/binfiles | sed 's/^\(.*\)\t.*/\1/')"
154     add2meta MTIME "$(< ${BUILDDIR}/${ARCHPKGNAME}/.mtime)"
155 niro 2287
156     # provided binfiles
157     SEARCH_DIRS="bin,sbin,usr/bin,usr/sbin"
158     SEARCH_DIRS+=",usr/*/bin,usr/*/sbin"
159     SEARCH_DIRS+=",opt/bin,opt/*/bin,opt/*/sbin"
160     SEARCH_DIRS+=",opt/*/jre/bin"
161     # at last add braces
162 niro 2367 #SEARCH_DIRS="{${SEARCH_DIRS}}"
163 niro 2287 # search them
164 niro 2367 #add2meta PROVIDED_BINARIES "$(find $(eval echo ${BUILDDIR}/${ARCHPKGNAME}/binfiles/${SEARCH_DIRS}) -type f -printf '%f ' 2> /dev/null)"
165     # generate MD5SUM (get it with tail -n1)
166     add2meta PKG_CHECKSUM_MD5 "$(cd ${PKGDIR}; md5sum ${ARCHPKGNAME}.${PKGSUFFIX} | cut -d' ' -f1 )"
167 niro 2287
168 niro 2367 # generate content file
169     find ${BINDIR} | sed "s:${BINDIR}::g;/^$/d" | sort -d > ${PKGMETADIR}/content