You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.1 KiB

  1. #!/usr/bin/env sh
  2. [ "$(id -u)" -eq 0 ] || { echo 'You need to be ROOT (sudo can be used)' ; exit 1 ;}
  3. . /log2ram.conf # Include config to check if size is enought (See below)
  4. # See if we can find out the init-system
  5. echo 'Try to detect init and running log2ram service...'
  6. if [ "$(systemctl --version 2> /dev/null)" != '' ] ; then
  7. INIT='systemd'
  8. elif [ "$(rc-service --version 2> /dev/null)" != '' ] ; then
  9. INIT='openrc'
  10. fi
  11. case "$INIT" in
  12. systemd)
  13. systemctl -q is-active log2ram && { echo 'ERROR: log2ram service is still running. Please run "sudo service log2ram stop" to stop it.' ; exit 1 ;} ;;
  14. openrc)
  15. rc-service log2ram status >/dev/null 2>&1 && { echo 'ERROR: log2ram service is still running. Please run "sudo rc-service log2ram stop" to stop it.' ; exit 1 ;} ;;
  16. *) echo 'ERROR: could not detect init-system' ; exit 1
  17. ;;
  18. esac
  19. echo "Installing log2ram for $INIT init-system"
  20. # log2ram
  21. mkdir -p /usr/local/bin/
  22. install -m 755 log2ram /usr/local/bin/log2ram
  23. install -m 644 log2ram.conf /etc/log2ram.conf
  24. install -m 644 uninstall.sh /usr/local/bin/uninstall-log2ram.sh
  25. if [ "$INIT" = 'systemd' ] ; then
  26. install -m 644 log2ram.service /etc/systemd/system/log2ram.service
  27. systemctl enable log2ram
  28. elif [ "$INIT" = 'openrc' ] ; then
  29. install -m 755 log2ram.initd /etc/init.d/log2ram
  30. rc-update add log2ram boot
  31. fi
  32. # cron
  33. if [ "$INIT" = 'systemd' ] ; then
  34. install -m 755 log2ram.cron /etc/cron.daily/log2ram
  35. elif [ "$INIT" = 'openrc' ] ; then
  36. install -m 755 log2ram.openrc_cron /etc/cron.daily/log2ram
  37. fi
  38. install -m 644 log2ram.logrotate /etc/logrotate.d/log2ram
  39. # Remove a previous log2ram version
  40. rm -rf /var/log.hdd
  41. # Make sure we start clean
  42. rm -rf /var/hdd.log
  43. # Check if var SIZE is sufficient and show a warning when too small
  44. if [ -n "$(du -sh -t "$SIZE" /var/log | cut -f1)" ] ; then # /var/log should be ok on all systems
  45. echo 'WARNING: Variable SIZE in /etc/log2ram.conf is too small to store the /var/log!'
  46. echo 'Actual size of /var/log is:' ; du -sh /var/log
  47. fi
  48. echo '##### Reboot to activate log2ram! #####'
  49. echo '##### Edit /etc/log2ram.conf to configure options #####'