1 | #!/bin/bash
|
---|
2 | #
|
---|
3 | # $Id$
|
---|
4 | #
|
---|
5 | set -e
|
---|
6 | declare TARGET
|
---|
7 | declare DEP_LEVEL
|
---|
8 | declare PKGXML
|
---|
9 | declare BLFS_XML
|
---|
10 | declare VERBOSITY=1
|
---|
11 |
|
---|
12 | # Grab and name the command line options
|
---|
13 | optTARGET=$1 # Package target
|
---|
14 | optDEPENDENCY=$2 # Dependencies level, 1/2/3
|
---|
15 | SUDO=$3 # Build as user (y) or as root (n)
|
---|
16 |
|
---|
17 | [[ -z $SUDO ]] && SUDO=y
|
---|
18 |
|
---|
19 |
|
---|
20 | #---------------------
|
---|
21 | # Constants
|
---|
22 | source libs/constants.inc
|
---|
23 | [[ $? > 0 ]] && echo -e "\n\tERROR: constants.inc did not load..\n" && exit
|
---|
24 |
|
---|
25 | #---------------------
|
---|
26 | # Configuration file for alternatives
|
---|
27 | source alternatives.conf
|
---|
28 | [[ $? > 0 ]] && echo -e "\n\tERROR: alternatives.conf did not load..\n" && exit
|
---|
29 |
|
---|
30 | #---------------------
|
---|
31 | # Dependencies module
|
---|
32 | source libs/func_dependencies
|
---|
33 | [[ $? > 0 ]] && echo -e "\n\tERROR: func_dependencies did not load..\n" && exit
|
---|
34 |
|
---|
35 | #---------------------
|
---|
36 | # parser module
|
---|
37 | source libs/func_parser
|
---|
38 | [[ $? > 0 ]] && echo -e "\n\tERROR: func_parser did not load..\n" && exit
|
---|
39 |
|
---|
40 |
|
---|
41 |
|
---|
42 | #-------------------------#
|
---|
43 | validate_target() { # ID of target package (as listed in packages file)
|
---|
44 | #-------------------------#
|
---|
45 | : <<inline_doc
|
---|
46 | function: Validate the TARGET parameter.
|
---|
47 | input vars: $1, package/target to validate
|
---|
48 | externals: file: packages
|
---|
49 | modifies: TARGET
|
---|
50 | returns: nothing
|
---|
51 | output: nothing
|
---|
52 | on error: exit
|
---|
53 | on success: modifies TARGET
|
---|
54 | inline_doc
|
---|
55 |
|
---|
56 | if [[ -z "$1" ]] ; then
|
---|
57 | echo -e "\n\tYou must to provide a package ID."
|
---|
58 | echo -e "\tSee packages file for a list of available targets.\n"
|
---|
59 | exit 1
|
---|
60 | fi
|
---|
61 |
|
---|
62 | if ! grep "^$1[[:space:]]" packages > /dev/null ; then
|
---|
63 | echo -e "\n\t$1 is not a valid package ID."
|
---|
64 | echo -e "\tSee packages file for a list of available targets.\n"
|
---|
65 | exit 1
|
---|
66 | fi
|
---|
67 |
|
---|
68 | TARGET=$1
|
---|
69 | echo -e "\n\tUsing $TARGET as the target package."
|
---|
70 | }
|
---|
71 |
|
---|
72 | #-------------------------#
|
---|
73 | validate_dependency() { # Dependencies level 1(required)/2(1 + recommended)/3(2+ optional)
|
---|
74 | #-------------------------#
|
---|
75 | : <<inline_doc
|
---|
76 | function: Validate the dependency level requested.
|
---|
77 | input vars: $1, requested dependency level
|
---|
78 | externals: vars: TARGET
|
---|
79 | modifies: vars: DEP_LEVEL
|
---|
80 | returns: nothing
|
---|
81 | output: nothing
|
---|
82 | on error: nothing
|
---|
83 | on success: modifies DEP_LEVEL, default value = 2
|
---|
84 | inline_doc
|
---|
85 |
|
---|
86 | if [[ -z "$1" ]] ; then
|
---|
87 | DEP_LEVEL=2
|
---|
88 | echo -e "\n\tNo dependencies level has been defined."
|
---|
89 | echo -e "\tAssuming level $DEP_LEVEL (Required plus Recommended).\n"
|
---|
90 | return
|
---|
91 | fi
|
---|
92 |
|
---|
93 | case $1 in
|
---|
94 | 1 | 2 | 3 )
|
---|
95 | DEP_LEVEL=$1
|
---|
96 | echo -e "\n\tUsing $DEP_LEVEL as dependencies level.\n"
|
---|
97 | ;;
|
---|
98 | * )
|
---|
99 | DEP_LEVEL=2
|
---|
100 | echo -e "\n\t$1 is not a valid dependencies level."
|
---|
101 | echo -e "\tAssuming level $DEP_LEVEL (Required plus Recommended).\n"
|
---|
102 | ;;
|
---|
103 | esac
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | #------- MAIN --------
|
---|
108 | if [[ ! -f packages ]] ; then
|
---|
109 | echo -e "\tNo packages file has been found.\n"
|
---|
110 | echo -e "\tExecution aborted.\n"
|
---|
111 | exit 1
|
---|
112 | fi
|
---|
113 |
|
---|
114 | validate_target "${optTARGET}"
|
---|
115 | validate_dependency "${optDEPENDENCY}"
|
---|
116 | generate_dependency_tree
|
---|
117 | generate_TARGET_xml
|
---|
118 | generate_target_book
|
---|
119 | create_build_scripts "${SUDO}"
|
---|