Snort scripts and config update.
[ipfire-2.x.git] / config / rootfiles / core / 38 / update.sh
CommitLineData
4335a594
AF
1#!/bin/bash
2############################################################################
3# #
4# This file is part of the IPFire Firewall. #
5# #
6# IPFire is free software; you can redistribute it and/or modify #
7# it under the terms of the GNU General Public License as published by #
8# the Free Software Foundation; either version 3 of the License, or #
9# (at your option) any later version. #
10# #
11# IPFire is distributed in the hope that it will be useful, #
12# but WITHOUT ANY WARRANTY; without even the implied warranty of #
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14# GNU General Public License for more details. #
15# #
16# You should have received a copy of the GNU General Public License #
17# along with IPFire; if not, write to the Free Software #
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
19# #
20# Copyright (C) 2010 IPFire-Team <info@ipfire.org>. #
21# #
22############################################################################
23#
24. /opt/pakfire/lib/functions.sh
25/usr/local/bin/backupctrl exclude >/dev/null 2>&1
26#
c8783a6a
AF
27OLDVERSION=`grep "version = " /opt/pakfire/etc/pakfire.conf | cut -d'"' -f2`
28#
29# Test if we running on xen
30#
31uname -r | grep "ipfire-xen";
32if [ ${?} = 0 ]; then
33 #Xen Kernel is active
34 NEWVERSION="2.7-xen"
35else
36 #Normal Kernel
37 NEWVERSION="2.7"
38fi
39#
de167abd 40KVER="2.6.32.15"
4335a594
AF
41ROOT=`grep "root=" /boot/grub/grub.conf | cut -d"=" -f2 | cut -d" " -f1 | tail -n 1`
42MOUNT=`grep "kernel" /boot/grub/grub.conf | tail -n 1`
43# Nur den letzten Parameter verwenden
44echo $MOUNT > /dev/null
45MOUNT=$_
46if [ ! $MOUNT == "rw" ]; then
47 MOUNT="ro"
48fi
49#
50# check if we the backup file already exist
51if [ -e /var/ipfire/backup/core-upgrade_$KVER.tar.bz2 ]; then
52 echo Moving backup to backup-old ...
53 mv -f /var/ipfire/backup/core-upgrade_$KVER.tar.bz2 \
54 /var/ipfire/backup/core-upgrade_$KVER-old.tar.bz2
55fi
56echo First we made a backup of all files that was inside of the
57echo update archive. This may take a while ...
58# Add some files that are not in the package to backup
59echo lib/modules >> /opt/pakfire/tmp/ROOTFILES
60echo boot >> /opt/pakfire/tmp/ROOTFILES
61echo etc/sysconfig/lm_sensors >> /opt/pakfire/tmp/ROOTFILES
618097cb
AF
62echo usr/lib/ipsec >> /opt/pakfire/tmp/ROOTFILES
63echo usr/libexec/ipsec >> /opt/pakfire/tmp/ROOTFILES
4335a594
AF
64tar cjvf /var/ipfire/backup/core-upgrade_$KVER.tar.bz2 \
65 -C / -T /opt/pakfire/tmp/ROOTFILES --exclude='#*' > /dev/null 2>&1
c131aeaf
AF
66
67#
68# Stop Sevices
69#
70/etc/init.d/collectd stop
71/etc/init.d/squid stop
72/etc/init.d/ipsec stop
8dc25f04 73/etc/init.d/snort stop
c131aeaf 74
4335a594
AF
75echo
76echo Update Kernel to $KVER ...
77# Remove old kernel, configs, initrd, modules ...
78#
79rm -rf /boot/System.map-*
80rm -rf /boot/config-*
81rm -rf /boot/ipfirerd-*
82rm -rf /boot/vmlinuz-*
4335a594 83rm -rf /lib/modules/*-ipfire
de167abd
AF
84# Don't remove all old xen modules. Kernel may stored outside.
85# only from 2.6.27.25 and 31
86rm -rf /lib/modules/2.6.27.25-ipfire-xen
87rm -rf /lib/modules/2.6.27.31-ipfire-xen
4335a594 88#
b151637d 89# remove openswan libs ...
4335a594 90#
b151637d
AF
91rm -rf /usr/lib/ipsec
92rm -rf /usr/libexec/ipsec
b86d9c0a 93#
8dc25f04 94# old snort libs and rules ...
b86d9c0a
AF
95#
96rm -rf /usr/lib/snort_*
8dc25f04 97rm -rf /etc/snort
4335a594
AF
98
99#
100# Backup grub.conf
101#
102cp -vf /boot/grub/grub.conf /boot/grub/grub.conf.org
103#
d2d2da10
AF
104# Stop sysklogd
105/etc/init.d/sysklogd stop
106#
4335a594
AF
107# Unpack the updated files
108#
109echo
110echo Unpack the updated files ...
111#
112tar xvf /opt/pakfire/tmp/files --preserve --numeric-owner -C / \
113 --no-overwrite-dir
114#
d2d2da10
AF
115# Start Sevices
116/etc/init.d/sysklogd start
117/etc/init.d/squid start
118#
4335a594
AF
119# Modify grub.conf
120#
121echo
122echo Update grub configuration ...
123sed -i "s|ROOT|$ROOT|g" /boot/grub/grub.conf
124sed -i "s|KVER|$KVER|g" /boot/grub/grub.conf
125sed -i "s|MOUNT|$MOUNT|g" /boot/grub/grub.conf
126
127if [ "$(grep "^serial" /boot/grub/grub.conf.org)" == "" ]; then
128 echo "grub use default console ..."
129else
130 echo "grub use serial console ..."
131 sed -i -e "s|splashimage|#splashimage|g" /boot/grub/grub.conf
132 sed -i -e "s|#serial|serial|g" /boot/grub/grub.conf
133 sed -i -e "s|#terminal|terminal|g" /boot/grub/grub.conf
134 sed -i -e "s| panic=10 | console=ttyS0,38400n8 panic=10 |g" /boot/grub/grub.conf
135fi
136#
137# Made emergency - initramdisk
138#
139echo
140echo Create new Initramdisks ...
141cp -f /etc/mkinitcpio.conf /etc/mkinitcpio.conf.org
142sed -i "s| autodetect | |g" /etc/mkinitcpio.conf
143mkinitcpio -k $KVER-ipfire -g /boot/ipfirerd-$KVER-emergency.img
144cp -f /etc/mkinitcpio.conf.org /etc/mkinitcpio.conf
145#
146# Made initramdisk
147#
148if [ "${ROOT:0:7}" == "/dev/sd" ]; then
149 # Remove ide hook if root is on sda
150 sed -i "s| ide | |g" /etc/mkinitcpio.conf
151else
152if [ "${ROOT:0:7}" == "/dev/hd" ]; then
153 # Remove pata & sata hook if root is on hda
154 sed -i "s| pata | |g" /etc/mkinitcpio.conf
155 sed -i "s| sata | |g" /etc/mkinitcpio.conf
156fi
157fi
158mkinitcpio -k $KVER-ipfire -g /boot/ipfirerd-$KVER.img
159#
160# ReInstall grub
161#
162grub-install --no-floppy ${ROOT::`expr length $ROOT`-1} --recheck
163#
164# Rebuild Language
165#
166perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
167#
d7cd8ad9
CS
168# Cleanup Collectd statistics...
169#
170PRECLEAN=`du -sh /var/log/rrd/collectd`
171#
172rm -rf /var/log/rrd*/collectd/localhost/processes-*/ps_count*
173rm -rf /var/log/rrd*/collectd/localhost/processes-*/ps_pagefaults*
174rm -rf /var/log/rrd*/collectd/localhost/processes-*/ps_stacksize*
175rm -rf /var/log/rrd*/collectd/localhost/processes-*/ps_state*
176rm -rf /var/log/rrd*/collectd/localhost/processes-*/ps_vm*
177#
178rm -rf /var/log/rrd*/collectd/localhost/interface/if_errors*
179rm -rf /var/log/rrd*/collectd/localhost/interface/if_packets*
180#
181rm -rf /var/log/rrd*/collectd/localhost/disk-*/disk_merged*
182rm -rf /var/log/rrd*/collectd/localhost/disk-*/disk_ops*
183rm -rf /var/log/rrd*/collectd/localhost/disk-*/disk_time*
48cad624
AF
184#
185rm -rf /var/log/rrd*/collectd/localhost/iptables-filter-INPUT/*-DROP_Wirelessinput*
186rm -rf /var/log/rrd*/collectd/localhost/iptables-filter-FORWARD/*-DROP_Wirelessforward*
187rm -rf /var/log/rrd*/collectd/localhost/iptables-filter-OUTGOINGFW
d7cd8ad9
CS
188POSTCLEAN=`du -sh /var/log/rrd/collectd`
189#
190echo Cleaned up collectd directory from $PRECLEAN to $POSTCLEAN size.
191#
d2d2da10
AF
192# Start collectd
193/etc/init.d/collectd start
194#
195# Delete old lm-sensor modullist to force search at next boot
196#
197rm -rf /etc/sysconfig/lm_sensors
198#
58fcc270
AF
199# USB Modeswitch conf now called setup, rename ...
200#
618097cb 201if [ -e /etc/usb_modeswitch.conf ]; then
58fcc270 202mv -f /etc/usb_modeswitch.conf /etc/usb_modeswitch.setup
618097cb 203fi
58fcc270 204#
618097cb
AF
205# rebuild qosscript if enabled...
206if [ -e /var/ipfire/qos/enable ]; then
207 /usr/local/bin/qosctrl stop
7d3d5dbd 208 /usr/local/bin/qosctrl generate
618097cb
AF
209 /usr/local/bin/qosctrl start
210fi
4335a594
AF
211#
212#
e3c5d22a
AF
213# convert ipsec.conf from openswan to strongswan...
214mv /var/ipfire/vpn/ipsec.conf /var/ipfire/vpn/ipsec.conf.org
215cat /var/ipfire/vpn/ipsec.conf.org | \
216grep -v "disablearrivalcheck=" | \
63249c67 217grep -v "klipsdebug=" | \
e3c5d22a 218grep -v "leftfirewall=" | \
b2d5dd6d 219grep -v "lefthostaccess=" | \
e3c5d22a
AF
220grep -v "charonstart=" | \
221grep -v "aggrmode=" > /var/ipfire/vpn/ipsec.conf
222sed -i "s|ipsec[0-9]=||g" /var/ipfire/vpn/ipsec.conf
63249c67
AF
223sed -i "s|nat_t ||g" /var/ipfire/vpn/ipsec.conf
224sed -i "s|klips ||g" /var/ipfire/vpn/ipsec.conf
b2d5dd6d 225sed -i "s|^conn [A-Za-z].*$|&\n\tleftfirewall=yes\n\tlefthostaccess=yes|g" /var/ipfire/vpn/ipsec.conf
e3c5d22a
AF
226sed -i "s|^config setup$|&\n\tcharonstart=no|g" /var/ipfire/vpn/ipsec.conf
227chown nobody:nobody /var/ipfire/vpn/ipsec.conf
228chmod 644 /var/ipfire/vpn/ipsec.conf
4335a594 229#
d2d2da10
AF
230# Add cryptodev to /etc/sysconfig/modules
231mv /etc/sysconfig/modules /etc/sysconfig/modules.org
232cat /etc/sysconfig/modules.org | \
233grep -v "cryptodev" | \
234grep -v "# End /etc/sysconfig/modules" > /etc/sysconfig/modules
235echo "" >> /etc/sysconfig/modules
236echo "### cryptodev" >> /etc/sysconfig/modules
237echo "#" >> /etc/sysconfig/modules
238echo "cryptodev" >> /etc/sysconfig/modules
239echo "" >> /etc/sysconfig/modules
240echo "# End /etc/sysconfig/modules" >> /etc/sysconfig/modules
241chmod 644 /etc/sysconfig/modules
c8783a6a
AF
242# Change version of Pakfire.conf
243#
244sed -i "s|$OLDVERSION|$NEWVERSION|g" /opt/pakfire/etc/pakfire.conf
4335a594 245#
f9677eea
AF
246# After pakfire has ended run it again and update the lists and do upgrade
247#
00d59063
AF
248echo '#!/bin/bash' > /tmp/pak_update
249echo 'while [ "$(ps -A | grep " update.sh")" != "" ]; do' >> /tmp/pak_update
250echo ' sleep 1' >> /tmp/pak_update
251echo 'done' >> /tmp/pak_update
252echo 'while [ "$(ps -A | grep " pakfire")" != "" ]; do' >> /tmp/pak_update
253echo ' sleep 1' >> /tmp/pak_update
254echo 'done' >> /tmp/pak_update
255echo '/opt/pakfire/pakfire update -y --force' >> /tmp/pak_update
256echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
257echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
258echo '/opt/pakfire/pakfire upgrade -y' >> /tmp/pak_update
259echo '/usr/bin/logger -p syslog.emerg -t core-upgrade-38 "Upgrade finished. If you use a customized grub.cfg"' >> /tmp/pak_update
260echo '/usr/bin/logger -p syslog.emerg -t core-upgrade-38 "Check it before reboot !!!"' >> /tmp/pak_update
261echo '/usr/bin/logger -p syslog.emerg -t core-upgrade-38 " *** Please reboot... *** "' >> /tmp/pak_update
262#
263chmod +x /tmp/pak_update
264/tmp/pak_update &
f9677eea
AF
265#
266echo
267echo Please wait until pakfire has ended...
268echo