-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge-addons.sh
executable file
·75 lines (58 loc) · 1.45 KB
/
merge-addons.sh
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
#!/bin/bash
output="$1"
shift
log() {
echo "$0 - $@"
}
error() {
log "$@"
exit 1
}
help() {
echo " $0 OUTPUT-ADDON ADDON [ADDON]..."
echo ""
echo " Merge the ADDONs into the OUTPUT-ADDON."
}
if [ -z "$output" ] || [ -z "$1" ]; then
help
exit 1
fi
base="/tmp/`basename \"output\"`-`date '+%N'`"
target="$base/addon"
temp_output="$base/output"
log "Operating in $base"
mkdir -p "$temp_output"
if [ -z "`which mksquashfs`" ]; then
log "Installing squashfs tools"
apt-get -y install squashfs-tools
fi
for addon in "$@"; do
[ -e "$addon" ] || \
error "Addon not found: $addon"
# from http://superuser.com/a/196655
! [ -f "$output" ] || \
[ "`stat -c '%d:%i' \"$addon\"`" != "`stat -c '%d:%i' \"$output\"`" ] || {
error "Can not use $addon as input because it is also the output."
}
log "Working with $addon"
mkdir -p "$target"
unsquashfs -f -d "$target" "$addon" || \
error "Could not unsquash"
log "Copy $target"
log " to $temp_output"
log "Attempting hard link to save space"
cp -rflTP "$target" "$temp_output" || {
log "Hard link failed. Falling back to copy."
cp -rfuTP "$target" "$temp_output" || \
error "Could not copy addon"
}
rm -r "$target" || \
error "Could not remove previous addon."
done
log "squashing $temp_output"
log " to $output"
log "Content: "`ls "$temp_output"`
mksquashfs "$temp_output" "$output" -noappend || \
error "Could not squash"
rm -rf "$base"
exit 0