LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 04-15-2013, 12:45 PM   #46
vdemuth
Member
 
Registered: Oct 2003
Location: West Midlands, UK
Distribution: Slackware 14 (Server),Suse 13.1 (Desktop),, Mepis on the wifes lappy
Posts: 768

Rep: Reputation: 92

Quote:
Originally Posted by jtsn View Post
There is a reason, why something like upgradepkg is called upgradepkg and not BreakMyMachine.

Really
 
Old 04-15-2013, 02:18 PM   #47
ruario
Senior Member
 
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 1,866

Rep: Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884
Quote:
Originally Posted by jtsn View Post
Instead of using weird names for a tool, I recommend to stick with something which is already in similar use in the Unix world:

Code:
checkpkg is a tool which checks Solaris packages for problems.

It analyzes files contained within package files. It's related to GAR, but it can be also used with any packages.
http://wiki.opencsw.org/checkpkg

There is a reason, why something like upgradepkg is called upgradepkg and not BreakMyMachine.
There are also plenty of names that use word play or are based on jokes in the *nix world though, e.g. tac (reverse cat), less and most (improved more commands), etc. Nothing wrong with it IMHO.
 
Old 04-17-2013, 04:03 AM   #48
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,763

Original Poster
Rep: Reputation: 471Reputation: 471Reputation: 471Reputation: 471Reputation: 471
Thanks to everyone for the great suggestions. I finally settled on just using 'pkg-check'. I'll attach here a copy of the first 'release'. It's not really exhaustive in what it does, but is handy anyway.

The program notifies you of any unusual content in already-created packages or directories with raw package content. It can be used for slackware-style *.txz packages, *.rpm or *.deb package archives. Using pkg-check is completely non-destructive -it only reports and makes no corrections or changes to package or directory content.
The command 'pkg-check --help' will show the help page.
Code:
#!/bin/bash
# pkg-check
# Copyright 2013 Gilbert Ashley <amigo@ibiblio.org>

# This program checks package content for any unusual conditions,
# It can be run using the name of a compressed package or the name
# of a directory which contains package content. Valid package
# types are slackware-style *.txz, *.rpm or *.deb archives.

# A bunch of neat ideas for the name of this program were given here:
# http://www.linuxquestions.org/questions/slackware-14/help-me-brainstorm-a-name-for-a-program-4175451639/
# Thanks to everyone for their suggestions.

Version=0.4

HERE=$PWD
Temp=/tmp/${0##*/}$$

rm -rf $Temp
mkdir -p $Temp

show_version() {
	echo $Version
	exit
}

show_help() {
	echo "${0##*/}: Check for unusual package content"
	echo "Syntax:"
	echo $'\t'"${0##*/} [OPTIONS] file-or-dir-name"
	echo "Options:"
	echo $'\t'"--help		Show this help page."
	echo $'\t'"--version	Show the program version number."
	echo $'\t'"--debug		Preserve temporary ananlysis files."
	echo
	#echo "${0##*/} checks package content and reports any 'unusual' conditions."
	echo "'unusual' package content means:"
	echo $'\t'"any files or directories which are not chowned root:root"
	echo $'\t'"any files or directories which are hidden"
	echo $'\t'"any links contained in the content"
	echo $'\t'"any directories which are not chmodded 755"
	echo $'\t'"any files which are empty"
	echo $'\t'"any scripts or binaries which are not chomdded 755 (unless in documents)"
	echo $'\t'"any 'regular files' which are not chmodded 644"
	echo $'\t'"any unusual locations, such as:/share, /include, /usr/etc, /usr/var,"
	echo $'\t'"    /usr/local, /root or /home"
	echo $'\t'"any static libraries in /lib"
	echo $'\t'"any missing package description file (for Slackware-type packages)"
	echo
	echo "The program output is meant to be informative and notifications"
	echo "should not necessarily be considered as warnings."
	echo "${0##*/} can be used to check Slackware-style *.txz, *.rpm or *.deb"
	echo "package archives or a directory where package content is located."
	exit
}

is_script_2() {
	local IFS=
	read -r -n 2 CHUNK < $1
	case "$CHUNK" in
		'') return 1 ;;
		\#!) return 0 ;;
		*) return 1 ;;
	esac
}

is_elf() {
	local IFS=
	read -r -n 4 CHUNK < $1
	case "$CHUNK" in
		'') return 1 ;;
		?ELF) return 0 ;;
		*) return 1 ;;
	esac
}

