1 | #!/bin/bash
|
---|
2 |
|
---|
3 | set -e
|
---|
4 |
|
---|
5 | : << inline_doc
|
---|
6 | Installs a set-up to build BLFS packages.
|
---|
7 | You can set these variables:
|
---|
8 | TRACKING_DIR : where the installed package file is kept.
|
---|
9 | (default /var/lib/jhalfs/BLFS)
|
---|
10 | INITSYS : which books do you want? 'sysv' or 'systemd' (default sysv)
|
---|
11 | BLFS_ROOT : where the installed tools will be installed, relative to $HOME.
|
---|
12 | Must start with a '/' (default /blfs_root)
|
---|
13 | BLFS_BRANCH_ID: development, branch-xxx, xxx (where xxx is a valid tag)
|
---|
14 | (default development)
|
---|
15 | LFS_BRANCH_ID : development, branch-xxx, xxx (where xxx is a valid tag)
|
---|
16 | (default development)
|
---|
17 | Examples:
|
---|
18 | 1 - If you plan to use the tools to build BLFS on top of LFS, but you did not
|
---|
19 | use jhalfs, or forgot to include the jhalfs-blfs tools:
|
---|
20 | (as root) mkdir -p /var/lib/jhalfs/BLFS && chown -R <user> /var/lib/jhalfs
|
---|
21 | (as user) INITSYS=<your system> ./install-blfs-tools.sh
|
---|
22 | 2 - To install with only user privileges (default to sysv):
|
---|
23 | TRACKING_DIR=$HOME/blfs_root/trackdir ./install-blfs-tools.sh
|
---|
24 |
|
---|
25 | This script can also be called automatically after running make in this
|
---|
26 | directory. The parameters will then be taken from the configuration file.
|
---|
27 | inline_doc
|
---|
28 |
|
---|
29 |
|
---|
30 | # VT100 colors
|
---|
31 | declare -r BLACK=$'\e[1;30m'
|
---|
32 | declare -r DK_GRAY=$'\e[0;30m'
|
---|
33 |
|
---|
34 | declare -r RED=$'\e[31m'
|
---|
35 | declare -r GREEN=$'\e[32m'
|
---|
36 | declare -r YELLOW=$'\e[33m'
|
---|
37 | declare -r BLUE=$'\e[34m'
|
---|
38 | declare -r MAGENTA=$'\e[35m'
|
---|
39 | declare -r CYAN=$'\e[36m'
|
---|
40 | declare -r WHITE=$'\e[37m'
|
---|
41 |
|
---|
42 | declare -r OFF=$'\e[0m'
|
---|
43 | declare -r BOLD=$'\e[1m'
|
---|
44 | declare -r REVERSE=$'\e[7m'
|
---|
45 | declare -r HIDDEN=$'\e[8m'
|
---|
46 |
|
---|
47 | declare -r tab_=$'\t'
|
---|
48 | declare -r nl_=$'\n'
|
---|
49 |
|
---|
50 | declare -r DD_BORDER="${BOLD}==============================================================================${OFF}"
|
---|
51 | declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
|
---|
52 | declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}"
|
---|
53 | declare -r dotSTR=".................." # Format display of parameters and versions
|
---|
54 |
|
---|
55 | # bold yellow > < pair
|
---|
56 | declare -r R_arrow=$'\e[1;33m>\e[0m'
|
---|
57 | declare -r L_arrow=$'\e[1;33m<\e[0m'
|
---|
58 | VERBOSITY=1
|
---|
59 |
|
---|
60 | # Take parameters from "configuration" if $1="auto"
|
---|
61 | if [ "$1" = auto ]; then
|
---|
62 | [[ $VERBOSITY > 0 ]] && echo -n "Loading configuration ... "
|
---|
63 | source configuration
|
---|
64 | [[ $? > 0 ]] && echo -e "\nconfiguration could not be loaded" && exit 2
|
---|
65 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
66 | fi
|
---|
67 |
|
---|
68 | if [ "$BOOK_BLFS" = y ]; then
|
---|
69 | ## Read variables and sanity checks
|
---|
70 | [[ "$relGIT" = y ]] && BLFS_BRANCH_ID=development
|
---|
71 | [[ "$BRANCH" = y ]] && BLFS_BRANCH_ID=$BRANCH_ID
|
---|
72 | [[ "$WORKING_COPY" = y ]] && BLFS_BOOK=$BOOK
|
---|
73 | [[ "$BRANCH_ID" = "**EDIT ME**" ]] &&
|
---|
74 | echo You have not set the BLFS book version or branch && exit 1
|
---|
75 | [[ "$BOOK" = "**EDIT ME**" ]] &&
|
---|
76 | echo You have not set the BLFS working copy location && exit 1
|
---|
77 | [[ "$LFS_relGIT" = y ]] && LFS_BRANCH_ID=development
|
---|
78 | [[ "$LFS_BRANCH" = y ]] && LFS_BRANCH_ID=$BLFS_LFS_BRANCH_ID
|
---|
79 | [[ "$LFS_WORKING_COPY" = y ]] && LFS_BOOK=$BLFS_LFS_BOOK
|
---|
80 | [[ "$LFS_BRANCH_ID" = "**EDIT ME**" ]] &&
|
---|
81 | echo You have not set the LFS book version or branch && exit 1
|
---|
82 | [[ "$LFS_BOOK" = "**EDIT ME**" ]] &&
|
---|
83 | echo You have not set the LFS working copy location && exit 1
|
---|
84 | fi
|
---|
85 |
|
---|
86 | COMMON_DIR="common"
|
---|
87 | # blfs-tool envars
|
---|
88 | BLFS_TOOL='y'
|
---|
89 | BUILDDIR=$(cd ~;pwd)
|
---|
90 | BLFS_ROOT="${BLFS_ROOT:=/blfs_root}"
|
---|
91 | TRACKING_DIR="${TRACKING_DIR:=/var/lib/jhalfs/BLFS}"
|
---|
92 | INITSYS="${INITSYS:=sysv}"
|
---|
93 | BLFS_BRANCH_ID=${BLFS_BRANCH_ID:=development}
|
---|
94 | LFS_BRANCH_ID=${LFS_BRANCH_ID:=development}
|
---|
95 | BLFS_XML=${BLFS_XML:=blfs-xml}
|
---|
96 | LFS_XML=${LFS_XML:=lfs-xml}
|
---|
97 |
|
---|
98 | # Validate the configuration:
|
---|
99 | PARAMS="BLFS_ROOT TRACKING_DIR INITSYS BLFS_XML LFS_XML"
|
---|
100 | if [ "$WORKING_COPY" = y ]; then
|
---|
101 | PARAMS="$PARAMS WORKING_COPY BLFS_BOOK"
|
---|
102 | else
|
---|
103 | PARAMS="$PARAMS BLFS_BRANCH_ID"
|
---|
104 | fi
|
---|
105 | if [ "$LFS_WORKING_COPY" = y ]; then
|
---|
106 | PARAMS="$PARAMS LFS_WORKING_COPY LFS_BOOK"
|
---|
107 | else
|
---|
108 | PARAMS="$PARAMS LFS_BRANCH_ID"
|
---|
109 | fi
|
---|
110 | # Format for displaying parameters:
|
---|
111 | declare -r PARAM_VALS='${config_param}${dotSTR:${#config_param}} ${L_arrow}${BOLD}${!config_param}${OFF}${R_arrow}'
|
---|
112 |
|
---|
113 | for config_param in $PARAMS; do
|
---|
114 | echo -e "`eval echo $PARAM_VALS`"
|
---|
115 | done
|
---|
116 |
|
---|
117 | echo "${SD_BORDER}${nl_}"
|
---|
118 | echo -n "Are you happy with these settings? yes/no (no): "
|
---|
119 | read ANSWER
|
---|
120 | if [ x$ANSWER != "xyes" ] ; then
|
---|
121 | echo "${nl_}Rerun make and fix your settings.${nl_}"
|
---|
122 | exit
|
---|
123 | fi
|
---|
124 | [[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
|
---|
125 |
|
---|
126 | #*******************************************************************#
|
---|
127 | [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh> ..."
|
---|
128 | source $COMMON_DIR/libs/func_check_version.sh
|
---|
129 | [[ $? > 0 ]] && echo " function module did not load.." && exit 2
|
---|
130 | [[ $VERBOSITY > 0 ]] && echo " OK"
|
---|
131 |
|
---|
132 | [[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
|
---|
133 |
|
---|
134 | case $BLFS_BRANCH_ID in
|
---|
135 | development ) BLFS_TREE=trunk ;;
|
---|
136 | branch-* ) BLFS_TREE=${BLFS_BRANCH_ID#branch-} ;;
|
---|
137 | * ) BLFS_TREE=${BLFS_BRANCH_ID} ;;
|
---|
138 | esac
|
---|
139 | case $LFS_BRANCH_ID in
|
---|
140 | development ) LFS_TREE=trunk ;;
|
---|
141 | branch-* ) LFS_TREE=${LFS_BRANCH_ID#branch-} ;;
|
---|
142 | * ) LFS_TREE=${LFS_BRANCH_ID} ;;
|
---|
143 | esac
|
---|
144 |
|
---|
145 | # Check for build prerequisites.
|
---|
146 | echo
|
---|
147 | check_alfs_tools
|
---|
148 | check_blfs_tools
|
---|
149 | echo "${SD_BORDER}${nl_}"
|
---|
150 |
|
---|
151 | # Install the files
|
---|
152 | [[ $VERBOSITY > 0 ]] && echo -n "Populating the ${BUILDDIR}${BLFS_ROOT} directory "
|
---|
153 | [[ ! -d ${BUILDDIR}${BLFS_ROOT} ]] && mkdir -pv ${BUILDDIR}${BLFS_ROOT}
|
---|
154 | rm -rf ${BUILDDIR}${BLFS_ROOT}/*
|
---|
155 | cp -r BLFS/* ${BUILDDIR}${BLFS_ROOT}
|
---|
156 | cp -r menu ${BUILDDIR}${BLFS_ROOT}
|
---|
157 | cp $COMMON_DIR/progress_bar.sh ${BUILDDIR}${BLFS_ROOT}
|
---|
158 | cp README.BLFS ${BUILDDIR}${BLFS_ROOT}
|
---|
159 | [[ $VERBOSITY > 0 ]] && echo "... OK"
|
---|
160 |
|
---|
161 | # Clean-up
|
---|
162 | [[ $VERBOSITY > 0 ]] && echo -n "Cleaning the ${BUILDDIR}${BLFS_ROOT} directory "
|
---|
163 | # We do not want to keep an old version of the book:
|
---|
164 | rm -rf ${BUILDDIR}${BLFS_ROOT}/$BLFS_XML
|
---|
165 | rm -rf ${BUILDDIR}${BLFS_ROOT}/$LFS_XML
|
---|
166 |
|
---|
167 | # Set some harcoded envars to their proper values
|
---|
168 | sed -i s@tracking-dir@$TRACKING_DIR@ \
|
---|
169 | ${BUILDDIR}${BLFS_ROOT}/{Makefile,gen-makefile.sh,gen_pkg_book.sh}
|
---|
170 |
|
---|
171 | # Ensures the tracking directory exists.
|
---|
172 | # Throws an error if it does not exist and the user does not
|
---|
173 | # have write permission to create it.
|
---|
174 | # If it exists, does nothing.
|
---|
175 | mkdir -p $TRACKING_DIR
|
---|
176 | [[ $VERBOSITY > 0 ]] && echo "... OK"
|
---|
177 |
|
---|
178 | [[ -z "$BLFS_BOOK" ]] ||
|
---|
179 | [[ $BLFS_BOOK = $BUILDDIR$BLFS_ROOT/$BLFS_XML ]] || {
|
---|
180 | [[ $VERBOSITY > 0 ]] && echo -n "Retrieving BLFS working copy (may take some time) "
|
---|
181 | cp -a $BLFS_BOOK $BUILDDIR$BLFS_ROOT/$BLFS_XML
|
---|
182 | [[ $VERBOSITY > 0 ]] && echo "... OK"
|
---|
183 | }
|
---|
184 |
|
---|
185 | [[ -z "$LFS_BOOK" ]] ||
|
---|
186 | [[ $LFS_BOOK = $BUILDDIR$BLFS_ROOT/$LFS_XML ]] || {
|
---|
187 | [[ $VERBOSITY > 0 ]] && echo -n "Retrieving the LFS working copy (may take some time) "
|
---|
188 | cp -a $LFS_BOOK $BUILDDIR$BLFS_ROOT/$LFS_XML
|
---|
189 | [[ $VERBOSITY > 0 ]] && echo "... OK"
|
---|
190 | }
|
---|
191 |
|
---|
192 | [[ $VERBOSITY > 0 ]] && echo "Initializing the BLFS tool directory "
|
---|
193 | make -j1 -C $BUILDDIR$BLFS_ROOT \
|
---|
194 | TRACKING_DIR=$TRACKING_DIR \
|
---|
195 | REV=$INITSYS \
|
---|
196 | LFS_XML=$BUILDDIR$BLFS_ROOT/$LFS_XML \
|
---|
197 | LFS-GIT=git://git.linuxfromscratch.org/lfs.git \
|
---|
198 | LFS-BRANCH=${LFS_TREE} \
|
---|
199 | BLFS_XML=$BUILDDIR$BLFS_ROOT/$BLFS_XML \
|
---|
200 | GIT=git://git.linuxfromscratch.org/blfs.git \
|
---|
201 | BLFS-BRANCH=${BLFS_TREE} \
|
---|
202 | $BUILDDIR$BLFS_ROOT/packages.xml
|
---|
203 | [[ $VERBOSITY > 0 ]] && echo "... OK"
|
---|
204 |
|
---|