source: BLFS/blfs-parser.sh@ 4aede02

experimental
Last change on this file since 4aede02 was 00f4966, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Merged r2936:2940 from trunk

  • Property mode set to 100755
File size: 3.0 KB
Line 
1#!/bin/bash
2#
3# $Id$
4#
5set -e
6declare TARGET
7declare DEP_LEVEL
8declare PKGXML
9declare BLFS_XML
10declare VERBOSITY=1
11
12# Grab and name the command line options
13 optTARGET=$1 # Package target
14optDEPENDENCY=$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
22source libs/constants.inc
23[[ $? > 0 ]] && echo -e "\n\tERROR: constants.inc did not load..\n" && exit
24
25#---------------------
26# Configuration file for alternatives
27source alternatives.conf
28[[ $? > 0 ]] && echo -e "\n\tERROR: alternatives.conf did not load..\n" && exit
29
30#---------------------
31# Dependencies module
32source libs/func_dependencies
33[[ $? > 0 ]] && echo -e "\n\tERROR: func_dependencies did not load..\n" && exit
34
35#---------------------
36# parser module
37source libs/func_parser
38[[ $? > 0 ]] && echo -e "\n\tERROR: func_parser did not load..\n" && exit
39
40
41
42#-------------------------#
43validate_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
54inline_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#-------------------------#
73validate_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
84inline_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 --------
108if [[ ! -f packages ]] ; then
109 echo -e "\tNo packages file has been found.\n"
110 echo -e "\tExecution aborted.\n"
111 exit 1
112fi
113
114validate_target "${optTARGET}"
115validate_dependency "${optDEPENDENCY}"
116generate_dependency_tree
117generate_TARGET_xml
118generate_target_book
119create_build_scripts "${SUDO}"
Note: See TracBrowser for help on using the repository browser.