1 | #!/bin/bash |
---|
2 | ##################################################################### |
---|
3 | ####### This script downloads svn repo and generates a debian package |
---|
4 | ####### Autor: Fredy <aluque@soleta.eu> 2018 Q1 |
---|
5 | ####### First attempt just launches the opengnsys_installer |
---|
6 | ##################################################################### |
---|
7 | |
---|
8 | # Needs root priviledges |
---|
9 | if [ "$(whoami)" != 'root' ]; then |
---|
10 | echo "ERROR: this program must run under root privileges!!" |
---|
11 | exit 1 |
---|
12 | fi |
---|
13 | |
---|
14 | VERSION="1.1" |
---|
15 | SVNURL=https://opengnsys.es/svn/branches/version$VERSION |
---|
16 | PKG_GEN_PATH=/root/debian-pkg |
---|
17 | #DESTDIR=$ROOTDIR/opt/opengnsys |
---|
18 | TMPDIR=/tmp/opengnsys_installer |
---|
19 | |
---|
20 | function help() |
---|
21 | { |
---|
22 | read -r -d '' HELP <<- EOM |
---|
23 | ######################################################################## |
---|
24 | # This script creates debian ".deb" packages for the great # |
---|
25 | # Opengnsys Deployment Software # |
---|
26 | # - Select which type of package you would like to generate # |
---|
27 | # - You will find your ".deb" file inside /root/debian-pkg folder # |
---|
28 | # - Send the ".deb" file to your destination machine and install it: # |
---|
29 | # - apt install ./opengnsys-*.deb (use apt instead apt-get or dpkg) # |
---|
30 | # The script has been tested on Ubuntu Xenial 16.04 LTS # |
---|
31 | ######################################################################## |
---|
32 | EOM |
---|
33 | echo "$HELP" |
---|
34 | } |
---|
35 | |
---|
36 | function createControlFile() |
---|
37 | { |
---|
38 | cat > $ROOTDIR/DEBIAN/control << EOF |
---|
39 | Package: $PKG_NAME |
---|
40 | Priority: optional |
---|
41 | Section: misc |
---|
42 | Maintainer: info@opengnsys.es |
---|
43 | Architecture: all |
---|
44 | Version: $VERSION |
---|
45 | $DEPENDS |
---|
46 | Description: Opengnsys Deploy Generator |
---|
47 | Homepage: https://opengnsys.es |
---|
48 | EOF |
---|
49 | } |
---|
50 | |
---|
51 | function createFullPackage() |
---|
52 | { |
---|
53 | PKG_NAME="opengnsys-full" |
---|
54 | ROOTDIR=$PKG_GEN_PATH/$PKG_NAME |
---|
55 | mkdir -p $DESTDIR $TMPDIR $ROOTDIR |
---|
56 | svn export --force $SVNURL $TMPDIR |
---|
57 | mkdir -p $ROOTDIR/DEBIAN $ROOTDIR/tmp |
---|
58 | ln -s $TMPDIR/ $TMPDIR/opengnsys |
---|
59 | 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" |
---|
60 | createControlFile |
---|
61 | # Copy installer to postinst |
---|
62 | cp $TMPDIR/installer/opengnsys_installer.sh $ROOTDIR/DEBIAN/postinst |
---|
63 | |
---|
64 | # Ejemplo de modificacion del postinst al vuelo |
---|
65 | # sed -i 's/wget --spider -q/wget --spider -q --no-check-certificate/g' $ROOTDIR/DEBIAN/postinst |
---|
66 | |
---|
67 | # deactivate svn function |
---|
68 | sed -i '/function svnExportCode/{N;s/$/\nreturn 0/}' $ROOTDIR/DEBIAN/postinst |
---|
69 | |
---|
70 | # copy svn repo structure inside .deb package |
---|
71 | cp -a $TMPDIR $ROOTDIR/tmp |
---|
72 | |
---|
73 | # Finally Generate package |
---|
74 | cd $PKG_GEN_PATH |
---|
75 | dpkg --build $PKG_NAME . |
---|
76 | } |
---|
77 | |
---|
78 | function createClientPackage() |
---|
79 | { |
---|
80 | PKG_NAME="opengnsys-client" |
---|
81 | ROOTDIR=$PKG_GEN_PATH/$PKG_NAME |
---|
82 | mkdir -p $TMPDIR/opengnsys/client/ |
---|
83 | mkdir -p $ROOTDIR/tmp/client |
---|
84 | svn checkout $SVNURL/client $TMPDIR/opengnsys/client/ |
---|
85 | mkdir -p $ROOTDIR/DEBIAN |
---|
86 | DEPENDS="Depends: debootstrap, subversion, schroot, squashfs-tools, syslinux, genisoimage, ipxe, qemu, lsof" |
---|
87 | createControlFile |
---|
88 | # Copy installer to postinst |
---|
89 | cp $TMPDIR/opengnsys/client/boot-tools/boottoolsgenerator.sh $ROOTDIR/DEBIAN/postinst |
---|
90 | # Modify installer |
---|
91 | sed -i 's/apt-get -y --force-yes install/#apt-get -y --force-yes install/g' $ROOTDIR/DEBIAN/postinst |
---|
92 | # Copy repo to package |
---|
93 | cp -a $TMPDIR $ROOTDIR/tmp |
---|
94 | # Generate package |
---|
95 | cd $PKG_GEN_PATH |
---|
96 | dpkg --build $PKG_NAME . |
---|
97 | } |
---|
98 | |
---|
99 | # Start the Menu |
---|
100 | echo "Main Menu" |
---|
101 | |
---|
102 | # Define the choices to present to the user. |
---|
103 | choices=( 'help' "Create full package" "Client package (testing)" 'exit') |
---|
104 | |
---|
105 | while [ "$menu" != 1 ]; do |
---|
106 | # Present the choices. |
---|
107 | # The user chooses by entering the *number* before the desired choice. |
---|
108 | select choice in "${choices[@]}"; do |
---|
109 | |
---|
110 | # Examine the choice. |
---|
111 | case $choice in |
---|
112 | help) |
---|
113 | echo "Generate Package Help" |
---|
114 | help |
---|
115 | |
---|
116 | ;; |
---|
117 | "Create full package") |
---|
118 | echo "Creating new full package..." |
---|
119 | createFullPackage |
---|
120 | exit 0 |
---|
121 | ;; |
---|
122 | "Client package (testing)") |
---|
123 | echo "Creating Client package..." |
---|
124 | createClientPackage |
---|
125 | exit 0 |
---|
126 | ;; |
---|
127 | exit) |
---|
128 | echo "Exiting. " |
---|
129 | exit 0 |
---|
130 | ;; |
---|
131 | *) |
---|
132 | echo "Wrong choice!" |
---|
133 | exit 1 |
---|
134 | esac |
---|
135 | break |
---|
136 | |
---|
137 | done |
---|
138 | done |
---|
139 | |
---|
140 | echo "End of the script" |
---|
141 | exit |
---|
142 | |
---|
143 | |
---|
144 | |
---|