forked from makefu/minikrebs
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcopy_profile
executable file
·82 lines (72 loc) · 2.18 KB
/
copy_profile
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
82
#!/usr/bin/env bash
set -eu
usage() {
cat << EOF
Usage: $0 PROFILE
ENVIRONMENT:
PLATFORM -- Set openWRT platform (Default: TLWR703, examples: TLMR3020)
TRAIT_DIR -- Set Trait directory (Default traits/)
EOF
echo
HIDE_TRAITS="true" bin/available_profiles
}
[ -z "${1:-}" ] && usage && exit 1
HERE="$(dirname "$(readlink -f "$0")")"
PROFILE_DIR="${HERE}/profiles"
TRAIT_DIR="${TRAIT_DIR:-${HERE}/traits}"
BUILD_DIR="${HERE}/builder/"
PLATFORM="${PLATFORM-TLWR703}"
PROFILE="$PROFILE_DIR/$1"
PKG_FILE="${BUILD_DIR}/root_packages"
OVERLAY_PKG_FILE="${BUILD_DIR}/overlay_packages"
APPEND_FILES="${HERE}/lib/append_files"
indent() {
while read -r line;do
yes ' ' | head -"${1:-4}" | tr -d '\n'
echo "$line"
done
}
handle_append(){
(while read -r i ;do
[ -e "$1/files/$i" ] && cat "$1/files/$i" >> "$BUILD_DIR/customfiles/$i"
done) < "${APPEND_FILES}"
}
handle_trait_dir(){
if [ "$(readlink -f "$TRAIT_DIR" )" = "$1" ];then
return 0
else
# higher level traits supersede more general definitions
cd "$1"
#echo "in $CUR" >&2
handle_trait_dir "$(readlink -f ..)" ||:
if [ -e "$1/files" ] ;then
rsync -rl --exclude-from="$APPEND_FILES" "$1/files/"* "$BUILD_DIR/customfiles"
handle_append "$1"
fi
if [ -e "$1/MANIFEST" ];then
. "$1/MANIFEST"
printf '%s' "${PACKAGES:-} " >> "$PKG_FILE"
printf '%s' "${OVERLAY_PACKAGES:-} " >> "$OVERLAY_PKG_FILE"
fi
fi
}
build_custom_make(){
#hack to avoid newlines in build file
PLATFORM="$1"
echo "make image PROFILE='$PLATFORM' PACKAGES='$(cat "$PKG_FILE")' FILES=customfiles/" > \
"$BUILD_DIR/custom_make"
chmod +x "$BUILD_DIR/custom_make"
}
main (){
rm -rf "$BUILD_DIR/customfiles"
rm -f "$OVERLAY_PKG_FILE" "$PKG_FILE"
mkdir -p "$BUILD_DIR/customfiles"
echo "Doc from the Profile:" >&2
grep '^\s*#' "$PROFILE" | indent 2 >&2
grep -v '^\s*#' "$PROFILE" | while read -r trait;do
echo "Handling $TRAIT_DIR/$trait" >&2
handle_trait_dir "$(readlink -f "$TRAIT_DIR/$trait")" ||:
done
build_custom_make "$PLATFORM"
}
main "$@"