Skip to content

Commit

Permalink
0.5: simplify and dash (not bash)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Apr 18, 2020
1 parent 43ce4d2 commit fa0ac87
Show file tree
Hide file tree
Showing 23 changed files with 486 additions and 680 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bash-deb-build.
0.3
0.5

# Bash DEB build.

Expand All @@ -14,6 +14,6 @@ Bash-script for build deb package:
dpkg, grep, tar, gzip, bzip2, lzma, coreutils, binutils

---
2018
2020
zvezdochiot
https://github.com/zvezdochiot/bash-deb-build
https://github.com/BASH-Auto-Tools/bash-deb-build
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4
0.5
6 changes: 3 additions & 3 deletions control
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package: bash-deb-build
Version: 0.4
Version: 0.5
Architecture: all
Maintainer: zvezdochiot <[email protected]>
Section: utils
Priority: optional
Installed-Size: 36
Depends: dpkg, grep, tar, gzip, coreutils, binutils
Homepage: http://mykaralw.narod.ru/
Installed-Size: 20
Homepage: https://github.com/BASH-Auto-Tools/bash-deb-build
Description: Bash-script for build deb package.
Bash-script for build deb package:
build:
Expand Down
278 changes: 120 additions & 158 deletions deb-build.sh
Original file line number Diff line number Diff line change
@@ -1,202 +1,164 @@
#!/bin/bash
#!/bin/sh
#deb-build.sh

VER="0.4"
GREEN="\033[1;32m"
RED="\033[0;31m"
YELLOW="\033[1;33m"
ENDCOLOR="\033[0m"

VER="0.5"
DEFPACK="gzip"

tproc=`basename $0`
echo -e $GREEN"$tproc version $VER"$ENDCOLOR
echo "$tproc version $VER"
echo ""

usage()
{
tproc=`basename $0`
echo -e $YELLOW"usage:"$ENDCOLOR
echo -e $GREEN" sudo bash $tproc [gzip|bzip2|lzma]"$ENDCOLOR
echo "usage:"
echo " sudo bash $tproc [options]"
echo " options:"
echo " -c [gzip|bzip2|lzma] - compress method"
echo " -h - this help"
exit 0
}

goodfinish()
{
echo ""
echo -e $YELLOW"OK.\n"$ENDCOLOR
echo "OK.\n"
echo ""
}

testargs()
{
if [ "+$1" != "+" -a "+$1" != "+gzip" -a "+$1" != "+bzip2" -a "+$1" != "+lzma" ]
if [ "+$1" = "+--help" -o "x$1" = "x-h" ]
then
usage
usage
fi
}

testcomponent()
{
tnocomp=""
tcomp="/bin/grep"
tdeb="grep_*.deb"
if [ ! -f "$tcomp" ]
then
tnocomp="$tnocomp $tcomp($tdeb)"
fi
tcomp="/usr/bin/awk"
tdeb="gawk_*.deb"
if [ ! -f "$tcomp" ]
then
tnocomp="$tnocomp $tcomp($tdeb)"
fi
tcomp="/bin/tar"
tdeb="tar_*.deb"
if [ ! -f "$tcomp" ]
then
tnocomp="$tnocomp $tcomp($tdeb)"
fi
tcomp="/bin/gzip"
tdeb="gzip_*.deb"
if [ ! -f "$tcomp" ]
then
tnocomp="$tnocomp $tcomp($tdeb)"
fi
tcomp="/usr/bin/md5sum"
tdeb="coreutils_*.deb"
if [ ! -f "$tcomp" ]
then
tnocomp="$tnocomp $tcomp($tdeb)"
fi
tcomp="/usr/bin/ar"
tdeb="binutils_*.deb"
if [ ! -f "$tcomp" ]
tcomp="grep"; [ $(which $tcomp) ] || tnocomp="$tnocomp $tcomp"
tcomp="awk"; [ $(which $tcomp) ] || tnocomp="$tnocomp $tcomp"
tcomp="tar"; [ $(which $tcomp) ] || tnocomp="$tnocomp $tcomp"
tcomp="ar"; [ $(which $tcomp) ] || tnocomp="$tnocomp $tcomp"
tcomp="gzip"; [ $(which $tcomp) ] || tnocomp="$tnocomp $tcomp"
tcomp="md5sum"; [ $(which $tcomp) ] || tnocomp="$tnocomp $tcomp"
if [ "x$tnocomp" != "x" ]
then
tnocomp="$tnocomp $tcomp($tdeb)"
fi
if [ "+$tnocomp" != "+" ]
then
echo -e $RED"Not found $tnocomp !"$ENDCOLOR
echo ""
exit 0
echo "ERROR: Not found $tnocomp !"
echo ""
exit 1
fi
}

testroot()
{
if [ $USER != root ]
if [ "$USER" != "root" ]
then
echo -e $RED"You no root!"$ENDCOLOR
echo ""
usage
exit 0
echo "ERROR: You no root!"
echo ""
usage
exit 1
fi
}

