Subject: [alpine-devel] [PATCH] new: aports helper scripts

From: Matt Smith <[email-masked]>
Date: Wed, 8 Dec 2010 15:20:21 -0600

I've created some helper scripts for aports, which I'll briefly cover here.

New files:
- aports/apk-aports.conf: configuration file for the following helper scripts
- aports/apkindex.sh:     creates a signed APKINDEX.tar.gz for your aports
- aports/apkwrapper.sh:   apk wrapper that uses your aports repository

Let me know what you think.
---
 apk-aports.conf |   32 ++++++++++++++++++++++++++++++++
 apkindex.sh     |   34 ++++++++++++++++++++++++++++++++++
 apkwrapper.sh   |   22 ++++++++++++++++++++++
 3 files changed, 88 insertions(+), 0 deletions(-)
 create mode 100644 apk-aports.conf
 create mode 100755 apkindex.sh
 create mode 100755 apkwrapper.sh

diff --git a/apk-aports.conf b/apk-aports.conf
new file mode 100644
index 0000000..18aca10
--- /dev/null
+++ b/apk-aports.conf
@@ -0,0 +1,32 @@
+#!/bin/sh
+################################################################################
+# Contributor: Matt Smith <[email-masked]>
+# Maintainer:  Matt Smith <[email-masked]>
+# Description: apk/aports configuration, used by aports helper scripts
+# Version:     2010-12-08T15:01-06:00 (ISO 8601:2004)
+################################################################################
+
+# REMOVE OR COMMENT THE FOLLOWING TWO LINES AND EDIT THE VARIABLES THAT FOLLOW.
+echo -e "Not configured!\nPlease edit ${APK_APORTS_CONF} ..."
+exit 1
+
+#
+# Path to aports directory, no trailing slash
+APORTS_DIR=/home/user/aports
+
+#
+# aport category directories to scan for .apk files, space delimited
+APORTS_CATS="main testing"
+
+#
+# Path to abuild private key
+ABUILD_PRIV_KEY=/home/user/.abuild/user.rsa
+
+#
+# Path to abuild public key
+ABUILD_PUB_KEY=/etc/apk/keys/user.rsa.pub
+
+
+# DO NOT EDIT BEYOND THIS POINT
+APORTS_APKINDEX="${APORTS_DIR}/APKINDEX.tar.gz"
+APORTS_REPOFILE="${APORTS_DIR}/APKREPO"
diff --git a/apkindex.sh b/apkindex.sh
new file mode 100755
index 0000000..44ebcc3
--- /dev/null
+++ b/apkindex.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+################################################################################
+# Contributor: Matt Smith <[email-masked]>
+# Maintainer:  Matt Smith <[email-masked]>
+# Description: aports helper script: creates a signed APKINDEX.tar.gz and
+#              APKREPO file for use with apk or aports/apkwrapper.sh
+# Usage:       apkindex.sh
+# Version:     2010-12-08T14:52-06:00 (ISO 8601:2004)
+################################################################################
+
+# Get configuration:
+APK_APORTS_CONF_NAME="apk-aports.conf"
+if [ "${0:0:2}" == "./" ]; then
+	APK_APORTS_CONF="./${APK_APORTS_CONF_NAME}"
+else
+	APK_APORTS_CONF="`echo $0 | \
+		sed -r "s;^(/.*)/[^/]+;\1/${APK_APORTS_CONF_NAME};"`"
+fi
+source $APK_APORTS_CONF
+
+# Create APKINDEX.tar.gz for aports
+APORTS_CAT_DIRS=""
+for APORTS_CAT in $APORTS_CATS; do
+	APORTS_CAT_DIRS="${APORTS_CAT_DIRS} ${APORTS_DIR}/${APORTS_CAT}/*/*.apk"
+done
+apk index -o $APORTS_APKINDEX ${APORTS_CAT_DIRS:1}
+
+# Sign the aports APKINDEX.tar.gz
+abuild-sign -k $ABUILD_PRIV_KEY -p $ABUILD_PUB_KEY $APORTS_APKINDEX
+
+# Create aports APKREPO to use like:
+#   apk --repositories-file $APKREPO add $APORTS_PKG
+#   (This is the purpose of aports/apkwrapper.sh)
+echo "${APORTS_DIR}/" > $APORTS_REPOFILE
diff --git a/apkwrapper.sh b/apkwrapper.sh
new file mode 100755
index 0000000..306328e
--- /dev/null
+++ b/apkwrapper.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+################################################################################
+# Contributor: Matt Smith <[email-masked]>
+# Maintainer:  Matt Smith <[email-masked]>
+# Description: aports helper script: apk wrapper that uses the signed
+#              APKINDEX.tar.gz and APKREPO files generated by aports/apkindex.sh
+# Example Use: apkwrapper.sh add /path/to/aports/main/package/package-0.1-r0.apk
+# Version:     2010-12-08T15:08-06:00 (ISO 8601:2004)
+################################################################################
+
+# Get configuration:
+APK_APORTS_CONF_NAME="apk-aports.conf"
+if [ "${0:0:2}" == "./" ]; then
+	APK_APORTS_CONF="./${APK_APORTS_CONF_NAME}"
+else
+	APK_APORTS_CONF="`echo $0 | \
+			sed -r "s;^(/.*)/[^/]+;\1/${APK_APORTS_CONF_NAME};"`"
+fi
+source $APK_APORTS_CONF
+
+# Invoke apk using the aports repository file
+apk --repositories-file $APORTS_REPOFILE $*
-- 
1.7.3.2

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---

