LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Help me brainstorm a name for a program (https://www.linuxquestions.org/questions/slackware-14/help-me-brainstorm-a-name-for-a-program-4175451639/)

vdemuth 04-15-2013 12:45 PM

Quote:

Originally Posted by jtsn (Post 4931956)
There is a reason, why something like upgradepkg is called upgradepkg and not BreakMyMachine.


Really:)

ruario 04-15-2013 02:18 PM

Quote:

Originally Posted by jtsn (Post 4931956)
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.

gnashley 04-17-2013 04:03 AM

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


ruario 04-17-2013 05:02 AM

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.

ruario 04-17-2013 05:13 AM

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.

ruario 04-17-2013 05:22 AM

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.

gnashley 04-17-2013 11:45 AM

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.

ruario 10-22-2013 04:48 AM

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).

slacktroll 10-22-2013 05:13 AM

I vote for the name
inspector-gadget

ruario 10-22-2013 05:57 AM

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.

PrinceCruise 10-22-2013 06:30 AM

Epic slacktroll is epic. ;)


Regards.

gnashley 10-22-2013 09:56 AM

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?

ruario 10-22-2013 10:14 AM

Quote:

Originally Posted by gnashley (Post 5050380)
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! ;)


All times are GMT -5. The time now is 05:50 PM.