On Thu, 16 Feb 2023 19:24:24 +0000
Jon Turney wrote:
> On 14/02/2023 21:21, Takashi Yano via Cygwin-apps wrote:
> > On Tue, 14 Feb 2023 17:41:16 +0100
> > ASSI wrote:
> >> Takashi Yano via Cygwin-apps writes:
> >>> Thanks for the advice. I have revised the cygport file.
> >>
> >> You are getting the file and the hash from the same unprotected source.
> >> I was thinking you should put the hash into the cygport file and hence
> >> the postinstall script.
> >>
> >> Also note that the system doing the postinstall will not necessarily
> >> have internet access, so you'll need to cope with errors that will
> >> produce.
> > 
> > Thanks.
> > 
> > The new cygport file attached downloads md5hash during
> > the packaging process and embeds it into postinstall
> > script. Does this make sense?
> 
> Thanks.
> 
> So, this looks like it works, and meets the requirements.
> 
> Is md5 the only hash available?  This is not really considered "good 
> enough" any more.
> 
> As a thought-experiment, consider doing it slightly differently:
> 
> package contains:
> - the headers
> - a data file with the version (or maybe URL) and hash
> - a script which can fetch (using above data) or remove the DLL
> - postinstall and preremove scripts which invoke that script appropriately
> 
> (I think this means the post/pre scripts can be static, and packaged via 
> $C, rather than written by the cygport itself)
> 
> What do you think of that?

Thanks for the advice!

So, how about this one?

package contains:
- the headers
- the data files with the version and hash
- postinstall and preremove scripts which fetch (using above data)
  and remove the DLL

-- 
Takashi Yano <takashi.y...@nifty.ne.jp>
NAME="openh264"
VERSION=2.3.1
RELEASE=1
CATEGORY="Video"
SUMMARY="H.264 codec library by Cisco"
DESCRIPTION="OpenH264 is a codec library which supports H.264 encoding and 
decoding. It is suitable for use in real time applications such as WebRTC. The 
binary library (runtime) itself will be downloaded from 
http://ciscobinary.openh264.org/";
HOMEPAGE="https://www.openh264.org/";
LICENSE="BSD-2-Clause"
ARCH="noarch" # This is noarch because it's just header files and shell scrpits.

SRC_URI="${NAME}-headers-${VERSION}.tar.xz"

# Make dummy source file for prep if the cleaned one is not exist.
if [ ! -f ${SRC_URI} ]
then
        mkdir ${NAME}-${VERSION}
        touch ${NAME}-${VERSION}/dummy
        tar acf ${SRC_URI} ${NAME}-${VERSION}
        rm -rf ${NAME}-${VERSION}
fi

CYGPORT_USE_UNSTABLE_API=1
src_unpack_hook() {
        if [ $(tar tvf ../../../${SRC_URI} | wc -l)  -eq 2 ] # Source file is 
dummy
        then
                NV=${NAME}-${VERSION}
                pushd ..
                rm -rf ${NV} # Remove dummy source file.
                # Download original source file.
                wget 
https://github.com/cisco/openh264/archive/refs/tags/v${VERSION}.tar.gz
                tar xf v${VERSION}.tar.gz
                rm -f v${VERSION}.tar.gz
                # Make source tarball file which has only necessary header 
files.
                tar acf ../../${NAME}-headers-${VERSION}.tar.xz 
${NV}/codec/api/wels/*.h
                # Update source directory.
                rm -rf ${NV}
                tar xf ../../${NAME}-headers-${VERSION}.tar.xz
                popd
        fi
}
        
PKG_NAMES="libopenh264 libopenh264-headers"
libopenh264_CATEGORY="Video Libs"
libopenh264_CONTENTS="etc/ usr/share/"
libopenh264_REQUIRES="wget bzip2"
libopenh264_SUMMARY="H.264 codec library runtime by Cisco"
libopenh264_headers_CATEGORY="Video Devel"
libopenh264_headers_CONTENTS="usr/include"
libopenh264_headers_SUMMARY="H.264 codec library headers"

src_compile() {
        :
}

src_install() {
        mkdir -p ${D}/usr/include
        ln -fs ${S}/codec/api/wels ${D}/usr/include/.
        # Get license file
        mkdir -p ${D}/usr/share/doc/lib${NAME}
        if ! wget -q http://www.openh264.org/BINARY_LICENSE.txt -O - > 
${D}/usr/share/doc/lib${NAME}/BINARY_LICENSE.txt
        then
                echo "Need internet access!!!"
                exit 1
        fi
        mkdir -p ${D}/etc/lib${NAME}
        # Make sha256 hash
        wget -q 
http://ciscobinary.openh264.org/${NAME}-${VERSION}-win64.dll.bz2 -O - | bunzip2 
| sha256sum | sed "s/-$/${NAME}-${VERSION}-win64.tmp/" > 
${D}/etc/lib${NAME}/${NAME}-${VERSION}-win64.dll.sha256
        wget -q 
http://ciscobinary.openh264.org/${NAME}-${VERSION}-win32.dll.bz2 -O - | bunzip2 
| sha256sum | sed "s/-$/${NAME}-${VERSION}-win32.tmp/" > 
${D}/etc/lib${NAME}/${NAME}-${VERSION}-win32.dll.sha256
        # Make version text
        echo ${VERSION} > ${D}/etc/lib${NAME}/version.txt
        # Install postinstall/preremove scripts
        mkdir -p ${D}/etc/postinstall  ${D}/etc/preremove
        cp ${C}/lib${NAME}.postinstall ${D}/etc/postinstall/lib${NAME}.sh
        cp ${C}/lib${NAME}.preremove ${D}/etc/preremove/lib${NAME}.sh
}
--- origsrc/openh264-2.3.1/CYGWIN-PATCHES/libopenh264.postinstall       
1970-01-01 09:00:00.000000000 +0900
+++ src/openh264-2.3.1/CYGWIN-PATCHES/libopenh264.postinstall   2023-02-17 
12:36:27.633701700 +0900
@@ -0,0 +1,18 @@
+if [ $(uname -m) = "x86_64" ]
+then
+       POSTFIX="win64"
+else
+       POSTFIX="win32"
+fi
+VERSION=$(cat /etc/libopenh264/version.txt)
+cd /tmp
+wget -q http://ciscobinary.openh264.org/openh264-${VERSION}-${POSTFIX}.dll.bz2 
-O - | bunzip2 > openh264-${VERSION}-${POSTFIX}.tmp
+if sha256sum --status -c 
/etc/libopenh264/openh264-${VERSION}-${POSTFIX}.dll.sha256
+then
+       mv openh264-${VERSION}-${POSTFIX}.tmp /usr/bin/libopenh264.dll
+else
+       # Hash mismatch (or failed to download)
+       rm openh264-${VERSION}-${POSTFIX}.tmp
+       exit 1
+fi
+chmod a+x /usr/bin/libopenh264.dll
--- origsrc/openh264-2.3.1/CYGWIN-PATCHES/libopenh264.preremove 1970-01-01 
09:00:00.000000000 +0900
+++ src/openh264-2.3.1/CYGWIN-PATCHES/libopenh264.preremove     2023-02-17 
12:14:05.806697700 +0900
@@ -0,0 +1 @@
+rm /usr/bin/libopenh264.dll

Reply via email to