summaryrefslogtreecommitdiffstats
path: root/installer/pkg-generator/genpkg.sh
blob: 4dd626b5536809262ea449df47e3cbec6a6aa243 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
#####################################################################
####### This script downloads svn repo and generates a debian package
####### Autor: Fredy <aluque@soleta.eu>      2018 Q1
####### First attempt just launches the opengnsys_installer
#####################################################################

# Needs root priviledges
if [ "$(whoami)" != 'root' ]; then
        echo "ERROR: this program must run under root privileges!!"
        exit 1
fi

VERSION="1.1"
SVNURL=https://opengnsys.es/svn/branches/version$VERSION
PKG_GEN_PATH=/root/debian-pkg
#DESTDIR=$ROOTDIR/opt/opengnsys
TMPDIR=/tmp/opengnsys_installer

function help()
{
read -r -d '' HELP <<- EOM
########################################################################
#  This script creates debian ".deb" packages for the great            #
#           Opengnsys Deployment Software                              #
#  - Select which type of package you would like to generate           #
#  - You will find your ".deb" file inside /root/debian-pkg folder     #
#  - Send the ".deb" file to your destination machine and install it:  #
#  - apt install ./opengnsys-*.deb   (use apt instead apt-get or dpkg) #
#  The script has been tested on Ubuntu Xenial 16.04 LTS               #
########################################################################
EOM
echo "$HELP"
}

function createControlFile()
{
cat > $ROOTDIR/DEBIAN/control << EOF
Package: $PKG_NAME
Priority: optional
Section: misc
Maintainer: info@opengnsys.es
Architecture: all
Version: $VERSION
$DEPENDS
Description: Opengnsys Deploy Generator
Homepage: https://opengnsys.es
EOF
}

function createFullPackage()
{
PKG_NAME="opengnsys-full"
ROOTDIR=$PKG_GEN_PATH/$PKG_NAME
mkdir -p $DESTDIR $TMPDIR $ROOTDIR
svn export --force $SVNURL $TMPDIR
mkdir -p $ROOTDIR/DEBIAN $ROOTDIR/tmp
ln -s $TMPDIR/ $TMPDIR/opengnsys
DEPENDS="Depends: subversion, apache2, php, php-ldap, libapache2-mod-php, isc-dhcp-server, bittorrent, tftp-hpa, tftpd-hpa, xinetd, build-essential, g++-multilib, libmysqlclient-dev, wget, curl, doxygen, graphviz, bittornado, ctorrent, samba, rsync, unzip, netpipes, debootstrap, schroot, squashfs-tools, btrfs-tools, procps, arp-scan, realpath, php-curl, gettext ,moreutils, jq, wakeonlan, mysql-server, php-mysql, udpcast"
createControlFile
# Copy installer to postinst
cp $TMPDIR/installer/opengnsys_installer.sh $ROOTDIR/DEBIAN/postinst

# Ejemplo de modificacion del postinst al vuelo
# sed -i 's/wget --spider -q/wget --spider -q --no-check-certificate/g' $ROOTDIR/DEBIAN/postinst

# deactivate svn function
sed -i '/function svnExportCode/{N;s/$/\nreturn 0/}' $ROOTDIR/DEBIAN/postinst

# copy svn repo structure inside .deb package
cp -a $TMPDIR $ROOTDIR/tmp

# Finally Generate package
cd $PKG_GEN_PATH
dpkg --build $PKG_NAME .
}

function createClientPackage()
{
PKG_NAME="opengnsys-client"
ROOTDIR=$PKG_GEN_PATH/$PKG_NAME
mkdir -p $TMPDIR/opengnsys/client/
mkdir -p $ROOTDIR/tmp/client
svn checkout $SVNURL/client $TMPDIR/opengnsys/client/
mkdir -p $ROOTDIR/DEBIAN
DEPENDS="Depends: debootstrap, subversion, schroot, squashfs-tools, syslinux, genisoimage, ipxe, qemu, lsof"
createControlFile
# Copy installer to postinst
cp $TMPDIR/opengnsys/client/boot-tools/boottoolsgenerator.sh $ROOTDIR/DEBIAN/postinst
# Modify installer
sed -i 's/apt-get -y --force-yes install/#apt-get -y --force-yes install/g' $ROOTDIR/DEBIAN/postinst
# Copy repo to package
cp -a $TMPDIR $ROOTDIR/tmp
# Generate package
cd $PKG_GEN_PATH
dpkg --build $PKG_NAME .
}

# Start the Menu
echo "Main Menu"

# Define the choices to present to the user.
choices=( 'help' "Create full package" "Client package (testing)" 'exit')

while [ "$menu" != 1 ]; do
# Present the choices.
# The user chooses by entering the *number* before the desired choice.
	select choice in "${choices[@]}"; do

		# Examine the choice.
		case $choice in
		help)
		  echo "Generate Package Help"
		  help

		  ;;
		"Create full package")
			echo "Creating new full package..."
			createFullPackage
			exit 0
		  ;;
		"Client package (testing)")
			echo "Creating Client package..."
			createClientPackage
			exit 0
		  ;;		  
		exit)
		  echo "Exiting. "
		  exit 0
		  ;;
		*)
		  echo "Wrong choice!"
		  exit 1
		esac
		break

	done
done

echo "End of the script"
exit