LinuxQuestions.org
Help answer threads with 0 replies.
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 11-21-2015, 11:08 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
Post [Helpful scripts] Useful add-on scripts for B/LFS


I've recently been crafting some extra scripts that can be used in Linux From Scratch using the template script and some reverse engineering of scripts from Slackware.

Though he may not read it, many thanks to Patrick Volkerding for keeping Slackware a script based init system or this effort would not have been possible.

And many thanks as well to Bruce Dubbs and crew from LFS for providing a useful template script.

If you have any other scripts you'd like to share feel free to post them here and include instructions on how to use them. A brief description is not necessary, but it will be smiled upon.

==================================================

Name: ConsoleKit

Usage: Provides a start and stop daemon script for ConsoleKit to ensure complete shutdown of the service once the system is issued the halt/reboot/shutdown/poweroff signal.

Script (install to /etc/rc.d/init.d):
Code:
#!/bin/sh
########################################################################
# Begin ConsoleKit
#
# Description : Start/stop script for ConsoleKit daemon
#
# Authors     : James Powell (adapted from Patrick Volkerding's script
#		for Slackware and other scripts by Bruce Dubbs of LFS.)
#
# Version     : LFS Custom
#
#
########################################################################

### BEGIN INIT INFO
# Provides:             console-kit-daemon
# Required-Start:	dbus
# Required-Stop:        dbus
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Short-Description:	Starts the console-kit-daemon utility for session management
# X-LFS-Provided-By:	Custom
### END INIT INFO

. /lib/lsb/init-functions

case "${1}" in
   start)
      log_info_msg "Starting ConsoleKit..."
      start_daemon /usr/bin/console-kit-daemon
      sleep 1
      evaluate_retval
      ;;

   stop)
      log_info_msg "Stopping ConsoleKit..."
      if [ -r /run/ConsoleKit/pid ]; then
         killproc -p /usr/bin/console-kit-daemon
         rm -f /run/ConsoleKit/pid
      fi
      evaluate_retval
      ;;

   restart)
      ${0} stop
      sleep 1
      ${0} start
      ;;

   *)
      echo "Usage: ${0} {start|stop|restart}"
      exit 1
      ;;
esac

exit 0

# End consolekit
Setup instructions
Code:
ln -sf ../../init.d/consolekit /etc/rc.d/rc0.d/K29consolekit
ln -sf ../../init.d/consolekit /etc/rc.d/rc1.d/K29consolekit
ln -sf ../../init.d/consolekit /etc/rc.d/rc6.d/K29consolekit
ln -sf ../../init.d/consolekit /etc/rc.d/rc2.d/S31consolekit
ln -sf ../../init.d/consolekit /etc/rc.d/rc3.d/S31consolekit
ln -sf ../../init.d/consolekit /etc/rc.d/rc4.d/S31consolekit
ln -sf ../../init.d/consolekit /etc/rc.d/rc5.d/S31consolekit
I chose command issues 29 and 31 as a reference point because dbus is a required start up and shutdown.

Last edited by ReaperX7; 11-23-2015 at 09:30 AM.
 
Old 01-25-2016, 05:25 PM   #2
huffdad
Member
 
Registered: Jan 2006
Location: Missouri
Distribution: Slackware & LFS
Posts: 31

Rep: Reputation: 6
I have been using a barely modified copy of Slackware's package management, so these should work for anyone who also uses Slack's tools. With some modification it should work fine with a custom-made tarball package management, which I plan to create, but not yet. I fall short in many areas when it comes to Linux, but I enjoy making scripts.

First is my "buildit" script. It is intended for use with package creation. It is very buggy if you redirect the output to a file. I decided to write this one when I realized somewhere during BLFS that my /lib64 directory wasn't a symlink to /lib like it was supposed to be. I'd like to rework a few parts, include more error checking, and clean it up a bit, but I haven't worked out the correct syntaxes yet.

Usage is:
buildit.sh <appname> <optional version number>
This moves the contents of the lib64 directories into lib, strips debugging symbols, then executes makepkg, incorporating the <appname> <version> arguments into the file name for that is automatically saved into the local repository directory. The REPO variable prepends $LFS so that it should work both during the tools build, and the chroot build.
Code:
#!/bin/bash
# J. Huffman -- 29January2016
# buildit.sh to automate the things I usually forget
# should have already done configure, make, make DESTDIR install
# and cd into the $DESTDIR

# Define some variables for ease of editing
APP=$1
VER=$2
if [ ! $REPO ] ; then REPO=$LFS/repo ; fi

# Make sure an argument has been passed, or else exit.
if [ ! $APP ] ; then
	printf "\n\nUsage: buildit.sh <appname> <optional.version.num>\n\n"
	exit
fi

