LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch
User Name
Password
Linux From Scratch This 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


Reply
  Search this Thread
Old 07-03-2014, 03:56 AM   #1
ReaperX7
LQ Guru
 
Registered: Jul 2011
Location: California
Distribution: Slackware64-15.0 Multilib
Posts: 6,558
Blog Entries: 15

Rep: Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097
Cool [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
 
Old 07-03-2014, 04:11 AM   #2
basica
Member
 
Registered: Nov 2011
Location: Australia
Distribution: Arch, LFS
Posts: 171

Rep: Reputation: 38
I hope you don't mind me pitching in..

Code:
#!/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
 
Old 07-03-2014, 04:30 AM   #3
ReaperX7
LQ Guru
 
Registered: Jul 2011
Location: California
Distribution: Slackware64-15.0 Multilib
Posts: 6,558

Original Poster
Blog Entries: 15

Rep: Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097
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.

Last edited by ReaperX7; 07-03-2014 at 04:31 AM.
 
Old 07-03-2014, 07:08 PM   #4
basica
Member
 
Registered: Nov 2011
Location: Australia
Distribution: Arch, LFS
Posts: 171

Rep: Reputation: 38
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.
 
Old 07-03-2014, 08:33 PM   #5
ReaperX7
LQ Guru
 
Registered: Jul 2011
Location: California
Distribution: Slackware64-15.0 Multilib
Posts: 6,558

Original Poster
Blog Entries: 15

Rep: Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097
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.

Last edited by ReaperX7; 07-03-2014 at 08:36 PM.
 
Old 07-03-2014, 09:04 PM   #6
basica
Member
 
Registered: Nov 2011
Location: Australia
Distribution: Arch, LFS
Posts: 171

Rep: Reputation: 38
Everyone has their own way of doing things, nothing wrong with that
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LFS-7.3 install script Johnburrell Linux From Scratch 0 03-06-2013 12:44 AM
[SOLVED] Need help writing basic bash script to toggle two i8kctl commands (fan speed hi/low) Dennola4 Slackware 5 06-12-2011 10:33 AM
Make an simple install script for my pc LFS 6.5 bucovaina78 Linux From Scratch 1 10-16-2009 07:30 PM
Writing an Install Script msgforsunil Linux - General 6 06-07-2006 02:04 AM
Is there a basic iso of a preconfigured LFS that I can download? t3gah Linux From Scratch 3 03-14-2005 08:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch

All times are GMT -5. The time now is 03:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration