#!/bin/bash
# Joe Arose aka..big_bass
##slim and powerful and very fast
# SLAXER PACKAGE MANAGEMENT The Xdialog version
# version 2.2 dependency checking and missing libs viewer added tlz tbz support
# A new GUI frontend was written
# Uses Slackwares official tools for the backend
# built the menu so that each selected option is a stand alone subroutine
# edit also lines 489-490 if you have another package management directory to use
# had to do that to get the viewer to work
# export PKG_MANAGEMENT="/var/log/setup/tmp"
# export ADM_DIR="/var/log"
#------------------------------------------------------
while :; do ##big loop
export PKG_MANAGEMENT="/var/log/setup/tmp"
export ADM_DIR="/var/log"
# to eliminate errors by using $TMP
# PKG_MANAGEMENT is the new name
# for /var/log/setup/tmp
#fix error in ls
cd `dirname "$0"`
rm -f $PKG_MANAGEMENT/new_installer_list*
rm -f /tmp/missing_libs2.txt
TARGET_DIR='/'
ADM_DIR=/var/log
ADM_PATH=/var/log
LOG=$PKG_MANAGEMENT/PKGTOOL.REMOVED
PKG_MANAGEMENT=$ADM_DIR/setup/tmp
if [ ! -d $PKG_MANAGEMENT ]; then
mkdir -p $PKG_MANAGEMENT
chmod 700 $PKG_MANAGEMENT
fi
Xdialog --title "Light X Package Tool Version 2.2 " \
--menu "\nWelcome to the Light Xdialog Slaxer package tool ( X ) \n\
\n for tgz ,txz ,tlz ,tbz packages\n
\n Tip : unmount drives you don't want to search to speed up the find \n
" 0 0 8 \
"xinstaller" "Install one or more packages from the current directory" \
"Remove" "Remove one or more packages that are currently installed" \
"View" "View the list of files contained in a package" \
"finder_tgz" "find all tgz packages on your linux box " \
"finder_txz" "find all txz packages on your linux box " \
"Dependency" "dependent and missing libs " \
"Exit" "Exit Pkgtool" 2> $PKG_MANAGEMENT/reply2
retval=$?
choice=`cat $PKG_MANAGEMENT/reply2`
REPLY2=`cat $PKG_MANAGEMENT/reply2`
case $retval in
0)
echo "'$choice' chosen."
;;
1)
echo "Cancel pressed."
exit
;;
255)
echo "Box closed."
exit
;;
esac
#--------------------------------------------
# ## Exit ##
#--------------------------------------------
if [ "$REPLY2" = "Exit" ]; then
echo "Exit" > $PKG_MANAGEMENT/reply3
exit
#--------------------------------------------
# ## xinstaller ##
#--------------------------------------------
elif [ "$REPLY2" = "xinstaller" ]; then
echo "xinstaller" > $PKG_MANAGEMENT/reply3
# Xdialog based light installer for slackware tgz and txz packages
#
# This is a new front end that uses the official installpkg as a backend
# to insure proper handling of the packages
# advantages speed , allowing different directories
# terminal viewing of install could be paused with -hold
# since package info is not displayed in a dialog box
# this allows you to run the official package tools without editing
# any files used by it so its safe to use this New GUI at any time
# files are deleted in $PKG_MANAGEMENT
#----------------------------------------
# generate $PKG_MANAGEMENT/new_installer_list
#----------------------------------------
ls $pwd -1 *.tgz >$PKG_MANAGEMENT/new_installer_list.tmp1
#simple file check to see if its a gzip compressed dat
for i in `cat $PKG_MANAGEMENT/new_installer_list.tmp1` ; do
file $i | grep " gzip compressed dat" >/dev/null
if [[ $? -eq 0 ]] ; then # we found it
# do stuff to file
echo $i >>$PKG_MANAGEMENT/new_installer_list.tmp2
fi
done
for i in `cat $PKG_MANAGEMENT/new_installer_list.tmp2` ; do
echo \"$i\" \" \" OFF "\\">> $PKG_MANAGEMENT/new_installer_list.tmp3
done
#now test for txz packages
#tgz uses tmp 1,2,3
#txz uses tmp 4,5, #appended to tmp3
ls $pwd -1 *.txz >$PKG_MANAGEMENT/new_installer_list.tmp4
#simple file check to see if its xz compressed
for i in `cat $PKG_MANAGEMENT/new_installer_list.tmp4` ; do
file $i | grep " xz compressed " >/dev/null
if [[ $? -eq 0 ]] ; then # we found it
# do stuff to file
echo $i >>$PKG_MANAGEMENT/new_installer_list.tmp5
fi
done
for i in `cat $PKG_MANAGEMENT/new_installer_list.tmp5` ; do
echo \"$i\" \" \" OFF "\\">> $PKG_MANAGEMENT/new_installer_list.tmp3
done
# added tlz tbz support no file checking
ls $pwd -1 *.tlz *.tbz >$PKG_MANAGEMENT/new_installer_list.tmp6
for i in `cat $PKG_MANAGEMENT/new_installer_list.tmp6` ; do
echo $i >>$PKG_MANAGEMENT/new_installer_list.tmp7
done
for i in `cat $PKG_MANAGEMENT/new_installer_list.tmp6` ; do
echo \"$i\" \" \" OFF "\\">> $PKG_MANAGEMENT/new_installer_list.tmp3
done
# quick check to see if no packages were found in this directory
# if no packages found xdialog would crash
if ! [ -s $PKG_MANAGEMENT/new_installer_list.tmp3 ];then
Xdialog --title "NO tgz or txz packages found" \
--infobox "\nYou must have tgz or txz packages in this directory!.\n" 0 0 7000
exit
fi
#----------------------------------------
# generate x_installer_viewer
#----------------------------------------
cat << 'EOF' >$PKG_MANAGEMENT/x_installer_viewer
#!/bin/sh
Xdialog --title " Package you want to install" \
--backtitle "Install package " \
--checklist "Select a package you want to install \
\n" 0 0 0 \
EOF
#build the list of packages to install
echo "`cat $PKG_MANAGEMENT/new_installer_list.tmp3`">> $PKG_MANAGEMENT/x_installer_viewer
echo '2> $PKG_MANAGEMENT/return2'>> $PKG_MANAGEMENT/x_installer_viewer
echo 'return' >> $PKG_MANAGEMENT/x_installer_viewer
chmod a+x $PKG_MANAGEMENT/x_installer_viewer
#----------------------------------------
# run the new "installer"
# $PKG_MANAGEMENT/x_installer_viewer
#----------------------------------------
. $PKG_MANAGEMENT/x_installer_viewer
#add multiple installs formating required couldn't echo this
#so its done after selection of the packages
# raw original convert slash to space
cat $PKG_MANAGEMENT/return2|sed 's/\// /g'> $PKG_MANAGEMENT/return2
# convert space to new line
cat $PKG_MANAGEMENT/return2 |tr ' ' '\n' > $PKG_MANAGEMENT/return2
#----------------------------------------
# start installer tgz
#----------------------------------------
#auto installer tgz
#check the file is not empty or nothing selected if empty do nothing
if [ -s $PKG_MANAGEMENT/return2 ]
then
for package in `cat $PKG_MANAGEMENT/return2`; do
installpkg $pwd/$package
echo $package
xterm -geometry 40x30+150+40 -e installpkg "$package"
Xdialog --title "Complete" \
--infobox "\nInstalling $package has finished.\n" 0 0 3000
done
#get the menus updated not needed for slackware can be safely commented out
/usr/sbin/fixmenus #hack for JWM and ICEWM
jwm -restart #hack for JWM and ICEWM Joe Arose aka big_bass
fi
#--------------------------------------------
# ## Remove ##
#--------------------------------------------
elif [ "$REPLY2" = "Remove" ]; then
echo "Remove" > $PKG_MANAGEMENT/reply3
#----------------------------------------
# generate temporary_list2
#----------------------------------------
# create_list_of_files_to_remove ()
#{
FILES=$(ls $ADM_DIR/packages)
cd $ADM_DIR/packages
{ grep '^PACKAGE DESCRIPTION:$' -Z -H -m1 -A1 $FILES; echo; } \
| sed -n 'h;n;/\x00/{h;n;};x;s/ */ /g;s/ $//;s/[\"`$]/\\&/g
s/\(.*\)\x00\([^:]*:\)\? *\(.*\)/ "\1" "" OFF \\/;p' > $PKG_MANAGEMENT/temporary_list2
touch $PKG_MANAGEMENT/temporary_list2
#}
cat << 'EOF' >$PKG_MANAGEMENT/xremove_package_viewer
#!/bin/sh
Xdialog --title " Package you want to remove" \
--backtitle "Remove package " \
--checklist "Select a package you want to remove \
\n" 0 0 0 \
EOF
#build the list of installed packages
echo "`cat $PKG_MANAGEMENT/temporary_list2`">> $PKG_MANAGEMENT/xremove_package_viewer
#the chosen value is used to view just that file from the main list
cat << 'EOF' >>$PKG_MANAGEMENT/xremove_package_viewer
2> $PKG_MANAGEMENT/return2
case $? in
0)
echo "Yes chosen.";;
1)
echo "No chosen."
return
;;
255)
echo "Box closed."
exit
;;
esac
#add multiple removes pre formating required
# raw original convert slash to space
cat $PKG_MANAGEMENT/return2 |sed 's/\// /g'> $PKG_MANAGEMENT/return2
# convert space to new line
cat $PKG_MANAGEMENT/return2 |tr ' ' '\n' > $PKG_MANAGEMENT/return2
# the return brings you to "if [ -L $LOG -o -r $LOG ]; then"
return
EOF
chmod a+x $PKG_MANAGEMENT/xremove_package_viewer
#----------------------------------------
# run the new "remover"
# $PKG_MANAGEMENT/xremove_package_viewer
#----------------------------------------
. $PKG_MANAGEMENT/xremove_package_viewer
#returns here from xremove_package_viewer if ok selected
if [ -L $LOG -o -r $LOG ]; then
rm -f $LOG
fi
cat /dev/null > $LOG
chmod 600 $LOG
#export ADM_DIR;
#remove_packages was a function but was placed as a stand alone app
for pkg_name in $(cat $PKG_MANAGEMENT/return2 | tr -d "\042")
do
if [ -r $ADM_DIR/packages/$pkg_name ]; then
Xdialog --title "PACKAGE REMOVAL IN PROGRESS" --cr-wrap --infobox \
"\nRemoving $pkg_name .\n\
\n\
Since each file must be checked \n\
against the contents of every other \n\
installed package to avoid wiping out \n\
areas of overlap, this process can take\n\
quite some time. If you'd like to watch\n\
the progress, flip over to another \n\
virtual console and type: \n\
\n\
tail -f $PKG_MANAGEMENT/PKGTOOL.REMOVED\n" 0 0 4000
export ROOT=$TARGET_DIR
removepkg $pkg_name >> $LOG 2> /dev/null
##I added a bonus tailbox here if you want it uncomment it
## Xdialog --title "TAIL BOX PKGTOOL.REMOVED" --tailbox $PKG_MANAGEMENT/PKGTOOL.REMOVED 24 64 0 3000
else
echo "No such package: $pkg_name. Can't remove." >> $LOG
fi
done
#end remove_packages routine
if [ "$(cat $PKG_MANAGEMENT/PKGTOOL.REMOVED)" = "" ]; then
rm -f $PKG_MANAGEMENT/PKGTOOL.REMOVED
Xdialog --title "NO PACKAGES REMOVED" \
--msgbox "Hit OK to return \
to the main menu." 0 0 2>$PKG_MANAGEMENT/reply2
case $? in
0)
echo "OK"
;;
255)
echo "Box closed."
exit
;;
esac
sleep 1
else
Xdialog --title "PACKAGE REMOVAL COMPLETE" --infobox "The packages have \
been removed.\n\
A complete log of the files that were\n\
removed has been created \n\
in $PKG_MANAGEMENT/: PKGTOOL.REMOVED." 0 0 2000
fi # end Remove
# return to the main menu:
#--------------------------------------------
# ## View ##
#--------------------------------------------
elif [ "$REPLY2" = "View" ]; then
echo "View" > $PKG_MANAGEMENT/reply3
#----------------------------------------
# generate list_of_installed_packages2
#----------------------------------------
FILES=$(ls $ADM_DIR/packages)
cd $ADM_DIR/packages
{ grep '^PACKAGE DESCRIPTION:$' -Z -H -m1 -A1 $FILES; echo; } \
| sed -n 'h;n;/\x00/{h;n;};x;s/ */ /g;s/ $//;s/[\"`$]/\\&/g
s/\(.*\)\x00\([^:]*:\)\? *\(.*\)/ "\1" "" OFF \\/;p' > $PKG_MANAGEMENT/list_of_installed_packages2
touch $PKG_MANAGEMENT/list_of_installed_packages2
#----------------------------------------
# generate viewsrc2
#----------------------------------------
cat << 'EOF' >$PKG_MANAGEMENT/viewsrc2
#!/bin/sh
#make the package selected to view a string value called RETURN2
RETURN2=`cat $PKG_MANAGEMENT/return2`
#then pipe that into xdialog
echo "`cat $ADM_DIR/packages/$RETURN2`" | Xdialog --title " $RETURN2 files " \--backtitle " $RETURN2 list " \--textbox "-" 0 0 0
EOF
chmod a+x $PKG_MANAGEMENT/viewsrc2
#----------------------------------------
# generate $PKG_MANAGEMENT/xpackage_viewer
#----------------------------------------
# this makes a script using echo
# with the new formated PACKAGE DESCRIPTION:
# make the xdialog head
cat << 'EOF' >$PKG_MANAGEMENT/xpackage_viewer
#!/bin/sh
Xdialog --title " Package you wish to view more info" \
--backtitle "Installed packages info " \
--radiolist "Select a package you want to view \
\n" 0 0 0 \
EOF
# build the list of installed packages
# this the body of the script
echo "`cat $PKG_MANAGEMENT/list_of_installed_packages2`">>$PKG_MANAGEMENT/xpackage_viewer
# the chosen value is used to view just that file from the main list
cat << 'EOF' >>$PKG_MANAGEMENT/xpackage_viewer
2> $PKG_MANAGEMENT/return2
case $? in
0)
echo "Yes chosen.";;
1)
echo "No chosen."
return
;;
255)
echo "Box closed."
exit
;;
esac
export PKG_MANAGEMENT="/var/log/setup/tmp"
export ADM_DIR="/var/log"
$PKG_MANAGEMENT/viewsrc2
EOF
# make it executable
chmod a+x $PKG_MANAGEMENT/xpackage_viewer
#----------------------------------------
# run the new "viewscr2"
# automatically from $PKG_MANAGEMENT/xpackage_viewer
#----------------------------------------
. $PKG_MANAGEMENT/xpackage_viewer
#end view
# return to the main menu:
return
#end view
# return to the main menu:
#--------------------------------------------
# ## finder_tgz ##
#--------------------------------------------
elif [ "$REPLY2" = "finder_tgz" ]; then
echo "finder_tgz" > $PKG_MANAGEMENT/reply3
#----------------------------------------
# generate $PKG_MANAGEMENT/new_installer_list
#----------------------------------------
cd /
find / -name '*.tgz' -exec echo {} \; >$PKG_MANAGEMENT/new_installer_list
# filter out initrd
cat /var/log/setup/tmp/new_installer_list | grep -v 'initrd' >$PKG_MANAGEMENT/new_installer_list
touch $PKG_MANAGEMENT/new_installer_list
#----------------------------------------
# generate $PKG_MANAGEMENT/view_all_tgz
#----------------------------------------
cat << 'EOF' >$PKG_MANAGEMENT/view_all_tgz
#!/bin/sh
# then stick that in your Xdialog pipe and smoke it :D
echo "`cat $PKG_MANAGEMENT/new_installer_list`" | Xdialog --title " TGZ finder " \--backtitle " All TGZ list " \--textbox "-" 0 0 0
EOF
chmod a+x $PKG_MANAGEMENT/view_all_tgz
. $PKG_MANAGEMENT/view_all_tgz
continue
#end of finder_tgz
# return to the main menu:
#--------------------------------------------
# ## finder_txz ##
#--------------------------------------------
elif [ "$REPLY2" = "finder_txz" ]; then
echo "finder_txz" > $PKG_MANAGEMENT/reply3
#----------------------------------------
# generate $PKG_MANAGEMENT/new_installer_list2
#----------------------------------------
#note here new_installer_list2 is used
cd /
find / -name '*.txz' -exec echo {} \; >$PKG_MANAGEMENT/new_installer_list2
# filter out initrd
cat /var/log/setup/tmp/new_installer_list2 | grep -v 'initrd' >$PKG_MANAGEMENT/new_installer_list2
touch $PKG_MANAGEMENT/new_installer_list2
#----------------------------------------
# generate $PKG_MANAGEMENT/view_all_txz
#----------------------------------------
cat << 'EOF' >$PKG_MANAGEMENT/view_all_txz
#!/bin/sh
# then stick that in your Xdialog pipe and smoke it :D
echo "`cat $PKG_MANAGEMENT/new_installer_list2`" | Xdialog --title " TXZ finder " \--backtitle " All TXZ list " \--textbox "-" 0 0 0
EOF
chmod a+x $PKG_MANAGEMENT/view_all_txz
. $PKG_MANAGEMENT/view_all_txz
continue
#end of finder_txz
# return to the main menu:
#--------------------------------------------
# ## Dependency_check ##
#--------------------------------------------
elif [ "$REPLY2" = "Dependency" ]; then
echo "Dependency" > $PKG_MANAGEMENT/reply3
# all the ELF executables listed in the find
# are tested with ldd
# a dependency list is generated with the correct program name
# showing all of the dependencies listed for that program
# a missing libs list is also generated
# it is added to the bottom of the depencency list if
# any missing dependencies are found
rm -f /tmp/missing_libs2.txt
mkdir -p /var/lib/pkgtool/dependencies ##everything is saved here
##firefox is odd in that it needs
## ldd /usr/lib/firefox/firefox-bin
## I need to make some special cases
## when you which firefox it points to a script in
# /usr/bin/firefox
# not at /usr/lib/firefox/firefox-bin
# you could fix that
# by placing it the path and adding to ld.so.config
#set up values
ADM_DIR=/var/log
ADM_PATH=/var/log
PKG_MANAGEMENT=$ADM_DIR/setup/tmp
rm -f $PKG_MANAGEMENT/filtered_list
rm -f $PKG_MANAGEMENT/lld_tmp_file2
rm -f $PKG_MANAGEMENT/lld_tmp_file3
# shows the installed packages
FILES=$(ls $ADM_DIR/packages)
cd $ADM_DIR/packages
{ grep '^PACKAGE DESCRIPTION:$' -Z -H -m1 -A1 $FILES; echo; } \
| sed -n 'h;n;/\x00/{h;n;};x;s/ */ /g;s/ $//;s/[\"`$]/\\&/g
s/\(.*\)\x00\([^:]*:\)\? *\(.*\)/ "\1" "" OFF \\/;p' > $PKG_MANAGEMENT/temporary_list2
touch $PKG_MANAGEMENT/temporary_list2
#----------------------------------------
# generate $PKG_MANAGEMENT/x_dependency_viewer
#----------------------------------------
# this makes a script using echo
# with the new formated PACKAGE DESCRIPTION:
# make the xdialog head
cat << 'EOF' >$PKG_MANAGEMENT/x_dependency_viewer
#!/bin/sh
Xdialog --title " Package you wish to view dependencies" \
--backtitle "Dependency info only ELF executables are shown " \
--radiolist "Select a package to view dependencies \
\n" 0 0 0 \
EOF
# build the list of installed packages
# this the body of the script
echo "`cat $PKG_MANAGEMENT/temporary_list2`">>$PKG_MANAGEMENT/x_dependency_viewer
# the chosen value is used to view just that file from the main list
cat << 'EOF' >>$PKG_MANAGEMENT/x_dependency_viewer
2> $PKG_MANAGEMENT/return2
case $? in
0)
echo "Yes chosen.";;
1)
echo "No chosen."
return
;;
255)
echo "Box closed."
exit
;;
esac
export PKG_MANAGEMENT="/var/log/setup/tmp"
export ADM_DIR="/var/log"
EOF
# make it executable
chmod a+x $PKG_MANAGEMENT/x_dependency_viewer
#----------------------------------------
# run the new "viewscr2"
# automatically from $PKG_MANAGEMENT/x_dependency_viewer
#----------------------------------------
. $PKG_MANAGEMENT/x_dependency_viewer
#all that just for a package name :S
PKGNAME=`cat $PKG_MANAGEMENT/return2`
# since the installed package has a header we remove it but first select a key word
if fgrep "./" $ADM_DIR/packages/$PKGNAME 1> /dev/null 2>&1; then
TRIGGER="^\.\/"
else
TRIGGER="FILE LIST:"
fi
#removes header
sed -n "/$TRIGGER/,/^$/p" < $ADM_DIR/packages/$PKGNAME | \
fgrep -v "FILE LIST:" | sort -u > $PKG_MANAGEMENT/delete_list2
#going to filter out possible executables to later check dependencies with a smaller list for speed
sed -n "/$TRIGGER/,/^$/p" < $ADM_DIR/packages/$PKGNAME | \
fgrep -v "FILE LIST:" | sort -u | egrep '(bin|sbin)' | egrep -v "/usr/doc*" | egrep -v "usr/share/doc*" | grep -v '/$' > $PKG_MANAGEMENT/filtered_list
#---------------------------------------
#generate a list of confirmed ELF files
#----------------------------------------
for i in `cat $PKG_MANAGEMENT/filtered_list`; do
#the first slash "/"is removed so add it onto the name
#a dependency file will be saved later using this name
echo "/$i" >>$PKG_MANAGEMENT/lld_tmp_file2
done
#---------------------------------------
#make the dependency files
#----------------------------------------
echo "finding dependencies"
#read the list of confirmed ELF files
#it is shown using path+filename
for i in `cat $PKG_MANAGEMENT/lld_tmp_file2 | xargs file | grep ELF | cut -f 1 -d :`
do
#strip off path
#a dependency file will be saved later using this name
echo "$i" | basename $i >$PKG_MANAGEMENT/lld_tmp_file3
#echo "$i" | basename $i
##removed some extra hex code here by filtering it first
ldd "$i">> /var/lib/pkgtool/dependencies/$PKGNAME"-filtering.txt"
#fixed missing dependency checker to display cleanly
LDD_RESULT="`ldd $i`"
MISSING_LIBS="`echo "$LDD_RESULT" | grep "not found" |uniq | cut -f 2 | cut -f 1 -d " " | tr "\n" " " `"
if [ ! "$MISSING_LIBS" = "" ];then
echo "">> /tmp/missing_libs2.txt
echo "-----------------------------------------------">> /tmp/missing_libs2.txt
echo " $PROGNAME has these missing library files:" >> /tmp/missing_libs2.txt
echo " $MISSING_LIBS" >> /tmp/missing_libs2.txt
echo "">> /tmp/missing_libs2.txt
fi
cat /var/lib/pkgtool/dependencies/$PKGNAME"-filtering.txt"| cut -f 1 -d '(' > /var/lib/pkgtool/dependencies/$PKGNAME"-depends.txt"
#if there are missing depends add the warning to the bottom of the list
cat /tmp/missing_libs2.txt >> /var/lib/pkgtool/dependencies/$PKGNAME"-depends.txt"
rm -f /var/lib/pkgtool/dependencies/$PKGNAME"-filtering.txt" ## clean up the extra unfilted file created
done
#----------------------------------------
# generate viewsrc2
#----------------------------------------
#make the package selected to view a string value called RETURN2
RETURN2=`cat $PKG_MANAGEMENT/return2`
#then pipe that into xdialog
echo "`cat /var/lib/pkgtool/dependencies/$RETURN2-depends.txt`" | Xdialog --title " $RETURN2 files " \--backtitle " $RETURN2 list " \--textbox "-" 0 0 0
# end depcheck
# return to the main menu:
return
fi # end for all the elifs
done