Merge "Prepare future versions"
[staging/xdg-launcher.git] / install.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2015, 2016 "IoT.bzh"
4 # Author "Romain Forlot" <romain.forlot@iot.bzh>
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #        http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18
19 die()
20 {
21         local _ret=$2
22         test -n "$_ret" || _ret=1
23         test "$_PRINT_HELP" = yes && print_help >&2
24         echo "$1" >&2
25         exit ${_ret}
26 }
27
28 begins_with_short_option()
29 {
30         local first_option all_short_options
31         all_short_options='tdbh'
32         first_option="${1:0:1}"
33         test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
34 }
35
36 # THE DEFAULTS INITIALIZATION - POSITIONALS
37 _positionals=()
38 # THE DEFAULTS INITIALIZATION - OPTIONALS
39 _arg_components_path=()
40 _arg_debug=off
41
42 print_help ()
43 {
44         echo "The general script's help msg"
45         printf 'Usage: %s [-d|--(no-)debug] [-h|--help] <root-path>\n' "$0"
46         printf "\t%s\n" "<root-path>: Project root path"
47         printf "\t%s\n" "-d,--debug,--no-debug: Optional debug flag. (off by default)"
48         printf "\t%s\n" "-h,--help: Prints help"
49 }
50
51 # THE PARSING ITSELF
52 while test $# -gt 0
53 do
54         _key="$1"
55         case "$_key" in
56                 -d*|--no-debug|--debug)
57                         _arg_debug="on"
58                         _next="${_key##-d}"
59                         if test -n "$_next" -a "$_next" != "$_key"
60                         then
61                                 begins_with_short_option "$_next" && shift && set -- "-d" "-${_next}" "$@" || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
62                         fi
63                         test "${1:0:5}" = "--no-" && _arg_debug="off"
64                         ;;
65                 -h*|--help)
66                         print_help
67                         exit 0
68                         ;;
69                 *)
70                         _positionals+=("$1")
71                         ;;
72         esac
73         shift
74 done
75
76 _positional_names=('_arg_root_path' )
77 _required_args_string="'root-path'"
78 test ${#_positionals[@]} -lt 1 && _PRINT_HELP=yes die "FATAL ERROR: Not enough positional arguments - we require exactly 1 (namely: $_required_args_string), but got only ${#_positionals[@]}." 1
79 test ${#_positionals[@]} -gt 1 && _PRINT_HELP=yes die "FATAL ERROR: There were spurious positional arguments --- we expect exactly 1 (namely: $_required_args_string), but got ${#_positionals[@]} (the last one was: '${_positionals[*]: -1}')." 1
80 for (( ii = 0; ii < ${#_positionals[@]}; ii++))
81 do
82         eval "${_positional_names[ii]}=\${_positionals[ii]}" || die "Error during argument parsing, possibly an Argbash bug." 1
83 done
84
85 [ "${_arg_debug}" = "on" ] && echo "Copying template structure to your project root path: ${_arg_root_path}"
86 cp -rf template/etc template/AGLBuild template/packaging ${_arg_root_path}/
87
88 echo "Installation finished."
89 echo "Please customize the config.cmake file under the 'etc' directory of your project."
90 echo "Specify manually your target, you should look at samples provided in this repository to make yours."
91 echo "Then when you are ready to build, using 'AGLBuild' that will wrap CMake build command:"
92 echo "./AGLBuild package"
93 echo ""
94 echo "Or with the classic way : "
95 echo "mkdir -p build && cd build"
96 echo "cmake .. && make"