---

From: Natanael Copa <[email-masked]>
Date: Thu, 09 Dec 2010 14:40:32 +0100

> Let me know what you think.

I'm not really sure what problem those scripts are supposed to solve?

-nc

---

---

From: "Matt Smith" <[email-masked]>
Date: Thu, 9 Dec 2010 09:41:50 -0600 (CST)

> I'm not really sure what problem those scripts are supposed to solve?

The idea is to make it easier/quicker to be able to install a package from aports (for testing, etc).

It's my understanding and experience that you can't simply "abuild -r; apk add ./package.apk", atleast without specifying --no-network to apk, but that seems to be a 'global option' instead of being per-package.

I suppose its no different though: doing --no-network, or specifying a specific local repository (atleast without HTTP repositories added into the mix?).

Ideally, I'd like to be able to "abuild -r; apk add ./package.apk" and have apk resolve dependencies either via /etc/apk/repositories (HTTP and/or local repos), or abuild the dependencies in aports instead, similar to FreeBSD ports, if I'm not mistaken.

Apologies if this is already possible.

Thanks in advance,
Matt

P.S.: Looks like I could use some form of "abuild -ri".

---

---

From: Natanael Copa <[email-masked]>
Date: Thu, 09 Dec 2010 17:03:57 +0100

> from aports (for testing, etc).

ah. I yes.

What i do is adding $HOME/.cache/apks first in /etc/apk/repositories

then i do:

abuild -r && apk add $package

if there are additional http repos in /etc/apk/repositories you can pick
some from local aports tree and some from network (to avoid build
everything)

> It's my understanding and experience that you can't simply "abuild -r;
> apk add ./package.apk", atleast without specifying --no-network to
> apk, but that seems to be a 'global option' instead of being
> per-package.

I think apk add ./package.apk is supposed to work but is buggy.

> I suppose its no different though: doing --no-network, or specifying a
> specific local repository (atleast without HTTP repositories added
> into the mix?).
> 
> Ideally, I'd like to be able to "abuild -r; apk add ./package.apk" and
> have apk resolve dependencies either via /etc/apk/repositories (HTTP
> and/or local repos), or abuild the dependencies in aports instead,
> similar to FreeBSD ports, if I'm not mistaken.
> 

np. and you are right. we could improve this.

---

---

From: "Matt Smith" <[email-masked]>
Date: Thu, 9 Dec 2010 10:30:51 -0600 (CST)