explode_rpm() {
  # this is a cut-down version from the exploderpm script
  # with only the '-x' archive extraction routine
  local pkg o sigsize gz
  pkg=$1
  o=104
  set -- $(od -j $o -N 8 -t u1 -- "$pkg")
  sigsize=$((8 + 16 *
      (256 * (256 * (256 * $2 + $3) + $4) + $5) +
      (256 * (256 * (256 * $6 + $7) + $8) + $9)))
  o=$((o + sigsize + (8 - (sigsize % 8)) % 8 + 8))
  set -- $(od -j $o -N 8 -t u1 -- "$pkg")
  o=$((o + 8 + 16 *
      (256 * (256 * (256 * $2 + $3) + $4) + $5) +
      (256 * (256 * (256 * $6 + $7) + $8) + $9)))
  comp=$(dd if="$pkg" ibs=$o skip=1 count=1 2>/dev/null \
      | dd bs=3 count=1 2> /dev/null)
  gz="$(echo -en '\037\0213')"
  #xz="$(echo -en '\0fd\037\07a\058\05a\000')"
  case "$comp" in
	BZh)      dd if="$pkg" ibs=$o skip=1 2>/dev/null | bunzip2 | cpio --quiet -ivdm ;;
	"$gz"*)   dd if="$pkg" ibs=$o skip=1 2>/dev/null | gunzip | cpio --quiet -ivdm ;;
	"]"*)     dd if="$pkg" ibs=$o skip=1 2>/dev/null | unxz | cpio --quiet -ivdm ;;
	*)        echo "Unrecognized rpm file: $pkg"; return 1 ;;
  esac
	
  [ $? != 0 ] && return 1
  
  return 0
}

case $1 in
	'') show_help ;;
esac

while [[ $1 ]] ; do
	case $1 in
		--version) show_version ;;
		--help) show_help ;;
		--debug) DEBUG=1 ; shift ;;
		*)
			if [[ -d $1 ]] ; then
				Workdir=$1
			elif [[ -e $1 ]] ; then 
				Object=$1
			fi
			shift
		;;
	esac

done

