factory-reset 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh
  2. ################################################################################
  3. # This file is part of OpenELEC - http://www.openelec.tv
  4. # Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv)
  5. #
  6. # OpenELEC 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 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # OpenELEC 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 OpenELEC. If not, see <http://www.gnu.org/licenses/>.
  18. ################################################################################
  19. get_target() {
  20. for arg in $(cat /proc/cmdline); do
  21. case $arg in
  22. disk=*)
  23. disk="${arg#*=}"
  24. case $disk in
  25. LABEL=*)
  26. label="${disk#*=}"
  27. target=`blkid -L $label`
  28. ;;
  29. UUID=*)
  30. uuid="${disk#*=}"
  31. target=`blkid -U $uuid`
  32. ;;
  33. /*)
  34. target=$disk
  35. ;;
  36. esac
  37. ;;
  38. esac
  39. done
  40. }
  41. if [ -f /storage/.cache/reset_oe ] ; then
  42. # hard reset
  43. rm -f /storage/.cache/reset_oe
  44. get_target
  45. if [ ! -z $target ] ; then
  46. echo "hard resetting..."
  47. umount /storage
  48. mke2fs -t ext4 -m 0 $target 2>&1 >/dev/null
  49. if [ ! -z $label ] ; then
  50. tune2fs -U random -L $label $target
  51. fi
  52. if [ ! -z $uuid ] ; then
  53. tune2fs -U $uuid $target
  54. fi
  55. echo "done"
  56. sleep 5
  57. fi
  58. elif [ -f /storage/.cache/reset_xbmc ] ; then
  59. # soft reset
  60. rm -f /storage/.cache/reset_xbmc
  61. get_target
  62. if [ ! -z $target ] ; then
  63. echo "soft resetting..."
  64. rm -rf /storage/.??* 2>&1 >/dev/null
  65. echo "done"
  66. sleep 5
  67. fi
  68. fi
  69. sync
  70. reboot -f