Showing posts with label Debian. Show all posts
Showing posts with label Debian. Show all posts

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