# Move "lib64's" into "lib's", due to the way Slack's makepkg handles
# symlinks. This should prevent accidentally obliterating the root
# file system structure during install, since lib64's are just symlinks.

# Make sure any hidden files are included in the upcoming move.
shopt -s dotglob

# move/copy the lib64 files/folders
if [ -d lib64 ] ; then
	if [ ! -d lib ] ; then
		mv lib64 lib
		else cp -R lib64/* lib && rm -fr lib64
	fi
fi
if [ -d usr/lib64 ] ; then
	if [ ! -d usr/lib ] ; then
		mv usr/lib64 usr/lib
		else cp -R usr/lib64/* usr/lib && rm -fr usr/lib64
	fi
fi
if [ -d usr/local/lib64 ] ; then
	if [ ! -d usr/local/lib ] ; then
		mv usr/local/lib64 usr/local/lib
		else cp -R usr/local/lib64/* usr/local/lib \
		     && rm -fr usr/local/lib64
	fi
fi
shopt -u dotglob

# Now that the directories are (hopefully) good, create the slack-desc
# file.  My system currently has a slack-desc template file that I sed
# substitute the package name then edit with vim. Remove or alter the
# following lines as you deem appropriate.
if [ ! -d install ] ; then mkdir install ; fi
cp ~/Documents/slack-desc.template install/slack-desc
sed -i "s/appname/$APP/g" install/slack-desc
vim install/slack-desc

# strip debugging symbols
# This is the same command as LFS ch 6.72 - Stripping Again
find {,usr/}{bin,lib,sbin} -type f -exec strip --strip-debug '{}' ';'

# Now build the package and save it to the repository
# Alter the lines below to suit your system's method of package creation. 
if [ ! -d $REPO ] ; then mkdir $REPO ; fi
makepkg -l y -c n $REPO/"$APP"-"$VER"-x86_64-1jh.tgz

# Prompt for cleanup.
printf "\nDelete the contents of the build directory? (y/n)"
read SMASH
if [ "$SMASH" = "y" ] ; then
	rm -fr *
	else
	printf "\nKeeping build tree.\n\n"
fi
And the second one searches the local tarball repository for a given file or directory name (passed as a command line argument). I plan to add more error checking into it, but it works as advertised. For now, it complains if there are non-tarballs in the repo directory. It is more resource intensive than, for example, a search through the files in (Slackware's) /var/log/packages, but it yields an accurate display of the current contents of a package.
Code:
#!/bin/bash
# pkgprobe - created on: 25January2016 by J. Huffman
# Script for searching through the package repository and probing each
# tarball package for a string given as the command line argument.

# Define vars
if [ "$REPO" = "" ] ; then REPO="$LFS/repo" ; fi
FILE=$(mktemp)

# If no argument has been passed, echo usage statement.
if [ ! $1 ] ; then 
	echo -e "\npkgprobe USAGE:"
	echo -e "[REPO=/repo_dir] [TMP=/temp_dir] pkgprobe <filename>\n"
	echo -e "where <filename> is the file or directory to be found."
	echo -e "Variables (if any) should precede the command.\n"
else

# The main loop
for PKG in $REPO/*   # Searches every file in the repo directory
do
	
	cat /dev/null > $FILE   # Reset $FILE to empty for each iteration.
        for ARCHIVE in $(tar -tf $PKG)
	do
		if [ $(basename $ARCHIVE) = $1 ]
		then
			echo $ARCHIVE >> $FILE
		fi
	done


	if [ $(stat -c s $FILE) != 0 ]
	then
		echo
		echo "==================================================="
		echo "$PKG contains:"
		echo "==================================================="
		cat $FILE
        fi
done
fi
rm $FILE
Sample output from the "pkgprobe" script:

# pkgprobe lynx

===================================================
/repo/lynx-2.8.9dev8-x86_64-1jh.tgz contains:
===================================================
./usr/bin/lynx
./etc/lynx/


Hopefully someone finds these tools useful. What I like most about these two scripts is that they can be used during every stage of B/LFS, even as early as creating the temporary toolchain, if one so desires.

Last edited by huffdad; 01-29-2016 at 08:54 PM.
 
  


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 scripts for chapter 5 moisespedro Linux From Scratch 0 09-13-2014 10:49 PM
Building LFS v7.5-rc1 via scripts stoat Linux From Scratch 10 02-23-2014 10:25 PM
samples of LFS build scripts dimaash Linux From Scratch 3 07-20-2005 09:35 PM
Is anyone else installing LFS with shell scripts SparceMatrix Linux From Scratch 25 06-12-2003 01:29 AM
as promised scripts for auto LFS NGraphiX Linux From Scratch 11 11-04-2002 05:49 AM

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

All times are GMT -5. The time now is 02:37 PM.

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