zramraid-manager 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides: zramraid-manager
  4. # Required-Start: udev $local_fs $remote_fs $time
  5. # Required-Stop: $local_fs $remote_fs
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: start the zraid
  9. # Description: starts zraid using start-stop-daemon
  10. ### END INIT INFO
  11. ## version =25.06.18
  12. PARMS=$1
  13. PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/etc/zramraid";
  14. DESC="Zram Raid"
  15. NAME="zramraid"
  16. SCRIPTNAME="zramraid-maker";
  17. ZPATH="/etc/zramraid"
  18. MODE="/etc/default/zramraid";
  19. ##
  20. if [[ "$PARMS" = '' ]];
  21. then
  22. echo "/etc/init.d/zramraid-manager {start|stop|restart|status}"
  23. exit 0
  24. fi
  25. function zRun() {
  26. if [ ! $(echo $USER|grep root|wc -m) = 0 ]
  27. then
  28. if [ $(cat $MODE |grep mode|grep -v '#'|sed 's/\mode=//g'|sed 's/\"//g;s/\;//g'|grep auto|wc -m) == 0 ]
  29. then
  30. echo "$(date) $NAME: no autostart from boot! mode=manual - /etc/defaults/zramraid">>/var/log/zramraid.log
  31. exit 0;
  32. else
  33. $ZPATH/$SCRIPTNAME --on
  34. fi
  35. exit 0;
  36. fi
  37. if [ ! $(echo $USER|grep '[priv]'|wc -m) = 0 ]
  38. then
  39. if [ $(cat $MODE |grep mode|grep -v '#'|sed 's/\mode=//g'|sed 's/\"//g;s/\;//g'|grep auto|wc -m) == 0 ]
  40. then
  41. echo "$(date) $NAME: no autostart from boot! mode=manual - /etc/defaults/zramraid">>/var/log/zramraid.log
  42. exit 0;
  43. else
  44. $ZPATH/$SCRIPTNAME --on
  45. fi
  46. exit 0;
  47. fi
  48. echo "$NAME:Sorry.. The only root privileges!"
  49. exit 0;
  50. }
  51. ### begin
  52. case "$PARMS" in
  53. "start" | "start" )
  54. zRun;
  55. exit 0
  56. ;;
  57. "stop" | "stop" )
  58. $ZPATH/$SCRIPTNAME --off
  59. exit 0
  60. ;;
  61. "restart" | "restart" )
  62. $ZPATH/$SCRIPTNAME --off
  63. sleep 3
  64. zRun;
  65. exit 0
  66. ;;
  67. "status" | "status" )
  68. $ZPATH/$SCRIPTNAME --status
  69. exit 0
  70. ;;
  71. "boot" | "boot" )
  72. zBoot;
  73. exit 0
  74. ;;
  75. * )
  76. echo
  77. echo "no input parameters."
  78. exit 1
  79. ;;
  80. esac