> some from local aports tree and some from network (to avoid build

Thanks, I'll try it out.  BTW, you do mean "apk add package" (without version and .apk), right?

>> apk add ./package.apk", at least without specifying --no-network to

I actually worked on this, adding "char *filename" to the apk_dependency struct, passing it the filename from argv in add.c and then, I think in apk_state_lock_dependency() or somewhere else in state.c, passed it to the relevant apk_package struct so when it came time to check the relevant package->filename, it wasn't NULL and should have done something similar to --no-network, but it bombs out in the end saying "BAD signature", which is where I decided to give up and write those scripts instead. :o

- Matt

---

---

From: Natanael Copa <[email-masked]>
Date: Thu, 9 Dec 2010 21:18:12 +0000

On Thu, 9 Dec 2010 10:30:51 -0600 (CST)

> version and .apk), right?

yes

> >> It's my understanding and experience that you can't simply "abuild
> >> -r; apk add ./package.apk", at least without specifying
> >> --no-network to apk, but that seems to be a 'global option'
> >> instead of being per-package.
> > 
> I actually worked on this, adding "char *filename" to the
> apk_dependency struct, passing it the filename from argv in add.c and
> then, I think in apk_state_lock_dependency() or somewhere else in
> state.c, passed it to the relevant apk_package struct so when it came
> time to check the relevant package->filename, it wasn't NULL and
> should have done something similar to --no-network, but it bombs out
> in the end saying "BAD signature", which is where I decided to give
> up and write those scripts instead. :o

I think it works as long there are no exact same version available in
index.

could you please create an issue for i on bugs.alpinelinux.org if its
not there already?

i think timo is aware of it and it will be fixed eventually but it
might be good to have it in the bug tracker as a known bug for others.

thanks

-nc

---

---

From: "Matt Smith" <[email-masked]>
Date: Thu, 9 Dec 2010 21:42:28 -0600 (CST)

> I think it works as long there are no exact same version available in

Yep, you are right.

> might be good to have it in the bug tracker as a known bug for others.

Ok, I've reported it just now here:
http://redmine.alpinelinux.org/issues/492

And it links back to this mailing list thread.  Also, I can update the wiki accordingly later on.

Thanks,
Matt

---

---

From: Jeremy Thomerson <[email-masked]>
Date: Thu, 9 Dec 2010 10:28:30 -0600

If it is not, can we get how to do this added to the wiki on the page about
building aports ?

Jeremy Thomerson
-- sent from my "smart" phone, so please excuse spelling, formatting, or
compiler errors

On Dec 9, 2010 10:04 AM, "Natanael Copa" <[email-masked]> wrote:

On Thu, 2010-12-09 at 09:41 -0600, Matt Smith wrote:
> On Thursday, December 9, 2010 7:40am, "Natana...
ah. I yes.

then i do:

> apk add ./package.apk",...

> specific local reposito...

> P.S.: Looks like I could use some form of "abuild -ri".

-...

---

From: Cameron Banta <[email-masked]>
Date: Thu, 09 Dec 2010 10:41:36 -0600

On 12/09/2010 10:28 AM, Jeremy Thomerson wrote:
>
> If it is not, can we get how to do this added to the wiki on the page 
> about building aports ?
>
Just to add my $0.02, I find it much more useful to dump the apks into a 
directory that's exported by a web server. Then you can put that url in 
the /etc/apt/repositories (before the edge urls) of a second testing box 
- now when you install and test packages it won't affect your aports dev 
box.

You can edit REPODEST in /etc/abuild.conf to put the compiled packages 
somewhere else (I use /srv/apks). Then I use nginx to serve them to my 
other alpine test boxes. Another, probably better, option is to just 
link ~/.cache/apks to /srv/apks. (The last option will automatically 
create your APKINDEX for you.)

-Cameron

> Jeremy Thomerson
> -- sent from my "smart" phone, so please excuse spelling, formatting, 
> or compiler errors
>
>> On Dec 9, 2010 10:04 AM, "Natanael Copa" <[email-masked] 
>> <mailto:[email-masked]>> wrote:
>>

---

From: Natanael Copa <[email-masked]>
Date: Thu, 9 Dec 2010 21:21:38 +0000

On Thu, 9 Dec 2010 10:28:30 -0600

> If it is not, can we get how to do this added to the wiki on the page

yes, I agree that it would be good to have it documented properly.

It is a wiki ;)

-nc

---