main()
{
if [ "+$1" = "+" ]
then
PACK=$DEFPACK
else
PACK="$1"
fi
if [ "$PACK" = "gzip" ]
then
PACKOPT="--gzip"
PACKSUF="tar.gz"
fi
if [ "$PACK" = "bzip2" ]
then
PACKOPT="--bzip2"
PACKSUF="tar.bz2"
fi
if [ "$PACK" = "lzma" ]
then
PACKOPT="--lzma"
PACKSUF="tar.lzma"
fi
if [ -d "config" -a -d "data" ]
PACK=$DEFPACK
while getopts ":c:h" opt
do
case $opt in
c) PACK="$OPTARG"
;;
h) usage
;;
*) echo "ERROR: Unknown option -$OPTARG" >&2
exit 1
;;
esac
done
case "$PACK" in
bzip2) PACKOPT="--bzip2"; PACKSUF="tar.bz2"
;;
lzma) PACKOPT="--lzma"; PACKSUF="tar.lzma"
;;
*) PACK="gzip"; PACKOPT="--gzip"; PACKSUF="tar.gz"
;;
esac
echo "Compress: $PACK"
if [ -d "DEBIAN" -a -d "CONTENTS" ]
then
mkdir "root"
cp -r "config" "root/control"
cp -r "data" "root/data"
cd "root"
chown -R root *
chgrp -R root *
cd "control"
rm -f "md5sums"
packname=`grep "^Package:" control | awk '{print $2}'`
vername=`grep "^Version:" control | awk '{print $2}'`
archname=`grep "^Architecture:" control | awk '{print $2}'`
debname=$packname"_"$vername"_"$archname".deb"
echo "$debname"

cd "../data"
echo "Package: $packname"
echo ""

echo "1) Compress contents of the package..."
tar -cvf "../data.tar" ./
echo ""
echo "SUMMARY:"
stat -c "%n : %s" "../data.tar"
echo ""
if [ "$PACK" = "gzip" ]
then
gzip -v "../data.tar"
fi
if [ "$PACK" = "bzip2" ]
then
bzip2 -v "../data.tar"
fi
if [ "$PACK" = "lzma" ]
then
lzma -v "../data.tar"
fi
echo ""

echo "2) Creating checksum..."
for tdir in *
do
if [ -d "$tdir" ]
then
find "$tdir" -type f -printf "\"%p\"\n" | xargs md5sum >> "../md5sums"
fi
done
cat "../md5sums"
echo ""

cd ../
mv -f "md5sums" "control"

cd control
echo "3) Compress of a package..."
tar -czvf "../control.tar.gz" ./
echo ""

cd ../
echo "4) Creating an index version packing deb package..."
echo "2.0" > "debian-binary"
cat "debian-binary"
echo ""

echo "5) Deb package assembly..."
ar -qS "$debname" "debian-binary" "control.tar.gz" "data.$PACKSUF"
cp "$debname" ../
cd ../
rm -fr root
echo ""
else
if [ ! -d "config" ]
then
echo "Not [config] packages!"
fi
if [ ! -d "data" ]
then
echo "Not [data] packages!"
fi
mkdir "root"
cp -r "DEBIAN" "root/DEBIAN"
cp -r "CONTENTS" "root/CONTENTS"
cd "root"
chown -R root *
chgrp -R root *
cd "DEBIAN"
rm -f "md5sums"
packname="$(grep '^Package:' control | awk '{print $2}')"
vername="$(grep '^Version:' control | awk '{print $2}')"
archname="$(grep '^Architecture:' control | awk '{print $2}')"
debname=$packname"_"$vername"_"$archname".deb"
echo "$debname"

cd "../CONTENTS"
echo "Package: $packname"
echo ""

echo "1) Creating checksum..."
for tdir in *
do
if [ -d "$tdir" ]
then
find "$tdir" -type f -printf "\"%p\"\n" | xargs md5sum >> "../DEBIAN/md5sums"
fi
done
cat "../DEBIAN/md5sums"
echo ""

echo "2) Compress contents of the package..."
tar -cvf "../data.tar" ./
echo ""
echo "SUMMARY:"
stat -c "%n : %s" "../data.tar"
echo ""
case "$PACK" in
bzip2) bzip2 -v "../data.tar"
;;
lzma) lzma -v "../data.tar"
;;
*) gzip -v "../data.tar"
;;
esac
echo ""

cd "../DEBIAN"
echo "3) Compress of a package..."
tar -czvf "../control.tar.gz" ./
echo ""

cd ../
echo "4) Creating an index version packing deb package..."
echo "2.0" > "debian-binary"
cat "debian-binary"
echo ""

echo "5) Deb package assembly..."
ar -qS "$debname" "debian-binary" "control.tar.gz" "data.$PACKSUF"
cp "$debname" ../
cd ../
rm -fr root
echo ""
else
if [ ! -d "DEBIAN" ]
then
echo "Not [DEBIAN] packages!"
fi
if [ ! -d "CONTENTS" ]
then
echo "Not [CONTENTS] packages!"
fi
fi
}

Expand Down
Loading

0 comments on commit fa0ac87

Please sign in to comment.