forked from makefu/minikrebs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy_profile
executable file
·78 lines (70 loc) · 1.92 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
#!/bin/sh
set -eu
usage() {
cat << EOF
Usage: $0 PROFILE
ENVIRONMENT:
PLATFORM -- Set openWRT platform (Default: TLWR703)
TRAIT_DIR -- Set Trait directory (Default traits/)
EOF
echo
HIDE_TRAITS="true" bin/available_profiles
}
[ x"${1:-}" = "x" ] && 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"
ALL_PACKAGES=""
APPEND_FILES=("etc/rc.local")
indent() {
while read line;do
yes ' ' | head -${1:-4} | tr -d '\n'
echo $line
done
}
handle_append(){
local CURRENT_TRAIT_DIR="$1"
for i in ${APPEND_FILES[@]};do
[ -e "$CURRENT_TRAIT_DIR/files/$i" ] && cat "$CURRENT_TRAIT_DIR/files/$i" >>\
"$BUILD_DIR/customfiles/$i"
done
}
handle_trait_dir(){
local CUR="$(readlink -f $1 )"
if [ "$(readlink -f $TRAIT_DIR )" = "$CUR" ];then
return 0
else
# higher level traits supersede more general definitions
cd "$CUR"
#echo "in $CUR" >&2
handle_trait_dir .. ||:
if [ -e "$CUR/files" ] ;then
rsync -rl --exclude "$APPEND_FILES" "$CUR/files/"* "$BUILD_DIR/customfiles" >/dev/null
handle_append "$CUR"
fi
if [ -e "$CUR/MANIFEST" ];then
source "$CUR/MANIFEST"
echo -n "$PACKAGES "
fi
fi
}
build_custom_make(){
#hack to avoid newlines in build file
PLATFORM="$1"
shift
echo "make image PROFILE='$PLATFORM' PACKAGES='$@' FILES=customfiles/" > \
"$BUILD_DIR/custom_make"
}
main (){
rm -r "$BUILD_DIR/customfiles" || :
mkdir "$BUILD_DIR/customfiles" || :
ALL_PACKAGES=`cat "$PROFILE" | while read trait;do
echo "Handling $TRAIT_DIR/$trait" >&2
handle_trait_dir "$TRAIT_DIR/$trait" ||:
done`
build_custom_make "$PLATFORM" "$ALL_PACKAGES"
}
main $@