Wednesday, 8 June 2016

How to create debian package without tarball file?


Prerequisites

  1. Installed packages 
    1. build-essential
    2. fakeroot
    3. devscripts
    4. gnupg-agent
    5. debhelper
    6. dh_make
Notes:

  1. This tutorial is useful to develop a quick Debian package example.
  2. This tutorial doesn't have any explanation' s for 
    1. Debian rules.
    2. Various Debian build stage' s.
    3. license creation and attaching to Debian package.
    4. Debian man pages creation& integrating to the Debian package.
    5. Debian package creation from existing tarball.
    6. how to write debian package build changes.
    7. gpg key for Debian Package

Step1: add Debian Package default Name, Email-Id to global environment variables /etc/environment.

DEBEMAIL="developer@zerooneprograms.com"
DEBFULLNAME="zerooneprograms"
EMAIL="support@zerooneprograms.com"

Step2: add Debian Package Name, installation script file name, HOME Folder Path for Script& Package Version.

SOURCEBINPATH=$(pwd)
SOURCEBIN=zerooneprograms
DEBFOLDER=zerooneprograms
DEBVERSION=1.0

Step3: Create Folder Debian Package with below  naming Conventions

DEBFOLDERNAME=$DEBFOLDER-$DEBVERSION
# Create your scripts source dir
mkdir $DEBFOLDERNAME

Step4: Copy the installation script file to the Debian Package HOME Folder.

# Copy your script to the source dir
cp $SOURCEBINPATH/$SOURCEBIN $DEBFOLDERNAME
cd $DEBFOLDERNAME

Step5: Create Sample Files& Folder/ Skeleton from Standard Debian Package Format.

# Create the packaging skeleton (debian/*)
dh_make  -s --indep --createorig

|-- debian
|   |-- rules
|   |-- copoyright
|   |-- control
|   |-- changelog
|   |-- patches
|   |-- source
|   `-- upstream
|-- doc
|   |-- man
|   |   `-- fr
|   |-- syntax
|   `-- texinfo
|-- m4
|-- po
`-- src

Step6: Change the script files for below, based on package requirements

  1. add zerooneprograms script file to root folder 
  2. preinstallation scripts
  3. post installation scripts
  4. pre remove scripts
  5. post remove scripts
  6. control file
  7. rules

echo "\nchange control file, preins, postins,prerm and postrm and hit the <Enter> with any key"
read temp

Step7: Create custom Linux terminal commands,  debian/install has instructions to create File& Folder' s while installing the package. Below line will add the file zerooneprograms script in /usr/bin, which creates a terminal command.
echo $SOURCEBIN usr/bin > debian/install

add the instructions to create Folder' s and to copy the files& Folder to the Specific path.

