diff options
author | Daniel Drake <dsd@laptop.org> | 2011-05-16 19:38:02 (GMT) |
---|---|---|
committer | Daniel Drake <dsd@laptop.org> | 2011-05-16 20:25:20 (GMT) |
commit | da680b0bde03a16ae824fffa228ae42822be0686 (patch) | |
tree | fb1e5f2c8340ed1daf8554534b933f40a4d1589f | |
parent | d614daeee5330bdc1de78394a89c873b497f9d19 (diff) |
Install sugar bundles using sugar-install-bundle (#10427)
Also improves consistency between the 3 bundle-fetching modules.
Based on work by Jerry Vonau.
-rw-r--r-- | lib/ooblib.py | 19 | ||||
-rw-r--r-- | lib/shlib.sh | 18 | ||||
-rw-r--r-- | modules/sugar/kspost.80.install_bundles.inc | 12 | ||||
-rw-r--r-- | modules/sugar_activities_extra/kspost.60.nochroot.activities.sh | 16 | ||||
-rw-r--r-- | modules/sugar_activity_group/kspost.60.nochroot.activities.py | 13 | ||||
-rw-r--r-- | modules/sugarlabs_activities/kspost.60.nochroot.aslo.sh | 10 |
6 files changed, 54 insertions, 34 deletions
diff --git a/lib/ooblib.py b/lib/ooblib.py index eea30a3..76845d5 100644 --- a/lib/ooblib.py +++ b/lib/ooblib.py @@ -2,6 +2,7 @@ # Licensed under the terms of the GNU GPL v2 or later; see COPYING for details. import os +import shutil import urllib2 from xml.etree.ElementTree import ElementTree @@ -74,3 +75,21 @@ def get_repomd(baseurl): except: pass return md + +def ln_or_cp(src, dest): + src_dev = os.stat(src).st_dev + dest_dev = os.stat(dest).st_dev + + if src_dev == dest_dev: + if os.path.isdir(dest): + dest = os.path.join(dest, os.path.basename(src)) + os.link(src, dest) + else: + shutil.copy(src, dest) + +def install_sugar_bundle(path): + bundlesdir = os.path.join(intermediatesdir, "shared", "sugar-bundles") + if not os.path.exists(bundlesdir): + os.makedirs(bundlesdir) + ln_or_cp(path, bundlesdir) + diff --git a/lib/shlib.sh b/lib/shlib.sh index 0d23985..5075154 100644 --- a/lib/shlib.sh +++ b/lib/shlib.sh @@ -31,3 +31,21 @@ image_name() { printf $name_tmpl $(read_buildnr) } +# hard link a file, but fall-back on copy if a device boundary is being crossed +ln_or_cp() { + local src=$1 + local dest=$2 + local src_dev=$(stat -c "%D" "$src") + local dest_dev=$(stat -c "%D" "$dest") + if [ "$src_dev" = "$dest_dev" ]; then + cp -l "$src" "$dest" + else + cp "$src" "$dest" + fi +} + +install_sugar_bundle() { + mkdir -p "$intermediatesdir/shared/sugar-bundles" + ln_or_cp "$1" "$intermediatesdir/shared/sugar-bundles" +} + diff --git a/modules/sugar/kspost.80.install_bundles.inc b/modules/sugar/kspost.80.install_bundles.inc new file mode 100644 index 0000000..753c005 --- /dev/null +++ b/modules/sugar/kspost.80.install_bundles.inc @@ -0,0 +1,12 @@ +mkdir -p /home/olpc/{Activities,Library} +chown olpc:olpc /home/olpc/{Activities,Library} + +for i in /build_shared/sugar-bundles/*; do + if [ "${i:(-4)}" == ".xol" ]; then + /usr/bin/unzip -d /home/olpc/Library -q $i + else + /bin/su -c "/usr/bin/sugar-install-bundle $i" olpc + fi +done + +chown -R olpc:olpc /home/olpc/{Activities,Library} diff --git a/modules/sugar_activities_extra/kspost.60.nochroot.activities.sh b/modules/sugar_activities_extra/kspost.60.nochroot.activities.sh index 27c33e7..e9d3b50 100644 --- a/modules/sugar_activities_extra/kspost.60.nochroot.activities.sh +++ b/modules/sugar_activities_extra/kspost.60.nochroot.activities.sh @@ -13,26 +13,14 @@ for line in $(env); do echo "Downloading from $aurl ..." >&2 wget --no-verbose --inet4-only -P $cache -N "$aurl" - outfile=$cache/$(basename "$aurl") - if [ "${outfile:(-4)}" == ".xol" ]; then - echo "unzip -d \$INSTALL_ROOT/home/olpc/Library -q '$outfile'" - else - echo "unzip -d \$INSTALL_ROOT/home/olpc/Activities -q '$outfile'" - fi + install_sugar_bundle $cache/$(basename "$aurl") done IFS=$oIFS - actpath=$(read_config sugar_activities_extra local_dir) if [ -n "$actpath" -a -d "$actpath" ]; then for i in "$actpath"/*; do - if [ "${i:(-4)}" == ".xol" ]; then - echo "unzip -d \$INSTALL_ROOT/home/olpc/Library -q '$i'" - else - echo "unzip -d \$INSTALL_ROOT/home/olpc/Activities -q '$i'" - fi + install_sugar_bundle $i done fi -echo 'chown -R 500:500 $INSTALL_ROOT/home/olpc/{Activities,Library}' - diff --git a/modules/sugar_activity_group/kspost.60.nochroot.activities.py b/modules/sugar_activity_group/kspost.60.nochroot.activities.py index bb2aed2..f77a9e1 100644 --- a/modules/sugar_activity_group/kspost.60.nochroot.activities.py +++ b/modules/sugar_activity_group/kspost.60.nochroot.activities.py @@ -14,13 +14,6 @@ from bitfrost.update import microformat import ooblib -def generate_install_cmd(path): - if path.endswith(".xol"): - print "unzip -d $INSTALL_ROOT/home/olpc/Library -q '%s'" % path - else: - print "unzip -d $INSTALL_ROOT/home/olpc/Activities -q '%s'" % path - - cache = os.path.join(ooblib.cachedir, 'activities') if not os.path.exists(cache): os.makedirs(cache) @@ -71,7 +64,7 @@ if install_activities: localsize = os.stat(localpath).st_size if localsize == length: print >>sys.stderr, "Not downloading, already in cache." - generate_install_cmd(localpath) + ooblib.install_sugar_bundle(localpath) continue print >>sys.stderr, "Downloading (%dkB)..." % (length/1024) @@ -79,7 +72,7 @@ if install_activities: localfd.write(fd.read()) fd.close() localfd.close() - generate_install_cmd(localpath) + ooblib.install_sugar_bundle(localpath) # only process the first working URL break @@ -90,5 +83,3 @@ if systemwide: else: print "echo '%s' > $INSTALL_ROOT/home/olpc/Activities/.groups" % baseurl -print "chown -R 500:500 $INSTALL_ROOT/home/olpc/{Activities,Library}" - diff --git a/modules/sugarlabs_activities/kspost.60.nochroot.aslo.sh b/modules/sugarlabs_activities/kspost.60.nochroot.aslo.sh index 2c71f95..0118a53 100644 --- a/modules/sugarlabs_activities/kspost.60.nochroot.aslo.sh +++ b/modules/sugarlabs_activities/kspost.60.nochroot.aslo.sh @@ -25,15 +25,7 @@ for id in $activities; do echo "Downloading from $aurl ..." >&2 wget --no-verbose --inet4-only -P $cache -N "$aurl" - - outfile=$cache/$(basename "$aurl") - if [ "${outfile:(-4)}" == ".xol" ]; then - echo "unzip -d \$INSTALL_ROOT/home/olpc/Library -q '$outfile'" - else - echo "unzip -d \$INSTALL_ROOT/home/olpc/Activities -q '$outfile'" - fi + install_sugar_bundle $cache/$(basename "$aurl") done IFS=$oIFS -echo 'chown -R 500:500 $INSTALL_ROOT/home/olpc/{Activities,Library}' - |