#!/bin/bash# Hello and welcome to the source code of my own Database program!# It is written in Bash Script and uses common applications you will find in linux.# most are free, except for rar.. # Ione line to give the program's name and an idea of what it does.##Copyright (C) 2007 Erin C. Gibson##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 #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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.#######Mounts the cdrommount /media/cdromfunction drill { echo ' what is the broadest pattern to be searched?' read patte echo ' what is the next broadest pattern to be searched?' read patte1 grep "$patte" database.db | grep "$patte1" | less #read patte #grep -i $patte database.db > temp_grep.txt #echo 'what is the next pattern?' #read patte #while ! [ -z $patte ] ; do # grep -i $patte temp_grep.txt > temp_grep1.txt # echo 'what is the next pattern?' # read patte # cat temp_grep1.txt > temp_grep.txt # done #cat temp_grep1.txt | sort | less}function search_copy {find $1 -maxdepth 100 -type f -name \*.$2 | xargs -i cp -rv {} $3#<- where the order of arguments is [source dir] [file type extension] [destination dir]} #Function for adding new items to the databasefunction new {function sedme {sed s?^?`date +%y-%m-%d`:? tmp_sed.txt > tmp_sed1.txt sed s?^?`$name`:? tmp_sed1.txt > tmp_sed.txt sed 's?^?'$cata':?' tmp_sed.txt >tmp_sed1.txt cat tmp_sed1.txt >> database.db cat tmp_sed1.txt }echo 'the name of the disk' awk '{print $2}' /dev/cdrom | head -1 > cdrom.txt cat cdrom.txt a="cat cdrom.txt" name=$a find /media/cdrom/* > tmp_sed.txt sed s?^?`date +%y-%m-%d`:? tmp_sed.txt > tmp_sed1.txt sed s#^#`$name`:# tmp_sed1.txt > tmp_sed.txt sed 's?^?'$cata':?' tmp_sed.txt >tmp_sed1.txt cat tmp_sed1.txt >> database.db cat tmp_sed1.txt FILES=(/media/cdrom/*.rar); if [ -e "$FILES" ] ; then find /media/cdrom/ -maxdepth 1 -type f -name \*.rar | xargs -i unrar lb {} > tmp_sed.txt sedme FILES=(/media/cdrom/*.tar); elif [ -e "$FILES" ] ; then find /media/cdrom/ -maxdepth 1 -type f -name \*.tar | xargs -i tar -tzf {} > tmp_sed.txt sedme FILES=(/media/cdrom/*.tar.gz); elif [ -e "$FILES" ] ; then find /media/cdrom/ -maxdepth 1 -type f -name \*.tar.gz | xargs -i tar -tzf {} > tmp_sed.txt sedme FILES=(/media/cdrom/*.gz); elif [ -e "$FILES" ] ; then find /media/cdrom/ -maxdepth 1 -type f -name \*.gz | xargs -i tar -tzf {} > tmp_sed.txt sedme FILES=(/media/cdrom/*.zip); elif [ -e "$FILES" ] ; then find /media/cdrom/ -maxdepth 1 -type f -name \*.zip | xargs -i tar -tzf {} > tmp_sed.txt sedme fi } function find_meta_file_ext { echo 'Type extension you wish to find' echo 'example .ext' read ext echo 'found this many' "$ext" cut -d: -f4 database.db | sort -u | grep -i $ext | wc -l echo 'Amount of disks associated with extension' "$ext" grep -i $ext database.db | cut -d: -f2 | sort -u | wc -l echo 'Said disks containing extension' "$ext" grep -i $ext database.db | cut -d: -f2 | sort -u }function show_cata {cut -d: -f1 database.db | sort -u | less }function search_copy2 {cp -rv movies* /home/erin/downloads/movies/cp -rv app* /home/erin/downloads/misc_vids/cp -rv misc_vid* /home/erin/downloads/apps/ }function multi { echo 'this is the multi search please imput as many patterns as you like' pattern=0 while [ "$pattern" != "" ]doecho ' what is the pattern?'read patternecho $pattern >> pattern.txtdonegrep -i --file=pattern.txt database.db > temp_grep1.txtrm pattern.txt}while [ "$option" != "quit" ]doecho '------------------------------------------------------------'echo 'Bash_Database version 1, Copyright (C) 2007 Aaron C. GibsonBash_Database comes with ABSOLUTELY NO WARRANTY; for detailstype "show w". This is free software, and you are welcometo redistribute it under certain conditions; type "show w"for details.'echo '----------------------------------------------------------'echo 'what do you want to do?'echo 'show cata?'echo 'find ext?'echo 'new?'echo 'fastadd?'echo 'list?'echo 'search?'echo 'multi?'echo 'drill?'echo 'copy?'echo 'backup?'echo 'quit?'read optioncase "$option" in"show w" )echo '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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.'a;;"new" ) echo 'what is the category?' read cata new ;;"show cata" ) show_cata ;;"find ext" )find_meta_file_ext;;"fastadd" ) echo 'what is the category?' read cata while [ "$answer" != "y" ] do mount /media/cdrom new eject /media/cdrom echo 'do you wish to quit?' read answer done ;; "list" ) cat database.db | sort | less ;; "search" ) echo 'What do you wish to search for?' read search grep -i $search database.db | sort | less ;;"drill" ) drill ;;"copy" ) while [ "$num" != "0" ] do mount /media/cdromsearch_copy ./ avi /home/erin/downloads/search_copy ./ mpeg /home/erin/downloads/search_copy ./ rm /home/erin/downloads/search_copy ./ rmvb /home/erin/downloads/search_copy ./ mpg /home/erin/downloads/search_copy ./ jpeg /home/erin/downloads/misc_vids/search_copy ./ jpg /home/erin/downloads/misc_vids/#search_copy ./ rar /home/erin/downloads/#search_copy ./ exe /home/erin/downloads/appssearch_copy ./ zip /home/erin/downloads/search_copy ./ tar /home/erin/downloads/search_copy ./ gz /homee/erin/downloads/search_copy2 eject cdrom echo 'are you finished?' read answer if [ "$answer" = "y" ] ; then num=0 fi done ;;"multi" )multicat temp_grep1.txt | sort | less;;"backup" )tar cvvzf database.sh.tar.gz database.*;;"quit" )echo 'umounting /media/cdrom'ejectesacdoneexit 0