[How-to] Writing a basic install script for B/LFS.
Linux From ScratchThis Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
[How-to] Writing a basic install script for B/LFS.
Often you find that you really just don't have time to perform an action to build something in LFS and other issues come up. The dog needs to be shaved, the cat needs a bath, the bird got into the Cheerios, or the gold fish took a poo that requires some careful scooping. To combat this, I wrote this SIMPLE script to handle most of the functions minus entries that would require command inputs that trigger a utility, and trust me, when you have to give a cat a bath, not worrying about your Linux box is priority. Kitty has claws and a bottle of baby shampoo is about the only weapon you'll have.
Anyway, here is a basic template I use:
Code:
#!/bin/sh
pushd /sources
tar -xvf <package-name>-*.tar.*
cd <package-name>-*
cd ..
rm -rf <package-name>-?.?.?
popd
Now of course for the bootstrap system I change /sources to $LFS/sources.
Now I don't always use * and revert to using ?.?.? for version control issues where a multiple named package could exist. However, I use the ? placeholder when removing a source extraction because if you use * it can delete the tarballed source also, and that's bad.
For the in between lines, I copy in whatever is listed in the book. I often skip the testing steps but you can add them, but do see my how-to on outputting stdout and stderr to a log file rather than the console.
Anyways, hope this helps and enjoy giving you cat a well needed bath. You cat will make sure to thank you later. :-p
#!/bin/bash
case "$1" in
-t)
./configure --prefix=/tools
make
make install
;;
-u)
./configure --prefix=/usr
make
make install
;;
-r)
cd ..
remove_this_dir=$(echo $lfs_package_dir)
rm -rfv $remove_this_dir
if [[ $remove_this_dir == binutils* ]] ||
[[ $remove_this_dir == glibc* ]] ||
[[ $remove_this_dir == gcc* ]];
then
short=$(echo $remove_this_dir | sed 's/-[.0-9]\{1,5\}//g')
rm -rfv "$short-build"
fi
unset lfs_package_dir
;;
-i)
tar -axvf $2
create_dir=$(echo $2 | grep -E "tar\.[a-z0-9]{2,3}" | sed 's/.tar.[a-z0-9]\{2,3\}//g;s/.orig//g;s/vim-7.4/vim74/g')
export lfs_package_dir="$create_dir"
cd $lfs_package_dir
;;
*)
echo "use an option, man"
;;
esac
EDIT: Added extra features, explained below:
You must run this through sourcing it as it relies on doing its thing in your current shell. In other words you run it as follows
Code:
. lfs -option optional parameter
or
Code:
source lfs -option optional parameter
The options are as follows
-i : run . lfs -i package-name. It will extract and cd into the directory for you.
-t : run . lfs -t and this will perform a .configure --prefix=/tools followed by make and make install
-u : run . lfs -u and it will do the above but to the /usr folder instead. In sections 5 and 6 there are a few packages that require only these commands to be run (maybe 8 to 10 in each chapter). This automates those package installations a fair bit.
-r : run . lfs -r and this will cd you out of the directory and remove it. In one or two of the packages there's a subdirectory created where this won't work, but I'll update that shortly. All you'll need to do in the mean time is cd into the main directory (cd ..) and then run it and you're good to go.
Anyways, any suggestion on improving this would be nice!
Last edited by basica; 07-03-2014 at 10:32 PM.
Reason: updated code
I know Keith has his scripts for his LFSpkg toolkit, but I've just used a basic shell script as my work horse. Keeping it simple to basic command calls has always worked best for me.
As far as anything else goes, in BLFS, I keep my cleaned source packages to use with make uninstall as needed. BLFS is the only place I change out the rm -rf command for make clean. As Gentoo, I treat the LFS base as a single entity, much like FreeBSD. This way the core is the core, and everything else is treated as add-ons.
So, I just completed yet another LFS build and I gotta say that I saved a lot of time. Besides the the benefit of getting familiar with the book, I also gained speed boosts from running the above script. In essence it halved the common commands (untarring, then cdding in, and on the end part, cdding out then rm -rf ). I also saved time by doing the following where appropriate:
Code:
make && make install && . lfs -r
Though interestingly, doing that at the gettext package resulted in an error. Running the commands individually though was fine. Very interesting. Lastly, I noticed a lot of packages have the formula of simply configuring the path and then making and installing. I will probably add a third case to cover those to further improve on time. I would say that this time around, I spent about 4 and a half hours (4.5 hours) from start to finish. My last install was about double that and my first successful install took the better part of two days.
I think for my next install, I'm probably going to use a package manager of sorts. We'll see.
To me the best package manager is make. As twisted that sounds, it's actually the absolute best solution.
The commands make install and make uninstall both perform a great job in their own rights. If you archive your make clean sources as I do, you'll spend a lot less time worrying about an after-market package manager, like pacman, pkgtools, etc.
The only part of the system I actually package is the core itself. One I get LFS completed, I generally add in the recommended software from BLFS that's in the Reboot Chapter, complete BLFS Chapter 3, then backup the sources, remove the sources, and then backup the finished system, and restore the sources.
This way, I have my sources, my core, and the rest BLFS is just a variable that's sacrificial.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.