#!/bin/bash
. /usr/share/jsjinstalltools/GetVersion
ZYPP_CONF=$(mktemp /tmp/zypp.conf.XXXXXXXXXX)
sed -e '/download.use_deltarpm =/ a download.use_deltarpm=false' < /etc/zypp/zypp.conf > $ZYPP_CONF
mv $ZYPP_CONF /etc/zypp/zypp.conf
chmod 644 /etc/zypp/zypp.conf
if [[ ${VERSION_ID/./} -ge 160 ]] ; then
  systemctl enable RunZypperUpdateCron.timer
  systemctl start RunZypperUpdateCron.timer
else
  zypper -n in -l yast2-online-update-configuration
  egrep /cron.hourly /etc/crontab
  if [ $? = 1 ]; then
    cat - >> /etc/crontab << EOF
59 *  * * *     root  rm -f /var/spool/cron/lastrun/cron.hourly
14 0  * * *     root  rm -f /var/spool/cron/lastrun/cron.daily
29 0  * * 6     root  rm -f /var/spool/cron/lastrun/cron.weekly
44 0  1 * *     root  rm -f /var/spool/cron/lastrun/cron.monthly
EOF
  fi
  ( crontab -l; echo "$((0x$(head -c2 /dev/urandom | hexdump | awk '$2 > 0 {print $2}') % 60)) */4 * * * /usr/share/jsjinstalltools/RunZypperUpdateCron" ) | \
    egrep -v "^#" | crontab -
fi
if [[ ${VERSION_ID/./} -eq 423 || (( ${VERSION_ID/./} -ge 132 && ${VERSION_ID/./} -lt 421 )) ]]; then
  sed -i -e '/^AccuracySec/ s/=.*$/=1min/' /usr/lib/systemd/system/logrotate.timer
  systemctl enable logrotate.timer
  systemctl start logrotate.timer
fi
