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