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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
#!/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
# Registro de incidencias.
OGLOGFILE=$TMPDIR/log/${PROGRAMNAME%.sh}.log
LOG_FILE=/tmp/$(basename $OGLOGFILE)
BRANCH="master"
CODE_URL="https://codeload.github.com/opengnsys/OpenGnsys/zip/$BRANCH"
API_URL="https://api.github.com/repos/opengnsys/OpenGnsys/branches/$BRANCH"
RAW_URL="https://raw.githubusercontent.com/opengnsys/OpenGnsys/$BRANCH"
DEV_BRANCH="debian-pkg"
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 getDateTime()
{
date "+%Y%m%d-%H%M%S"
}
# Escribe a fichero y muestra por pantalla
function echoAndLog()
{
echo $1
DATETIME=`getDateTime`
echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE
}
function errorAndLog()
{
echo "ERROR: $1"
DATETIME=`getDateTime`
echo "$DATETIME;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE
}
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 downloadCode()
{
if [ $# -ne 1 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local url="$1"
echoAndLog "${FUNCNAME}(): downloading code..."
curl "${url}" -o opengnsys.zip && unzip opengnsys.zip && mv "OpenGnsys-$BRANCH" opengnsys
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error getting code from ${url}, verify your user and password"
return 1
fi
rm -f opengnsys.zip
echoAndLog "${FUNCNAME}(): code was downloaded"
return 0
}
function createFullPackage()
{
PKG_NAME="opengnsys-full"
ROOTDIR=$PKG_GEN_PATH/$PKG_NAME
mkdir -p $DESTDIR $TMPDIR $ROOTDIR
#downloadCode $CODE_URL
# for testing and development:
git clone gituser@opengnsys.es:/git/opengnsys -b $DEV_BRANCH $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"
# Copy installer to postinst
#cp $TMPDIR/installer/opengnsys_git_installer.sh $ROOTDIR/DEBIAN/postinst
cp -a $TMPDIR/installer/pkg-generator/DEBIAN $ROOTDIR/
createControlFile
# 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 repo structure inside .deb package and delete .git dir
cp -r $TMPDIR $ROOTDIR/tmp
rm -Rf $ROOTDIR/tmp/opengnsys_installer/.git
# 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
|