freedombone-utils-filesystem 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Filesystem encryption, etc
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. TOMB_REPO="https://github.com/dyne/Tomb"
  31. TOMB_COMMIT='c80ebd6d6ed77980eb5b559757e03ea13a29bdd1'
  32. function mesh_install_tomb {
  33. chroot ${rootdir} apt-get -yq install cryptsetup zsh pinentry-curses
  34. if [ ! -d ${rootdir}/$INSTALL_DIR ]; then
  35. mkdir -p ${rootdir}/$INSTALL_DIR
  36. fi
  37. if [ -d /repos/tomb ]; then
  38. mkdir ${rootdir}/$INSTALL_DIR/tomb
  39. cp -r -p /repos/tomb/. ${rootdir}/$INSTALL_DIR/tomb
  40. cd ${rootdir}/$INSTALL_DIR/tomb
  41. git pull
  42. else
  43. git_clone $TOMB_REPO ${rootdir}/$INSTALL_DIR/tomb
  44. fi
  45. cd ${rootdir}/$INSTALL_DIR/tomb
  46. git checkout $TOMB_COMMIT -b $TOMB_COMMIT
  47. chroot ${rootdir} /bin/bash -x <<EOF
  48. cd $INSTALL_DIR/tomb
  49. make install
  50. EOF
  51. if [ ! -f ${rootdir}/usr/local/bin/tomb ]; then
  52. exit 93462
  53. fi
  54. }
  55. function install_tomb {
  56. if [ $INSTALLING_MESH ]; then
  57. mesh_install_tomb
  58. return
  59. fi
  60. function_check set_repo_commit
  61. set_repo_commit $INSTALL_DIR/tomb "tomb commit" "$TOMB_COMMIT" $TOMB_REPO
  62. if [ -f $COMPLETION_FILE ]; then
  63. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  64. return
  65. fi
  66. fi
  67. apt-get -yq install cryptsetup zsh pinentry-curses
  68. if [ ! -d $INSTALL_DIR ]; then
  69. mkdir -p $INSTALL_DIR
  70. fi
  71. if [ -d /repos/tomb ]; then
  72. mkdir $INSTALL_DIR/tomb
  73. cp -r -p /repos/tomb/. $INSTALL_DIR/tomb
  74. cd $INSTALL_DIR/tomb
  75. git pull
  76. else
  77. git_clone $TOMB_REPO $INSTALL_DIR/tomb
  78. fi
  79. cd $INSTALL_DIR/tomb
  80. git checkout $TOMB_COMMIT -b $TOMB_COMMIT
  81. set_completion_param "tomb commit" "$TOMB_COMMIT"
  82. make install
  83. if [ ! -f /usr/local/bin/tomb ]; then
  84. exit 93462
  85. fi
  86. mark_completed $FUNCNAME
  87. }
  88. function defrag_filesystem {
  89. fs_type=$(stat -f /)
  90. if [[ "$fs_type" != *"btrfs"* && "$fs_type" != *"ext4"* ]]; then
  91. return
  92. fi
  93. echo $'Defragmenting root directory'
  94. if [[ "$fs_type" == *"btrfs"* ]]; then
  95. btrfs filesystem defragment -r -clzo /
  96. fi
  97. if [[ "$fs_type" == *"ext4"* ]]; then
  98. e4defrag /
  99. fi
  100. echo $'Defragmentation completed'
  101. }
  102. function optimise_filesystem {
  103. if grep -q "btrfs" /etc/fstab; then
  104. if ! grep -q "btrfs defaults,subvol=@,compress=lzo,ssd" /etc/fstab; then
  105. sed -i 's|btrfs subvol=@|btrfs defaults,subvol=@,compress=lzo,ssd|g' /etc/fstab
  106. fi
  107. fi
  108. }
  109. # NOTE: deliberately no exit 0