freedombone-app-emacs 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Emacs application
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 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. VARIANTS='full'
  31. IN_DEFAULT_INSTALL=1
  32. SHOW_ON_ABOUT=0
  33. emacs_variables=(USB_MOUNT
  34. MY_USERNAME)
  35. function reconfigure_emacs {
  36. echo -n ''
  37. }
  38. function upgrade_emacs {
  39. echo -n ''
  40. }
  41. function backup_local_emacs {
  42. for d in /home/*/ ; do
  43. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  44. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  45. if [ -d /home/$USERNAME/.emacs.d ]; then
  46. echo $"Backing up Emacs config for $USERNAME"
  47. if [ -f /home/$USERNAME/.emacs ]; then
  48. cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
  49. fi
  50. function_check backup_directory_to_usb
  51. backup_directory_to_usb /home/$USERNAME/.emacs.d emacs/$USERNAME
  52. fi
  53. fi
  54. done
  55. }
  56. function restore_local_emacs {
  57. temp_restore_dir=/root/tempemacs
  58. if [ -d $USB_MOUNT/backup/emacs ]; then
  59. for d in $USB_MOUNT/backup/emacs/*/ ; do
  60. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  61. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  62. if [ ! -d /home/$USERNAME ]; then
  63. ${PROJECT_NAME}-adduser $USERNAME
  64. fi
  65. echo $"Restoring Emacs config for $USERNAME"
  66. function_check restore_directory_from_usb
  67. restore_directory_from_usb $temp_restore_dir emacs/$USERNAME
  68. cp -r $temp_restore_dir/home/$USERNAME/.emacs.d /home/$USERNAME/
  69. if [ ! "$?" = "0" ]; then
  70. rm -rf $temp_restore_dir
  71. function_check set_user_permissions
  72. set_user_permissions
  73. function_check backup_unmount_drive
  74. backup_unmount_drive
  75. exit 664
  76. fi
  77. cp -f $temp_restore_dir/home/$USERNAME/.emacs.d/dotemacs /home/$USERNAME/.emacs
  78. rm -rf $temp_restore_dir
  79. fi
  80. done
  81. fi
  82. }
  83. function backup_remote_emacs {
  84. for d in /home/*/ ; do
  85. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  86. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  87. if [ -d /home/$USERNAME/.emacs.d ]; then
  88. echo $"Backing up Emacs config for $USERNAME"
  89. if [ -f /home/$USERNAME/.emacs ]; then
  90. cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
  91. fi
  92. function_check backup_directory_to_friend
  93. backup_directory_to_friend /home/$USERNAME/.emacs.d emacs/$USERNAME
  94. fi
  95. fi
  96. done
  97. }
  98. function restore_remote_emacs {
  99. temp_restore_dir=/root/tempemacs
  100. if [ -d $USB_MOUNT/backup/emacs ]; then
  101. for d in $USB_MOUNT/backup/emacs/*/ ; do
  102. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  103. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  104. if [ ! -d /home/$USERNAME ]; then
  105. ${PROJECT_NAME}-adduser $USERNAME
  106. fi
  107. echo $"Restoring Emacs config for $USERNAME"
  108. function_check restore_directory_from_friend
  109. restore_directory_from_friend $temp_restore_dir emacs/$USERNAME
  110. cp -r $temp_restore_dir/home/$USERNAME/.emacs.d /home/$USERNAME/
  111. if [ ! "$?" = "0" ]; then
  112. rm -rf $temp_restore_dir
  113. function_check set_user_permissions
  114. set_user_permissions
  115. function_check backup_unmount_drive
  116. backup_unmount_drive
  117. exit 664
  118. fi
  119. cp -f $temp_restore_dir/home/$USERNAME/.emacs.d/dotemacs /home/$USERNAME/.emacs
  120. rm -rf $temp_restore_dir
  121. fi
  122. done
  123. fi
  124. }
  125. function remove_emacs {
  126. apt-get -yq remove --purge emacs24
  127. update-alternatives --set editor /usr/bin/nano
  128. sed -i '/install_emacs/d' $COMPLETION_FILE
  129. # remove emacs as the mutt email editor
  130. if [ -f /etc/Muttrc ]; then
  131. if grep -q "set editor=" /etc/Muttrc; then
  132. sed -i '/set editor=/d' /etc/Muttrc
  133. fi
  134. for d in /home/*/ ; do
  135. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  136. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  137. if [ -f /home/$USERNAME/.muttrc ]; then
  138. if grep -q "set editor=" /home/$USERNAME/.muttrc; then
  139. sed -i '/set editor=/d' /home/$USERNAME/.muttrc
  140. fi
  141. fi
  142. fi
  143. done
  144. fi
  145. }
  146. function install_emacs {
  147. apt-get -yq install emacs24
  148. update-alternatives --set editor /usr/bin/emacs24
  149. # A minimal emacs configuration
  150. #echo -n "(add-to-list 'load-path " > /home/$MY_USERNAME/.emacs
  151. #echo '"~/.emacs.d/")' >> /home/$MY_USERNAME/.emacs
  152. #echo '' >> /home/$MY_USERNAME/.emacs
  153. echo $';; ===== Remove trailing whitepace ======================================' >> /home/$MY_USERNAME/.emacs
  154. echo '' >> /home/$MY_USERNAME/.emacs
  155. echo ";;(add-hook 'before-save-hook 'delete-trailing-whitespace)" >> /home/$MY_USERNAME/.emacs
  156. echo '' >> /home/$MY_USERNAME/.emacs
  157. echo ';; Goto a line number with CTRL-l' >> /home/$MY_USERNAME/.emacs
  158. echo -n '(global-set-key "\C-l" ' >> /home/$MY_USERNAME/.emacs
  159. echo "'goto-line)" >> /home/$MY_USERNAME/.emacs
  160. echo '' >> /home/$MY_USERNAME/.emacs
  161. echo $';; ===== Show line numbers ==============================================' >> /home/$MY_USERNAME/.emacs
  162. echo '' >> /home/$MY_USERNAME/.emacs
  163. echo "(add-hook 'find-file-hook (lambda () (linum-mode 1)))" >> /home/$MY_USERNAME/.emacs
  164. echo '' >> /home/$MY_USERNAME/.emacs
  165. echo $';; ===== Enable line wrapping in org-mode ===============================' >> /home/$MY_USERNAME/.emacs
  166. echo '' >> /home/$MY_USERNAME/.emacs
  167. echo " (add-hook 'org-mode-hook" >> /home/$MY_USERNAME/.emacs
  168. echo " '(lambda ()" >> /home/$MY_USERNAME/.emacs
  169. echo " (visual-line-mode 1)))" >> /home/$MY_USERNAME/.emacs
  170. echo '' >> /home/$MY_USERNAME/.emacs
  171. echo $';; ===== Enable shift select in org mode ================================' >> /home/$MY_USERNAME/.emacs
  172. echo '' >> /home/$MY_USERNAME/.emacs
  173. echo '(setq org-support-shift-select t)' >> /home/$MY_USERNAME/.emacs
  174. echo '' >> /home/$MY_USERNAME/.emacs
  175. echo $';; ===== Set standard indent to 4 rather that 4 =========================' >> /home/$MY_USERNAME/.emacs
  176. echo '' >> /home/$MY_USERNAME/.emacs
  177. echo '(setq standard-indent 4)' >> /home/$MY_USERNAME/.emacs
  178. echo '(setq-default tab-width 4)' >> /home/$MY_USERNAME/.emacs
  179. echo '(setq c-basic-offset 4)' >> /home/$MY_USERNAME/.emacs
  180. echo '' >> /home/$MY_USERNAME/.emacs
  181. echo $';; ===== Support Wheel Mouse Scrolling ==================================' >> /home/$MY_USERNAME/.emacs
  182. echo '' >> /home/$MY_USERNAME/.emacs
  183. echo '(mouse-wheel-mode t)' >> /home/$MY_USERNAME/.emacs
  184. echo '' >> /home/$MY_USERNAME/.emacs
  185. echo $';; ===== Place Backup Files in Specific Directory =======================' >> /home/$MY_USERNAME/.emacs
  186. echo '' >> /home/$MY_USERNAME/.emacs
  187. echo '(setq make-backup-files t)' >> /home/$MY_USERNAME/.emacs
  188. echo '(setq version-control t)' >> /home/$MY_USERNAME/.emacs
  189. echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))' >> /home/$MY_USERNAME/.emacs
  190. echo '' >> /home/$MY_USERNAME/.emacs
  191. echo $';; ===== Make Text mode the default mode for new buffers ================' >> /home/$MY_USERNAME/.emacs
  192. echo '' >> /home/$MY_USERNAME/.emacs
  193. echo "(setq default-major-mode 'text-mode)" >> /home/$MY_USERNAME/.emacs
  194. echo '' >> /home/$MY_USERNAME/.emacs
  195. echo $';; ===== Line length ====================================================' >> /home/$MY_USERNAME/.emacs
  196. echo '' >> /home/$MY_USERNAME/.emacs
  197. echo '(setq-default fill-column 72)' >> /home/$MY_USERNAME/.emacs
  198. echo '' >> /home/$MY_USERNAME/.emacs
  199. echo $';; ===== Enable Line and Column Numbering ===============================' >> /home/$MY_USERNAME/.emacs
  200. echo '' >> /home/$MY_USERNAME/.emacs
  201. echo '(line-number-mode 1)' >> /home/$MY_USERNAME/.emacs
  202. echo '(column-number-mode 1)' >> /home/$MY_USERNAME/.emacs
  203. echo '' >> /home/$MY_USERNAME/.emacs
  204. echo $';; ===== Turn on Auto Fill mode automatically in all modes ==============' >> /home/$MY_USERNAME/.emacs
  205. echo '' >> /home/$MY_USERNAME/.emacs
  206. echo ';; Auto-fill-mode the the automatic wrapping of lines and insertion of' >> /home/$MY_USERNAME/.emacs
  207. echo ';; newlines when the cursor goes over the column limit.' >> /home/$MY_USERNAME/.emacs
  208. echo '' >> /home/$MY_USERNAME/.emacs
  209. echo ';; This should actually turn on auto-fill-mode by default in all major' >> /home/$MY_USERNAME/.emacs
  210. echo ';; modes. The other way to do this is to turn on the fill for specific modes' >> /home/$MY_USERNAME/.emacs
  211. echo ';; via hooks.' >> /home/$MY_USERNAME/.emacs
  212. echo '' >> /home/$MY_USERNAME/.emacs
  213. echo '(setq auto-fill-mode 1)' >> /home/$MY_USERNAME/.emacs
  214. echo '' >> /home/$MY_USERNAME/.emacs
  215. echo $';; ===== Enable GPG encryption =========================================' >> /home/$MY_USERNAME/.emacs
  216. echo '' >> /home/$MY_USERNAME/.emacs
  217. echo "(require 'epa)" >> /home/$MY_USERNAME/.emacs
  218. echo '(epa-file-enable)' >> /home/$MY_USERNAME/.emacs
  219. cp /home/$MY_USERNAME/.emacs /root/.emacs
  220. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs
  221. # add a mutt entry to use emacs to compose emails
  222. if [ -f /etc/Muttrc ]; then
  223. if ! grep -q "set editor=" /etc/Muttrc; then
  224. echo 'set editor="emacs -q --load ~/.emacs-mutt"' >> /etc/Muttrc
  225. else
  226. sed -i 's|set editor=.*|set editor="emacs -q --load ~/.emacs-mutt"|g' /etc/Muttrc
  227. fi
  228. for d in /home/*/ ; do
  229. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  230. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  231. if [ -f /home/$USERNAME/.muttrc ]; then
  232. if ! grep -q "set editor=" /home/$USERNAME/.muttrc; then
  233. echo 'set editor="emacs -q --load ~/.emacs-mutt"' >> /home/$USERNAME/.muttrc
  234. else
  235. sed -i 's|set editor=.*|set editor="emacs -q --load ~/.emacs-mutt"|g' /home/$USERNAME/.muttrc
  236. fi
  237. fi
  238. # create an Emacs configuration specifically for use with Mutt, which
  239. # has word wrap and spell checking on by default
  240. if [ ! -f /home/$USERNAME/.emacs-mutt ]; then
  241. echo "(add-hook 'before-save-hook 'delete-trailing-whitespace)" > /home/$USERNAME/.emacs-mutt
  242. echo '(setq org-support-shift-select t)' >> /home/$USERNAME/.emacs-mutt
  243. echo '(setq standard-indent 4)' >> /home/$USERNAME/.emacs-mutt
  244. echo '(setq-default tab-width 4)' >> /home/$USERNAME/.emacs-mutt
  245. echo '(setq c-basic-offset 4)' >> /home/$USERNAME/.emacs-mutt
  246. echo '(mouse-wheel-mode t)' >> /home/$USERNAME/.emacs-mutt
  247. echo '(setq make-backup-files t)' >> /home/$USERNAME/.emacs-mutt
  248. echo '(setq version-control t)' >> /home/$USERNAME/.emacs-mutt
  249. echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))' >> /home/$USERNAME/.emacs-mutt
  250. echo "(setq default-major-mode 'text-mode)" >> /home/$USERNAME/.emacs-mutt
  251. echo "(dolist (hook '(text-mode-hook))" >> /home/$USERNAME/.emacs-mutt
  252. echo ' (add-hook hook (lambda () (flyspell-mode 1))))' >> /home/$USERNAME/.emacs-mutt
  253. echo '(setq-default fill-column 72)' >> /home/$USERNAME/.emacs-mutt
  254. echo '(setq auto-fill-mode 0)' >> /home/$USERNAME/.emacs-mutt
  255. echo "(add-hook 'text-mode-hook 'turn-on-auto-fill)" >> /home/$USERNAME/.emacs-mutt
  256. echo "(setq-default auto-fill-function 'do-auto-fill)" >> /home/$USERNAME/.emacs-mutt
  257. chown $USERNAME:$USERNAME /home/$USERNAME/.emacs-mutt
  258. # add the emacs mutt configuration to the user profile skeleton
  259. if [ ! -f /etc/skel/.emacs-mutt ]; then
  260. cp /home/$USERNAME/.emacs-mutt /etc/skel/.emacs-mutt
  261. chown root:root /etc/skel/.emacs-mutt
  262. fi
  263. fi
  264. fi
  265. done
  266. fi
  267. APP_INSTALLED=1
  268. }
  269. function install_interactive_emacs {
  270. install_emacs
  271. }
  272. # NOTE: deliberately no exit 0