#!/bin/bash # Lazy Man's Unpacking Tool ############################################################################ # Copyright (C) 2004 by Rami Chowdhury # # rami.chowdhury@gmail.com # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation; either version 2 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the # # Free Software Foundation, Inc., # # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ########################################################################## #determines the type of file to be unpacked echo "Rami's Unpacker + Installer, at your service!" sleep 0.5 function HandleOptions { case $1 in -x | --debug ) set -x shift;; -h | --help ) echo "Usage is \"unPack FILENAME\" to decompress and install FILENAME" exit 1;; -*) echo "The only valid option is -x or --debug, for debugging!" shift;; esac } function typofile { if [ -f "$thefile" ]; then case "$thefile" in #tries to get filetype *.tar.gz ) filtyp=1;; #gzipped TARchive *.tgz ) filtyp=1;; #gzipped TARchive *.tar.bz2) filtyp=2;; #bzip2-ed TARchive *.tar ) filtyp=3;; #plain TARchive *.zip ) filtyp=4;; #simple Zip archive *.rpm ) filtyp=5;; #RPM Package Management Package - to be dealt with separately *) filtyp=0;; #other type, can't deal with it esac return 0 elif [ -z "$thefile" ]; then return 1 else echo "$thefile is not a regular file. Sorry." exit 1 fi } #actually does all the unpacking function unfak { echo "Unpacking..." case "$filtyp" in 1 ) echo "It is a gzipped TAR archive" tar -xvzf $thefile > $thefile.txt return 0;; 2 ) echo "It is a bzip2-ed TAR archive" tar -xvjf $thefile > $thefile.txt return 0;; 3 ) echo "It is a plain old TAR archive" tar -xvf $thefile > $thefile.txt return 0;; 4 ) echo "It is a simple Zip archive" unzip -v $thefile > $thefile.txt return 0;; 5 ) echo "It is an RPM package. You must enter the superuser password to install..." su -c "rpm -Uvh $thefile" root return 0;; 0 ) echo "It is in an unknown format." return 1;; * ) echo "Something fucked up. Oops!" return 1;; esac } #determines the folder to which the file was extracted function folderdet { headlyne=$(head -n1 $thefile.txt | grep / ) foldr="${headlyne%%/*[a-z]}" if [ -d "$foldr" ]; then return 0 else echo "Bugger, check the folderdet function." return 1 fi } #renames the folder, if that option is chosen function foldrename { echo "Please enter the new name:" read newname mv "$foldr" "$newname" foldr="$newname" if [ -d "$foldr" ]; then return 0 else echo "Bugger, check the foldrename function." return 1 fi } function installer { echo "Starting install..." #enter your preferred prefixes here. prefixes= if [ -f "configure" ] || [ -f "Makefile" ]; then echo "The necessary files are here. Installing..." sleep 0.5 if [ -f "configure" ]; then ./configure $prefixes || { echo "Didn't work!" exit 1 } fi make || { echo "Didn't work!" exit 1 } else echo "The required files are not present. You'll have to do it manually." return 1 fi echo "Are you sure you want to install this (you have to enter the superuser password)?" read surinst if [ "$surinst" = "Y*" ] || [ "$surinst" = "y*" ]; then echo "You must enter the superuser password before you can finish the install." su -c "make install" root && echo "Done!" return 0 else echo "OK, quitting..." sleep 0.5 make clean return 0 fi } #the main body, which calls all the other bits HandleOptions $* repeet=y thefile=$(find *$1*) until [ "$repeet" = "n" ] || [ "$repeet" = "N" ]; do if typofile; then echo "Unpacking $thefile..." else echo "Sorry, that file doesn't exist. Please try again." exit 1 fi if unfak; then if [ "$filtyp" = "5" ]; then echo "RPM package installed! To uninstall, type rpm -ev ${thefile%.?pm} as the superuser." exit 0 fi if folderdet; then echo "Unpacking $thefile successful! It has been extracted to $foldr." sleep 0.5 echo "Would you like to rename the folder?" read renam if [ "$renam" = "y" ] || [ "$renam" = "Y" ]; then if foldrename; then echo "The folder is now $foldr." else echo "The rename didn't work. The folder is still $foldr." fi sleep 0.5 fi echo "Would you like to install the files you just extracted?" read instal if [ "$instal" = "y" ] || [ "$instal" = "Y" ]; then cd "$foldr" if installer; then cd .. echo "Thanks for using me!" else cd .. echo "Thanks for using me!" fi fi rm $thefile.txt #put a "#" in front of this if you want to keep the list of files extracted else echo "Uh oh, something's wrong! But don't worry, it *should* have been extracted! Just look for the folder with a similar name to the original file ($thefile)!" exit 1 fi else echo "Didn't work (wrong type of file?). Try again!" exit 1 fi echo "Would you like to unpack another file?" read repeet if [ "$repeet" = "Y" ] || [ "$repeet" = "y" ]; then echo "Which file would you like to unpack?" read newfyle thefile=$(find *$newfyle*) fi done