Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/lib/shlib.sh
blob: 11324c2ee628cb0e2b2522f6c8add9abf1962fb6 (plain)
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
# Copyright (C) 2009 One Laptop Per Child
# Licensed under the terms of the GNU GPL v2 or later; see COPYING for details.

set -e

libdir=$OOB__libdir
bindir=$OOB__bindir
builddir=$OOB__builddir
cachedir=$OOB__cachedir
cacheonly=$OOB__cacheonly
intermediatesdir=$OOB__intermediatesdir
outputdir=$OOB__outputdir
statedir=$OOB__statedir
fsmount=$OOB__fsmount

read_config() {
	local vname="CFG_$1__$2"
	echo ${!vname}
}

find_option_values() {
	local out=$1
	local module=$2
	local option=$3
	local prefix=CFG_${module}__${option}

	while IFS= read -r -d '' line; do
		local name=${line%%=*}
		local value=${line#*=}
		[[ $name == $prefix || $name == ${prefix}_* ]] || continue
		eval "$out+=('$value')"
	done < <(env --null)
}

read_buildnr() {
	local buildnr_path=$intermediatesdir/buildnr
	if [[ -e $buildnr_path ]]; then
		echo "$(<$buildnr_path)"
	else
		echo "0"
	fi
}

read_laptop_model_number()
{
	local path=$intermediatesdir/laptop_model_number
	if [[ -e $path ]]; then
		echo "$(<$path)"
	else
		echo "0"
	fi
}

image_name() {
	local major_ver=$(read_config global olpc_version_major)
	local minor_ver=$(read_config global olpc_version_minor)
	local cust_tag=$(read_config global customization_tag)
	local buildnr=$(read_buildnr)
	local modelnr=$(read_laptop_model_number)

	buildnr=$(printf %03d "$buildnr")
	echo "${major_ver: -1}${minor_ver}${buildnr}${cust_tag}${modelnr}"
}

# 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"
}