if [[ -d $Workdir ]] ; then
	cd $Workdir
	tar -cf - * |tar -tv > $Temp/full.list
	case $Workdir in
		/*) WD=$Workdir ;;
		*) WD=.;;
	esac
elif [[ -e $Object ]] ; then
	case $Object in
		/*) OBJECT=$Object ;;
		*) OBJECT=$PWD/$Object ;;
	esac
	case $Object in
		*.txz|*.tpkg) TAR_COMP=xz ;;
		*.tgz|*.pet) TAR_COMP=gzip ;;
		*.tbz|*.tbz2) TAR_COMP=bzip2 ;;
	esac
	
	mkdir -p $Temp/PKG
	cd $Temp/PKG
	WD=$PWD
	case $TAR_COMP in
		xz|gzip|bzip2)
			tar --use-compress-program=$TAR_COMP -xf $OBJECT
			# create a long listing of the archive content
			tar -cf - * |tar -tv > $Temp/full.list
		;;
		*)
			case $Object in
				*.deb)
					ar x $OBJECT &>/dev/null
					rm debian-binary control.tar.?z*
					# unpack and remove the remaining data archive
					tar -xf *.?z*
					rm -f data.tar.?z*
					# create the long listing
					tar -cf - * |tar -tv > $Temp/full.list
				;;
				*.rpm)
					explode_rpm $OBJECT &>/dev/null
					# create the long listing
					tar -cf - * |tar -tv > $Temp/full.list
				;;
			esac
		;;
	esac
fi

if [[ ! -s $Temp/full.list ]] ; then
	echo "No files found in: $Workdir"
fi

# Read the long listing from tar -tv from $Temp/full.list
# $1=perms $2=owner/group $3=size $4=date $5=time $6=filename
while read LINE ; do
	set -- $(echo $LINE)
	# strip off any leading './' from the  filename and use FILE
	case $6 in
		'./'*) FILE=${6:2} ;;
		*) FILE=${6} ;;
	esac
	
	# if the file basename starts with '.' it is hidden
	case ${FILE##*/} in
		.*) echo "$FILE" >> $Temp/hidden-item.list
	esac
	
	case $1 in
		l*) echo "$FILE" >> $Temp/link.list
		;;
		d*) 
			case $1 in
				drwxr-xr-x) : ;; # dir is chmod 755
				*) echo "$FILE" >> $Temp/dir-perm.list
			esac
			case $2 in
				root/root) : ;; # dir belongs to root
				*) echo "$FILE" >> $Temp/dir-owner.list
			esac
		;;
		b*|c*) : ;; # block or character device files -no comment for now
		-*)
			case $2 in
				root/root) : ;; # file belongs to root:root
				*) echo "$FILE" >> $Temp/file-owner.list ;;
			esac
			#Handle empty files
			case $3 in
				0) echo "$FILE" >> $Temp/empty-file.list
				;;
			esac
			if $(is_elf $FILE) || $(is_script_2 $FILE) ; then
				#echo $6
				case $1 in
					-rwxr-xr-x) : ;; # file is chmod 755
					*) 
						case $FILE in
							*'/doc/'*) : ;; #ignore example scripts in docs
							install/*) : ;; #ignore installer scripts
							*)
								echo "$FILE" >> $Temp/exe-perm.list
							;;
						esac
					;;
				esac
			else
				#echo $6
				case $1 in
					-rw-r--r--) : ;; # file is chmod 644
					*) echo "$FILE" >> $Temp/file-perm.list ;;
				esac
				
			fi
		;;
	esac
	case $FILE in
		share/|include/|usr/etc/|usr/var/|usr/local/|root/|home/) echo "$FILE" >> $Temp/location.list ;;
	esac
	
done < $Temp/full.list

# Now examine unpacked content
# if it was a Slackware or KISS package, it should contain a description file
case $Object in
	*.txz|*.tpkg)
		if [[ -s install/slack-desc ]] || [[ -s install/pkg-desc ]] ; then
			Have_desc=1
		else
			echo -e $'\t'"Package does not include a description file"
		fi
	;;
esac

if [[ -s $Temp/location.list ]] ; then
	echo "Unusual locations:"
	while read LINE ; do
		case $LINE in
			share/) echo $'\t'"$LINE"$'\t\t'"Bad prefix, execprefix" ;;
			include/) echo $'\t'"$LINE"$'\t'"Bad prefix, execprefix" ;;
			root/|home/) echo $'\t'"$LINE"$'\t\t'"Somebodies HOME dir??" ;;
			usr/etc/) echo $'\t'"$LINE"$'\t'"Possibly should be --sysconfdir=/etc" ;;
			usr/var/) echo $'\t'"$LINE"$'\t'"Possibly should be --localstatedir=/var" ;;
			usr/local/) echo $'\t'"$LINE"$'\t'"Possible faulty install prefix" ;;
		esac
	done < $Temp/location.list
fi

for STAT in $(ls lib/*.a 2> /dev/null) ; do
	echo $'\t'"$STAT"$'\t\t'"Static library in /lib"
done

if [[ -s $Temp/dir-perm.list ]] ; then
	echo "Directories with unusual permissions:"
	while read LINE ; do
		Perms=$(stat -c %a $WD/$LINE)
		echo -e $'\t'"$Perms"$'\t' "$LINE"
	done < $Temp/dir-perm.list
	echo
fi

if [[ -s $Temp/dir-owner.list ]] ; then
	echo "Directories with unusual owner and/or group:"
	while read LINE ; do
		Owner=$(stat -c %U $WD/$LINE)
		Group=$(stat -c %G $WD/$LINE)
		echo -e $'\t'"$Owner"':'"$Group"$'\t' "$LINE"
	done < $Temp/dir-owner.list
	echo
fi

if [[ -s $Temp/exe-perm.list ]] ; then
	echo "Executables with unusual permissions:"
	while read LINE ; do
		Perms=$(stat -c %a $WD/$LINE)
		echo -e $'\t'"$Perms"$'\t'"$LINE"
	done < $Temp/exe-perm.list
	echo
fi

if [[ -s $Temp/file-perm.list ]] ; then
	echo "Non-executables with unusual permissions:"
	while read LINE ; do
		Perms=$(stat -c %a $WD/$LINE)
		echo -e $'\t'"$Perms"$'\t' "$LINE"
	done < $Temp/file-perm.list
	echo
fi

if [[ -s $Temp/file-owner.list ]] ; then
	echo "Files with unusual owner and/or group:"
	while read LINE ; do
		Owner=$(stat -c %U $WD/$LINE)
		Group=$(stat -c %G $WD/$LINE)
		echo -e $'\t'"$Owner"':'"$Group"$'\t' "$LINE"
	done < $Temp/file-owner.list
	echo
fi

if [[ -s $Temp/link.list ]] ; then
	echo "Symbolic links:"
	# we could verify these links, but then we'd want to also
	# run any doinst.sh script and check any links created there.
	# leave it for now  -running doinst.sh is iffy anyway.
	while read LINE ; do
		echo -e $'\t'"$LINE"
	done < $Temp/link.list
	echo
fi

if [[ -s $Temp/hidden-item.list ]] ; then
	echo "Hidden items:"
	while read LINE ; do
		echo -e $'\t'"$LINE"
	done < $Temp/hidden-item.list
	echo
fi

if [[ -s $Temp/empty-file.list ]] ; then
	echo "Empty files:"
	while read LINE ; do
		echo -e $'\t'"$LINE"
	done < $Temp/empty-file.list
	echo
fi

if [[ $DEBUG -ne 1 ]] ; then
	cd $HERE
	rm -rf $Temp
fi
 
1 members found this post helpful.
Old 04-17-2013, 05:02 AM   #49
ruario
Senior Member
 
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 1,866

Rep: Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884
I see you have to run it as root or it complains about file ownership. Not a complaint, just wasn't obvious to me at first as I do not think this is the case with lintian or rpmlint, IIRC.

EDIT: Perhaps pkg-check should issue a warning if it was not run as root, saying that file ownership checks may not work correctly. Or you could do ownership checks by reading the output from a verbose tar (or cpio in the case of rpm) listing of the archive, which would allow non-root users to run it.

Last edited by ruario; 04-17-2013 at 05:26 AM.
 
Old 04-17-2013, 05:13 AM   #50
ruario
Senior Member
 
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 1,866

Rep: Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884
I think you should be checking that the directory naming matches that of tar 1.13, i.e. internally the tar should have directories formatted like this:

Code:
./
usr/
usr/bin/
usr/bin/example
install/
install/slack-desc
install/doinst.sh
rather than like this:

Code:
   
./
./usr/
./usr/bin/
./usr/bin/example
./install/
./install/slack-desc
./install/doinst.sh
Otherwise the Slackware packages are not valid and Pkgtools will complain.

Last edited by ruario; 04-17-2013 at 11:13 AM. Reason: Left out a slack-desc from my example packages. :p
 
Old 04-17-2013, 05:22 AM   #51
ruario
Senior Member
 
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 1,866

Rep: Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884
You might want to do some checks on the formatting of slack-desc itself, e.g. line length and that the first line is formatted with correctly, so that it displays correctly when --terse is used.
 
Old 04-17-2013, 11:45 AM   #52
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,763

Original Poster
Rep: Reputation: 471Reputation: 471Reputation: 471Reputation: 471Reputation: 471
Thanks for the suggestions -I knew there would be more things to (maybe) do. As commented in the code, it would be useful to check symlinks for hard-coded paths and/or symlinks which appear to be faulty or point to locations not included in the package. I may be able to get around needing to be root for it to be quiet when all is really okay with owner/group.
 
Old 10-22-2013, 04:48 AM   #53
ruario
Senior Member
 
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 1,866

Rep: Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884
This was a really nice idea. Anything further ever happen with it or is it on hold for now? I can understand if it is as you are doing this stuff for free. Just wondering?

P.S. If you are still working on it you might want to consider adding a warning/error if you try to make a package with spaces in the symlink path? They may point to valid locations but will not work in Slackware packages (as of right now).

Last edited by ruario; 10-22-2013 at 04:55 AM.
 
Old 10-22-2013, 05:13 AM   #54
slacktroll
Member
 
Registered: May 2011
Distribution: Slackware 14.0 on Thinkpad X60
Posts: 58

Rep: Reputation: 4
I vote for the name
inspector-gadget
 
Old 10-22-2013, 05:57 AM   #55
ruario
Senior Member
 
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 1,866

Rep: Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884
If you scroll up you will see he already went for the name pkg-check so the original request is solved. Now we (or at least I) are asking about exact functionality.
 
Old 10-22-2013, 06:30 AM   #56
PrinceCruise
Member
 
Registered: Aug 2009
Location: /Universe/Earth/India/Pune
Distribution: Slackware64 14.1/Current, CentOS 6.5/7.0
Posts: 773

Rep: Reputation: Disabled
Epic slacktroll is epic.


Regards.
 
Old 10-22-2013, 09:56 AM   #57
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,763

Original Poster
Rep: Reputation: 471Reputation: 471Reputation: 471Reputation: 471Reputation: 471
Good idea, ruario. In fact it would be good to indicate any object with spaces in the name. I'll get on this soon -I'm a kind-of winter-of-code guy... have you been using pkg-check?
 
Old 10-22-2013, 10:14 AM   #58
ruario
Senior Member
 
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 1,866

Rep: Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884
Quote:
Originally Posted by gnashley View Post
Good idea, ruario. In fact it would be good to indicate any object with spaces in the name. I'll get on this soon -I'm a kind-of winter-of-code guy... have you been using pkg-check?
I was but then I forgot about it. Time to start again I think!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Brainstorm about a hypothetical system trademark91 General 8 02-09-2011 08:44 AM
Unofficial name brainstorm for LM11 (and beyond) Kenny_Strawn Linux Mint 2 02-03-2011 02:38 AM
LXer: The New Ubuntu Brainstorm LXer Syndicated Linux News 0 01-14-2009 02:20 PM
I have a Brainstorm, for a Linux programmer mickeyboa Linux - Software 4 04-17-2008 03:52 PM
Brainstorm corbintechboy General 47 01-14-2007 09:13 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration