home *** CD-ROM | disk | FTP | other *** search
/ ftp.ac-grenoble.fr / 2015.02.ftp.ac-grenoble.fr.tar / ftp.ac-grenoble.fr / pub / slis / upgrade-32.sh < prev   
Linux/UNIX/POSIX Shell Script  |  2006-06-13  |  10KB  |  312 lines

  1. #!/bin/bash
  2. #$Id: upgrade-32.sh,v 1.26 2006/06/06 15:14:04 bzizou Exp $
  3. # SLIS 3.1 to SLIS 3.2 upgrade script
  4. ######################################
  5.  
  6. . /etc/slis/slis.conf
  7.  
  8. # Update level check
  9. echo "Update level check..."
  10. logger -t "update-3.2" "Update level check..."
  11. declare -i REL
  12. REL=`rpm -q --qf "%{RELEASE}" slis-up2date`
  13. if [ "$REL" -lt "31" ]
  14. then
  15.   echo "ERROR: This slis 3.1 is not up-to-date. I can't upgrade. Aborting."
  16.   logger -t "update-3.2" "ERROR: This slis 3.1 is not up-to-date. I can't upgrade. Aborting."
  17.   exit 3
  18. fi
  19.  
  20.  
  21. # Clean temporary directories
  22. echo "Cleaning..."
  23. logger -t "update-3.2" "Cleaning..."
  24. /usr/sbin/tmpwatch 24 /tmp /var/tmp
  25. /sbin/service runcache stop
  26. killall RunCache 2>/dev/null
  27. killall squid 2>/dev/null
  28. sleep 5
  29. /bin/rm -rf /www-cache/*
  30.  
  31. # Removing docs
  32. echo "Removing docs to make some space..."
  33. logger -t "update-3.2" "Removing docs..."
  34. rm -rf /usr/share/docs/*
  35.  
  36. # Space disk checks
  37. echo "Disk space check..."
  38. logger -t "update-3.2" "Disk space check..."
  39. declare -i SPACE
  40. SPACE=`df -P | grep /tmp$ | awk '{print $4}'`
  41. if [ "$SPACE" -lt "10000" ]
  42. then
  43.   logger -t "update-3.2" "ERR: not enough free space into /tmp. ABORTING."
  44.   echo "ERR: not enough free space into /tmp. ABORTING."
  45.   /sbin/service squid start
  46.   exit 1
  47. fi
  48. SPACE=`df -P | grep /var$ | awk '{print $4}'`
  49. if [ "$SPACE" -lt "100000" ]
  50. then
  51.   logger -t "update-3.2" "ERR: not enough free space into /var. ABORTING."
  52.   echo "ERR: not enough free space into /var. ABORTING."
  53.   /sbin/service squid start
  54.   exit 1
  55. fi
  56. SPACE=`df -P | grep /$ | awk '{print $4}'`
  57. if [ "$SPACE" -lt "100000" ]
  58. then
  59.   logger -t "update-3.2" "ERR: not enough free space into /. ABORTING."
  60.   echo "ERR: not enough free space into /. ABORTING."
  61.   /sbin/service squid start
  62.   exit 1
  63. fi
  64. SPACE=`df -P | grep /home$ | awk '{print $4}'`
  65. if [ "$SPACE" -lt "10000" ]
  66. then
  67.   logger -t "update-3.2" "ERR: not enough free space into /home. ABORTING."
  68.   echo "ERR: not enough free space into /home. ABORTING."
  69.   /sbin/service squid start
  70.   exit 1
  71. fi
  72. SPACE=`df -P | grep /www-cache$ | awk '{print $4}'`
  73. if [ "$SPACE" -lt "400000" ]
  74. then
  75.   logger -t "update-3.2" "ERR: not enough free space into /www-cache. ABORTING."
  76.   echo "ERR: not enough free space into /www-cache. ABORTING."
  77.   /sbin/service squid start
  78.   exit 1
  79. fi
  80.  
  81. # We will use the squid-cache partiton as a temporary space
  82. echo "Moving the cache dir..."
  83. logger -t "update-3.2" "Moving the cache dir..."
  84. /bin/rm -rf /www-cache/*
  85. /bin/mv /var/cache /www-cache/
  86. /bin/ln -s /www-cache/cache /var/cache
  87.  
  88. # Dumping postgres
  89. echo "PG dump..."
  90. logger -t "update-3.2" "PG dump..."
  91. export PGUSER=`grep "POSTGRESUSER" /home/hadmin/html/config_pgsql.inc.php | cut -d\" -f2`
  92. export PGPASSWORD=`grep "POSTGRESPASS" /home/hadmin/html/config_pgsql.inc.php | cut -d\" -f2`
  93. psql -tqc "delete from access_squid" hadmin
  94. psql -tqc "delete from access_apache" hadmin
  95. pg_dumpall -D > /var/cache/dump.sql
  96. if [ $? != 0 ]
  97. then
  98.   logger -t "update-3.2" "ERROR: PG dump failed! Reverting to the initial state."
  99.   echo "ERROR: PG dump failed! Reverting to the initial state."
  100.   /bin/rm -f /var/cache/dump.sql
  101.   /bin/rm -f /var/cache
  102.   /bin/mv -f /www-cache/cache /var/
  103.   /sbin/service squid start
  104.   exit 2
  105. fi
  106.  
  107. # Removing slis-up2date
  108. echo "Removing slis-up2date..."
  109. apt-get remove -q2 slis-up2date
  110.  
  111. # Changing the APT repository
  112. echo "APT update..."
  113. logger -t "update-3.2" "APT update..."
  114. > /etc/apt/sources.list
  115. #NE PAS UTILISER LE CDROM : le kernel n'est pas le bon !
  116.  
  117. #mount /mnt/cdrom
  118. #if [ "`grep "Fedora Core 3" /mnt/cdrom/.discinfo`" != "" ]
  119. #then
  120. #  echo "  Cool, I found a Fedora Core 3 CDROM into the drive. I'll use it."
  121. #  logger -t "update-3.2" "Cool, I found a Fedora Core 3 CDROM into the drive! I'll use it."
  122.  # mkdir /var/tmp/apt
  123.  # cd /var/tmp/apt
  124.   #ln -s /mnt/cdrom/Fedora/RPMS RPMS.slis32
  125.   #mkdir SRPMS.slis32
  126.   #genbasedir --flat --bloat --progress /var/tmp/apt  slis32
  127.   #echo "rpm file:/var/tmp/ apt slis32" > /etc/apt/sources.list
  128. #fi
  129. # rpm ftp://ftp.ac-creteil.fr/SLIS slis/3.2/i386 updates fedora-updates os slis fedora.us 
  130. echo "rpm ftp://ftp.ac-grenoble.fr/pub/slis slis/3.2/i386 updates fedora-updates os slis" >> /etc/apt/sources.list
  131. apt-get -q2 update
  132.  
  133. # Kernel update
  134.  
  135. echo "Kernel-update..."
  136. logger -t "update-3.2" "Kernel-update..."
  137. apt-get -q2 install kernel#2.6.12-2.3.legacy_FC3 2>/dev/null
  138.  
  139. echo "kernel-update ok!"
  140.  
  141. /sbin/new-kernel-pkg --mkinitrd --depmod --install 2.6.12-2.3.legacy_FC3
  142.  
  143. apt-get -q2 remove kernel#2.4.22-1.2149.nptl 2>/dev/null
  144. apt-get -q2 remove kernel-smp#2.4.22-1.2149.nptl 2>/dev/null
  145. apt-get -q2 remove kernel#2.4.22-1.2166.nptl 2>/dev/null
  146. apt-get -q2 remove kernel-smp#2.4.22-1.2166.nptl 2>/dev/null
  147. apt-get -q2 remove kernel#2.4.22-1.2199.8.legacy.nptl 2>/dev/null
  148. apt-get -q2 remove kernel-smp#2.4.22-1.2199.8.legacy.nptl 2>/dev/null
  149.  
  150. rm -f /boot/System.map
  151. rm -f /boot/vmlinuz
  152.  
  153.  
  154. # Pre-download
  155. echo "Getting files..."
  156. logger -t "update-3.2" "Getting files..."
  157. apt-get -q2 --download-only dist-upgrade
  158. if [ $? != 0 ]
  159. then
  160.   logger -t "update-3.2" "ERROR: apt-get --download-only failed! Reverting to the initial state."
  161.   echo "ERROR: apt-get --download-only failed! Reverting to the initial state."
  162.   echo "rpm ftp://ftp.ac-grenoble.fr/pub/slis slis/3.1/i386 updates fedora-updates" > /etc/apt/sources.list
  163.   /bin/rm -f /var/cache/dump.sql
  164.   /bin/rm -f /var/cache
  165.   /bin/mv -f /www-cache/cache /var/
  166.   /sbin/service squid start
  167.   exit 2
  168. fi
  169.  
  170. # Now, no more tests... it goes or it brakes!
  171. # Upgrade
  172. echo "The big upgrade (may be long)..."
  173. logger -t "update-3.2" "The big upgrade (may be long)..."
  174. apt-get -q2 dist-upgrade
  175.  
  176. # Fixes a missing link to sendmail
  177. echo "Fixing missing sendmail link..."
  178. logger -t "update-3.2" "Fixing missing sendmail link..."
  179. /bin/ln -s /etc/alternatives/mta-sendmail /usr/lib/sendmail
  180.  
  181. # Kernel config
  182. echo "Kernel-config..."
  183. logger -t "update-3.2" "Kernel-config..."
  184. echo "udev_initrd=\"yes\"" >> /etc/udev/udev.conf
  185. /sbin/mkinitrd -f /boot/initrd-2.6.12-2.3.legacy_FC3.img 2.6.12-2.3.legacy_FC3
  186.  
  187. # Permissions
  188. echo "Setting permissions..."
  189. logger -t "update-3.2" "Setting permissions..."
  190. /usr/local/sbin/permslis
  191.  
  192.  
  193. # APT config
  194. echo "APT configuration..."
  195. logger -t "update-3.2" "APT configuration..."
  196. /bin/rm -rf /etc/apt/pgp/*
  197. /bin/rm -rf /etc/apt/apt.conf.d/*
  198. /bin/rm -rf /etc/apt/sources.list.d/*
  199. echo "Apt::State::FirstRun \"false\";" >> /etc/apt/apt.conf
  200. echo "RPM::Upgrade-Virtual \"false\";" > /etc/apt/apt.conf.d/kernel.conf
  201. echo "RPM::Allow-Duplicated { \"^gpg-pubkey\$\"; };" > /etc/apt/apt.conf.d/gpg-pubkeys.conf
  202.  
  203. # Don't know why, but bind seems to need a restart
  204. /sbin/service named restart
  205. sleep 10
  206.  
  207. # Don't know why, but I need to do another upgrade
  208. apt-get -q2 update
  209. apt-get -q2 dist-upgrade
  210.  
  211. # PG restore
  212. echo "PG restore..."
  213. logger -t "update-3.2" "PG restore..."
  214. /sbin/service postgresql stop
  215. cd /var/lib
  216. /bin/mv pgsql/ pgsql.32upd-backup
  217. mkdir pgsql
  218. chmod 700 pgsql
  219. chown postgres.postgres pgsql
  220. /sbin/service postgresql start
  221. sleep 10
  222. echo "alter user postgres with password '$PGPASSWORD'" > /tmp/pg.$$.sql
  223. su - postgres -c "psql -qf /tmp/pg.$$.sql template1 >/dev/null"
  224. /bin/rm -f /tmp/pg.$$.sql
  225. sleep 5
  226. su - postgres -c "psql -qf /var/cache/dump.sql template1 > /dev/null"
  227. /bin/cp -f /var/lib/pgsql.32upd-backup/data/pg_hba.conf /var/lib/pgsql/data/pg_hba.conf
  228. perl -pi -e "s/.*tcpip_socket.*=.*/tcpip_socket = true/" /var/lib/pgsql/data/postgresql.conf
  229. /sbin/service postgresql stop
  230. sleep 10
  231. /sbin/service postgresql start
  232.  
  233. # Don't know why TLS doesn't work anymore
  234. authconfig --kickstart --disableldaptls
  235. /sbin/service ldap restart
  236.  
  237. # Config de PAM (messages cron)
  238. echo "Pam session configuration for crond..."
  239. logger -t "update-3.2" "Pam session configuration for crond..."
  240. grep -v "^session" /etc/pam.d/crond > /tmp/crond
  241. echo "#
  242. # system-auth inclusion disabled for preventing floody-logging messages (pam_unix session module)
  243. #session    required  /lib/security/\$ISA/pam_stack.so service=system-auth
  244. session     required      /lib/security/\$ISA/pam_limits.so
  245. #session     required      /lib/security/\$ISA/pam_unix.so
  246. session     optional      /lib/security/\$ISA/pam_ldap.so
  247. #" >> /tmp/crond
  248. cp -f /tmp/crond /etc/pam.d/crond
  249.  
  250. # SLIS updates
  251. echo "Installing SLIS 3.2 updates..."
  252. #apt-get install -q2 slis-up2date
  253. apt-get -q2 --force-yes install slis-up2date openldap=2.2.13 openldap-clients=2.2.13 compat-openldap=2.1.30 openldap-servers=2.2.13
  254.  
  255. # Reconfiguration
  256. echo "SLIS reconfiguration..."
  257. logger -t "update-3.2" "SLIS reconfiguration..."
  258. /usr/local/sbin/mkhttpdconf -n -d -g -c -s -p /etc/php.ini.rpmnew
  259. /usr/local/sbin/mkslapdconf  > /etc/openldap/slapd.conf
  260. /usr/local/sbin/mksendmailcf -a
  261. /usr/local/sbin/mknamedconf > /etc/named.conf
  262. /usr/local/sbin/mknamedzones
  263. /usr/local/sbin/mknamedacls
  264. /usr/local/sbin/mksquidconf
  265. /usr/local/sbin/mksquidguardconf
  266. perl -pi -e "s/.*tls_checkpeer.*/tls_checkpeer no/" /etc/ldap.conf
  267. /usr/local/sbin/squid_rotate
  268.  
  269. # Don't know why TLS doesn't work anymore
  270. authconfig --kickstart --disableldaptls
  271. /sbin/service ldap restart
  272.  
  273. # Don't know why, but bind seems to need a restart
  274. /sbin/service named restart
  275. sleep 10
  276.  
  277. # Courier Imap
  278. echo "Courrier imap installation..."
  279. logger -t "update-3.2" "Courrier imap installation..."
  280. rpm -e imap-2002d-3* 2>/dev/null
  281. apt-get -q2 install courier-imap courier-authlib-ldap
  282.  
  283. /sbin/chkconfig courier-authlib on
  284. /sbin/chkconfig courier-imap on
  285.  
  286.  
  287. # Restore cache dir
  288. echo "Cache dir restore..."
  289. logger -t "update-3.2" "Cache dir restore..."
  290. apt-get -q2 clean
  291.  
  292. /bin/rm -f /var/cache
  293. /bin/mv -f /www-cache/cache /var
  294.  
  295. # Version number
  296. echo "Version number..."
  297. logger -t "update-3.2" "Version number..."
  298. echo "3.2 - Fedora Core 3 (upgraded from 3.1 - Fedora Core 1)" > /etc/version_slis
  299. echo "3.2" > /etc/version_slis_num
  300.  
  301. # Remove the local repos
  302. perl -pi -e "s/rpm file:.*//" /etc/apt/sources.list
  303. /bin/rm -rf /var/tmp/apt
  304.  
  305. # Option pci=nosort
  306. echo "Setting pci=nosort at boot to prevent from eth swap..."
  307. perl -pi -e "s/kernel(.*) ro /kernel\$1 ro pci=nosort /" /boot/grub/menu.lst
  308.  
  309. echo "Done. Please, reboot..."
  310. logger -t "update-3.2" "Done. Please, reboot..."
  311.  
  312.