Step8: Remove the all unnecessary files 
# Remove the example files
rm debian/*.ex

Step9: Remove the all unnecessary files 
dpkg-buildpackage -uc -us   #without key


Example Script for creating the debian package  create.sh 

#!/bin/bash
# Configure your paths and filenames
SOURCEBINPATH=$(pwd)
SOURCEBIN=zerooneprograms
DEBFOLDER=zerooneprograms
DEBVERSION=1.0


DEBFOLDERNAME=$DEBFOLDER-$DEBVERSION

# Create your scripts source dir
mkdir $DEBFOLDERNAME

# Copy your script to the source dir
cp $SOURCEBINPATH/$SOURCEBIN $DEBFOLDERNAME
cd $DEBFOLDERNAME

# Create the packaging skeleton (debian/*)
dh_make  -s --indep --createorig

echo "\nchange control file, preins, postins,prerm and postrm and hit the <Enter> with any key"
read temp

# Remove make calls
#grep -v makefile debian/rules > debian/rules.new
#mv debian/rules.new debian/rules

#mkdir -p debian/tmp

#cp $SOURCEBINPATH/$SOURCEBIN  debian/tmp/
# debian/install must contain the list of scripts to install
# as well as the target directory
echo $SOURCEBIN usr/bin > debian/install
#echo test opt >> debian/install

# Remove the example files
rm debian/*.ex

# Build the package.
# You  will get a lot of warnings and ../somescripts_0.1-1_i386.deb
#debuild -S -rfakeroot -k<gpg_key_id>

#debuild -S -rfakeroot -k50F6E79D
#(or)
dpkg-buildpackage -uc -us   #without key


Example rules for Debian Package Creation

#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

#%:
# dh $@
clean:
dh_testdir
dh_testroot
rm -f build-stamp configure-stamp

install: build
dh_testdir
dh_testroot
dh_clean -k 
dh_installdirs

# Add here commands to install the package into debian/flare.

install -d debian/opt/ZeroOnePrograms
cp -r $(CURDIR)/../ZeroOnePrograms    $(CURDIR)/debian/zerooneprograms/opt


# Sample RULE's

# install -m 755 $(DISTSDIR)/*              $(CURDIR)/debian/tmp/opt/
# bunzip2                          $(CURDIR)/debian/tmp/usr/share/doc/debian-book/*pdf*.bz2
# install -m 644 $(DISTSDIR)/*latex*.bz2    $(CURDIR)/debian/tmp/usr/share/doc/debian-book/
# cp -r          $(SRCDIR)/htmlsplit        $(CURDIR)/debian/tmp/usr/share/doc/debian-book/
# install -m 644 $(CURDIR)/debian/copyright $(CURDIR)/debian/tmp/usr/share/doc/debian-book/
# install -m 644 $(SRCDIR)/*.html           $(CURDIR)/debian/tmp/usr/share/doc/debian-book/
# install -m 644 $(SRCDIR)/*.css            $(CURDIR)/debian/tmp/usr/share/doc/debian-book/
# cp -r          $(SRCDIR)/images           $(CURDIR)/debian/tmp/usr/share/doc/debian-book/
# cp             $(CURDIR)/LICENSE          $(CURDIR)/debian/tmp/usr/share/doc/debian-book/
# cp             $(CURDIR)/AUTHORS          $(CURDIR)/debian/tmp/usr/share/doc/debian-book/
# gzip           $(CURDIR)/debian/tmp/usr/share/doc/debian-book/AUTHORS
# cp             $(CURDIR)/README           $(CURDIR)/debian/tmp/usr/share/doc/debian-book/
# gzip           $(CURDIR)/debian/tmp/usr/share/doc/debian-book/README
# cp             $(CURDIR)/TODO             $(CURDIR)/debian/tmp/usr/share/doc/debian-book/
# gzip           $(CURDIR)/debian/tmp/usr/share/doc/debian-book/TODO
# cp             $(CURDIR)/README.Debian    $(CURDIR)/debian/tmp/usr/share/doc/debian-book/
# gzip           $(CURDIR)/debian/tmp/usr/share/doc/debian-book/README.Debian
# cp             $(CURDIR)/ChangeLog        $(CURDIR)/changelog
# mv             $(CURDIR)/changelog        $(CURDIR)/debian/tmp/usr/share/doc/debian-book/
# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
dh_testdir
dh_testroot
dh_installchangelogs 
# dh_installdocs --exclude=CVS
# dh_installexamples
dh_install
# dh_installmenu
# dh_installdebconf
# dh_installlogrotate
# dh_installemacsen
# dh_installpam
# dh_installmime
# dh_installinit
# dh_installcron
# dh_installinfo
# dh_installman
dh_link
# dh_strip
dh_compress --exclude=.pdf --exclude=LICENSE
dh_fixperms
# dh_perl
# dh_python
# dh_makeshlibs
dh_installdeb
# dh_shlibdeps
dh_gencontrol
dh_md5sums
dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configu 


Reference

How to Validate SSL Certificates with bash script?

Prerequisites

  1. SSL Certificates
  2. OpensSSL to be Installed


Step1: Prompt for the SSL Certificates File Paths

echo "Reference"
echo "---------"
echo "enduser-example.com.crt
enduser-example.com.key
enduser-example.com.chain"
echo ""
echo ""
echo "Please Provide full Path for Certificate (enduser-example.com.crt)"

            if [ -e $PATH_CERT_FILE ];then
                    #Do Nothing
               echo ""
            else
                    echo "Wrong Path"
                exit 1
            fi

echo "Please Provide full path for Intermediate Certificate (enduser-example.com.chain|gd_bundle.crt)"
            read PATH_INTERMEDIATE_CERT
                        if [ -e $PATH_CERT_FILE ];then
                                #Do Nothing
                                echo ""
                        else
                                echo "Wrong Path"
                                exit 1
                        fi

echo "Please Provide the full path for Private Key File(enduser-example.com.key)"
            read PATH_KEY_FILE
                        if [ -e $PATH_CERT_FILE ];then
                                #Do Nothing
                                echo ""
                        else
                                echo "Wrong Path"
                                exit 1
                        fi

Step2: validate the certificates with OpenSSL tool

#Validating Certificates
_status=$(openssl verify -CAfile $PATH_INTERMEDIATE_CERT  $PATH_CERT_FILE | grep OK)
            result=$(echo $_status | cut -f2 -d ':')
            if [ "$result" != " OK" ]; then
                echo "Please Verify The Certificates and Try Again.."
                exit 1
            fi

How to change VHost Name & respective SSL Certificates with Bash Script?

Step1: change the VHost ServerName/Domain Name with sed
sed -i "s@OldDomain.*@NewDomain@g"

Step2: Prompt for the New Certificates Absolute Path& Validate them from above Procedure
Step3: On Successful validation, copy the certificate files to new Folder.

            #Configuring the Certificates
            _date=$(date +"%H%M%S")
            mkdir -p /etc/apache2/$_date
            echo $_date
            cp $PATH_CERT_FILE    /etc/apache2/"$_date"/
            cp $PATH_INTERMEDIATE_CERT /etc/apache2/"$_date"/
            cp $PATH_KEY_FILE  /etc/apache2/"$_date"/       


Step4: Copy the absolute path of each certificate to a variable.
            _CERT_FILE=$(echo "$PATH_CERT_FILE"| rev |cut -f1 -d '/' |rev)
            NEW_PATH_CERT_FILE=/etc/apache2/"$_date"/"$_CERT_FILE"

                _INTERMEDIATE_CERT_FILE=$(echo "$PATH_INTERMEDIATE_CERT"| rev |cut -f1 -d '/' |rev)
            NEW_PATH_INTERMEDIATE_CERT=/etc/apache2/"$_date"/"$_INTERMEDIATE_CERT_FILE"

            _KEY_FILE=$(echo "$PATH_KEY_FILE"| rev |cut -f1 -d '/' |rev)    
            NEW_PATH_KEY_FILE=/etc/apache2/"$_date"/"$_KEY_FILE"

Step5: Replace the SSL File Paths in Apache Configuration files.
            #Seetting New SSL Paths in Apache Configuration
            sed -i "s@SSLCertificateFile.*@SSLCertificateFile  $NEW_PATH_CERT_FILE@g"  /etc/apache2/sites-available/zerooneprograms.conf
            sed -i "s@SSLCertificateKeyFile.*@SSLCertificateKeyFile  $NEW_PATH_KEY_FILE@g"  /etc/apache2/sites-available/zerooneprograms.conf
            sed -i "s@SSLCertificateChainFile.*@SSLCertificateChainFile  $NEW_PATH_INTERMEDIATE_CERT@g"  /etc/apache2/sites-available/zerooneprograms.conf

Step6: Check the Apache Syntax and restart the web server.