Browse Source

function modules

master
ale 3 years ago
parent
commit
3dda858895
5 changed files with 182 additions and 176 deletions
  1. +2
    -0
      install.sh
  2. +3
    -176
      lch
  3. +97
    -0
      lib/check.sh
  4. +40
    -0
      lib/compressor.sh
  5. +40
    -0
      lib/decompressor.sh

+ 2
- 0
install.sh View File

@ -12,6 +12,8 @@ echo " Installing lch"
echo "======================"
echo ""
cp lch /usr/bin/lch
mkdir -p /usr/lib/lch
cp ./lib/* /usr/lib/lch
chmod 755 /usr/bin/lch
echo " Copied lch in /usr/bin"


+ 3
- 176
lch View File

@ -4,85 +4,9 @@ DEST=$1
shift 1
ORIG=$@
function decompressor()
{
case $DEST in
*.tar)
tar -xvf $DEST
;;
*.tar.gz | *.tgz)
tar -xzvf $DEST
;;
*.tar.bz2 | *.tbz | *.tbz2 | *.tb2)
tar xjf $DEST
;;
*.tar.xz | *.txz)
tar -xf $DEST
;;
*.bz2)
bzip2 -d $DEST
;;
*.gz)
gzip -d $DEST
;;
*.zip)
unzip $DEST
;;
*.7z)
7za e $DEST
;;
*.rar)
unrar x $DEST
;;
*)
echo "Extension not found."
echo -e "For more information run 'lch --help'\n"
;;
esac
echo -e "\nDone"
exit 0
}
function compressor()
{
case $DEST in
*.tar)
tar -cvf $DEST $ORIG
;;
*.tar.gz | *.tgz)
tar -czvf $DEST $ORIG
;;
*.tar.bz2 | *.tbz | *.tbz2 | *.tb2)
tar -c $ORIG | bzip2 > $DEST
;;
*.tar.xz | *.txz)
tar -cJf $DEST $ORIG
;;
*.bz2)
bzip2 -c $ORIG > $DEST
;;
*.gz)
gzip -c $ORIG > $DEST
;;
*.zip)
zip -r $DEST $ORIG
;;
*.7z)
7za a $DEST $ORIG
;;
*.rar)
rar a $DEST $ORIG
;;
*)
echo "Extension not found."
echo -e "For more information run 'lch --help'\n"
;;
esac
echo -e "\nDone"
exit 0
}
source /usr/lib/lch/compressor.sh || source ./lib/compressor.sh
source /usr/lib/lch/decompressor.sh || source ./lib/decompressor.sh
source /usr/lib/lch/check.sh || source ./lib/check.sh
function help()
{
@ -107,103 +31,6 @@ function help()
echo ""
}
function check()
{
local a=false
echo -e "Verification of compression systems:\n"
echo -e "Systems\t\t\tStatus"
echo "----------------------------------"
for i in "rar" "unrar" "tar" "bzip2" "gzip" "zip" "7za"
do
if ! [ -x "$(command -v $i)" ]
then
echo -e "$i\t\t\t\e[91mNot Installed\e[0m"
$a = true
else
echo -e "$i\t\t\t\e[32mInstalled\e[0m"
fi
done
if $a
then
echo -e "\nIn order to use all the extensions install the packages: tar, bzip2, gzip, zip, 7za, rar, unrar"
fi
echo ""
exit 0
}
function rarInstall(){
if [[ $(uname -m) -eq "x86_64" ]]
then
RAR_URL="https://www.rarlab.com/rar/rarlinux-x64-5.9.1.tar.gz"
RAR_FILE="rarlinux-x64-5.9.1.tar.gz"
else
RAR_URL="https://www.rarlab.com/rar/rarlinux-5.9.1.tar.gz"
RAR_FILE="rarlinux-5.9.1.tar.gz"
fi
wget $RAR_URL
tar -zxvf $RAR_FILE
cd rar
cp -v rar unrar /usr/local/bin/
cd ..
rm -r rar $RAR_FILE
echo "rar/unrar installed."
}
function install()
{
echo -e "Install dependencies\n"
if [ "$UID" != "0" ]; then
echo " Only root can execute this script, sorry."
echo " Try 'sudo $0 $DEST'"
exit 0
fi
if [ -e "$(command -v rar)" ]
then
echo "rar installed."
else
rarInstall
fi
if [ -x "$(command -v apt)" ]
then
echo -e "APT system detected\n"
apt install -y tar bzip2 gzip zip p7zip-full 1> /dev/null
elif [ -n "$(grep "centos" /etc/*-release)" ]
then
echo -e "CentOS system detected\n"
yum install -y -q epel-release 1> /dev/null
rpm -U --quiet http://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm 1> /dev/null
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 1> /dev/null
yum repolist 1> /dev/null
yum install -y -q tar bzip2 gzip zip p7zip 1> /dev/null
elif [ -x "$(command -v dnf)" ]
then
echo -e "DNF system detected\n"
dnf install -y -q tar bzip2 gzip zip p7zip 1> /dev/null
elif [ -x "$(command -v yum)" ]
then
echo -e "Yum system detected\n"
yum install -y -q tar bzip2 gzip zip p7zip 1> /dev/null
elif [ -x "$(command -v pacman)" ]
then
echo -e "Pacman system detected\n"
pacman -Sqy --noconfirm tar bzip2 gzip zip p7zip 1> /dev/null
elif [ -x "$(command -v zypper)" ]
then
echo -e "Zypper system detected\n"
zypper install -y tar bzip2 gzip zip p7zip-full 1> /dev/null
else
echo -e "System installer not detected\n"
fi
echo -e "\nDependencies installation finished\n"
exit 0
}
if [ "$DEST" = "--help" ] || [ "$DEST" = "-h" ]
then
help


+ 97
- 0
lib/check.sh View File

@ -0,0 +1,97 @@
#!/bin/bash
function check()
{
local a=false
echo -e "Verification of compression systems:\n"
echo -e "Systems\t\t\tStatus"
echo "----------------------------------"
for i in "rar" "unrar" "tar" "bzip2" "gzip" "zip" "7za"
do
if ! [ -x "$(command -v $i)" ]
then
echo -e "$i\t\t\t\e[91mNot Installed\e[0m"
$a = true
else
echo -e "$i\t\t\t\e[32mInstalled\e[0m"
fi
done
if $a
then
echo -e "\nIn order to use all the extensions install the packages: tar, bzip2, gzip, zip, 7za, rar, unrar"
fi
echo ""
exit 0
}
function rarInstall(){
if [[ $(uname -m) -eq "x86_64" ]]
then
RAR_URL="https://www.rarlab.com/rar/rarlinux-x64-5.9.1.tar.gz"
RAR_FILE="rarlinux-x64-5.9.1.tar.gz"
else
RAR_URL="https://www.rarlab.com/rar/rarlinux-5.9.1.tar.gz"
RAR_FILE="rarlinux-5.9.1.tar.gz"
fi
wget $RAR_URL
tar -zxvf $RAR_FILE
cd rar
cp -v rar unrar /usr/local/bin/
cd ..
rm -r rar $RAR_FILE
echo "rar/unrar installed."
}
function install()
{
echo -e "Install dependencies\n"
if [ "$UID" != "0" ]; then
echo " Only root can execute this script, sorry."
echo " Try 'sudo $0 $DEST'"
exit 0
fi
if [ -e "$(command -v rar)" ]
then
echo "rar installed."
else
rarInstall
fi
if [ -x "$(command -v apt)" ]
then
echo -e "APT system detected\n"
apt install -y tar bzip2 gzip zip p7zip-full 1> /dev/null
elif [ -n "$(grep "centos" /etc/*-release)" ]
then
echo -e "CentOS system detected\n"
yum install -y -q epel-release 1> /dev/null
rpm -U --quiet http://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm 1> /dev/null
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 1> /dev/null
yum repolist 1> /dev/null
yum install -y -q tar bzip2 gzip zip p7zip 1> /dev/null
elif [ -x "$(command -v dnf)" ]
then
echo -e "DNF system detected\n"
dnf install -y -q tar bzip2 gzip zip p7zip 1> /dev/null
elif [ -x "$(command -v yum)" ]
then
echo -e "Yum system detected\n"
yum install -y -q tar bzip2 gzip zip p7zip 1> /dev/null
elif [ -x "$(command -v pacman)" ]
then
echo -e "Pacman system detected\n"
pacman -Sqy --noconfirm tar bzip2 gzip zip p7zip 1> /dev/null
elif [ -x "$(command -v zypper)" ]
then
echo -e "Zypper system detected\n"
zypper install -y tar bzip2 gzip zip p7zip-full 1> /dev/null
else
echo -e "System installer not detected\n"
fi
echo -e "\nDependencies installation finished\n"
exit 0
}

+ 40
- 0
lib/compressor.sh View File

@ -0,0 +1,40 @@
#!/bin/bash
function compressor()
{
case $1 in
*.tar)
tar -cvf $1 $2
;;
*.tar.gz | *.tgz)
tar -czvf $1 $2
;;
*.tar.bz2 | *.tbz | *.tbz2 | *.tb2)
tar -c $2 | bzip2 > $1
;;
*.tar.xz | *.txz)
tar -cJf $1 $2
;;
*.bz2)
bzip2 -c $2 > $1
;;
*.gz)
gzip -c $2 > $1
;;
*.zip)
zip -r $1 $2
;;
*.7z)
7za a $1 $2
;;
*.rar)
rar a $1 $2
;;
*)
echo "Extension not found."
echo -e "For more information run 'lch --help'\n"
;;
esac
echo -e "\nDone"
exit 0
}

+ 40
- 0
lib/decompressor.sh View File

@ -0,0 +1,40 @@
#!/bin/bash
function decompressor()
{
case $1 in
*.tar)
tar -xvf $1
;;
*.tar.gz | *.tgz)
tar -xzvf $1
;;
*.tar.bz2 | *.tbz | *.tbz2 | *.tb2)
tar xjf $1
;;
*.tar.xz | *.txz)
tar -xf $1
;;
*.bz2)
bzip2 -d $1
;;
*.gz)
gzip -d $1
;;
*.zip)
unzip $1
;;
*.7z)
7za e $1
;;
*.rar)
unrar x $1
;;
*)
echo "Extension not found."
echo -e "For more information run 'lch --help'\n"
;;
esac
echo -e "\nDone"
exit 0
}

Loading…
Cancel
Save