build: fix generation of large .vdi images
[openwrt/staging/stintel.git] / scripts / ext-tools.sh
1 #!/usr/bin/env bash
2
3 TOOLS_TAR=""
4 HOST_BUILD_DIR=$(pwd)/"build_dir/host"
5 HOST_STAGING_DIR_STAMP=$(pwd)/"staging_dir/host/stamp"
6
7 refresh_timestamps() {
8 find -H "$1" -not -type l -print0 | xargs -0 touch
9 }
10
11 extract_prebuilt_tar() {
12 tar -xf "$1"
13 }
14
15 refresh_prebuilt_tools() {
16 if [ ! -d "$HOST_BUILD_DIR" ]; then
17 echo "Can't find Host Build Dir "$HOST_BUILD_DIR"" >&2
18 exit 1
19 fi
20
21 refresh_timestamps "$HOST_BUILD_DIR"
22 sleep 1
23
24 if [ ! -d "$HOST_STAGING_DIR_STAMP" ]; then
25 echo "Can't find Host Staging Dir Stamp "$HOST_STAGING_DIR_STAMP"" >&2
26 exit 1
27 fi
28
29 refresh_timestamps "$HOST_STAGING_DIR_STAMP"
30
31 return 0
32 }
33
34 install_prebuilt_tools() {
35 extract_prebuilt_tar "$TOOLS_TAR"
36
37 refresh_prebuilt_tools
38
39 return 0
40 }
41
42 while [ -n "$1" ]; do
43 arg="$1"; shift
44 case "$arg" in
45 --host-build-dir)
46 [ -d "$1" ] || {
47 echo "Directory '$1' does not exist." >&2
48 exit 1
49 }
50 HOST_BUILD_DIR="$(cd "$1"; pwd)"; shift
51 ;;
52
53 --host-staging-dir-stamp)
54 [ -d "$1" ] || {
55 echo "Directory '$1' does not exist." >&2
56 exit 1
57 }
58 HOST_STAGING_DIR_STAMP="$(cd "$1"; pwd)"; shift
59 ;;
60
61 --tools)
62 [ -f "$1" ] || {
63 echo "Tools tar file '$1' does not exist." >&2
64 exit 1
65 }
66 TOOLS_TAR="$1"; shift
67 install_prebuilt_tools
68
69 exit $?
70 ;;
71
72 --refresh)
73 refresh_prebuilt_tools
74
75 exit $?
76 ;;
77
78 -h|--help)
79 me="$(basename "$0")"
80 echo -e "\nUsage:\n" >&2
81 echo -e " $me --host-build-dir {directory}" >&2
82 echo -e " Set to refresh timestamp of this build directory" >&2
83 echo -e " with --tools." >&2
84 echo -e " THIS OPTION MUST BE SET BEFORE --tools." >&2
85 echo -e " If not provided the default directory is:" >&2
86 echo -e " $(pwd)/build_dir/host\n" >&2
87 echo -e " $me --host-staging-dir-stamp {directory}" >&2
88 echo -e " Set to refresh staging timestamp present in this" >&2
89 echo -e " directory with --tools." >&2
90 echo -e " THIS OPTION MUST BE SET BEFORE --tools." >&2
91 echo -e " If not provided the default directory is:" >&2
92 echo -e " $(pwd)/staging_dir/host/stamp\n" >&2
93 echo -e " $me --tools {tar}" >&2
94 echo -e " Install the prebuilt tools present in the passed" >&2
95 echo -e " tar and prepare them." >&2
96 echo -e " To correctly use them it's needed to update the" >&2
97 echo -e " timestamp of each tools to skip recompilation.\n" >&2
98 echo -e " $me --refresh" >&2
99 echo -e " Refresh timestamps of already extracted prebuilt" >&2
100 echo -e " tools to correctly use them and skip" >&2
101 echo -e " recompilation.\n" >&2
102 echo -e " $me --help" >&2
103 echo -e " Display this help text and exit.\n\n" >&2
104 exit 1
105 ;;
106
107 *)
108 echo "Unknown argument '$arg'" >&2
109 exec $0 --help
110 ;;
111 esac
112 done
113
114 exec $0 --help