freedombone-app-emacs 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. DEFAULT_LANGUAGE)
  36. function logging_on_emacs {
  37. echo -n ''
  38. }
  39. function logging_off_emacs {
  40. echo -n ''
  41. }
  42. function reconfigure_emacs {
  43. echo -n ''
  44. }
  45. function upgrade_emacs {
  46. echo -n ''
  47. }
  48. function backup_local_emacs {
  49. for d in /home/*/ ; do
  50. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  51. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  52. if [ -d /home/$USERNAME/.emacs.d ]; then
  53. echo $"Backing up Emacs config for $USERNAME"
  54. if [ -f /home/$USERNAME/.emacs ]; then
  55. cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
  56. fi
  57. function_check backup_directory_to_usb
  58. backup_directory_to_usb /home/$USERNAME/.emacs.d emacs/$USERNAME
  59. fi
  60. fi
  61. done
  62. }
  63. function restore_local_emacs {
  64. temp_restore_dir=/root/tempemacs
  65. if [ -d $USB_MOUNT/backup/emacs ]; then
  66. for d in $USB_MOUNT/backup/emacs/*/ ; do
  67. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  68. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  69. if [ ! -d /home/$USERNAME ]; then
  70. ${PROJECT_NAME}-adduser $USERNAME
  71. fi
  72. echo $"Restoring Emacs config for $USERNAME"
  73. function_check restore_directory_from_usb
  74. restore_directory_from_usb $temp_restore_dir emacs/$USERNAME
  75. if [ -d $temp_restore_dir/home/$USERNAME/.emacs.d ]; then
  76. cp -r $temp_restore_dir/home/$USERNAME/.emacs.d /home/$USERNAME/
  77. else
  78. if [ ! -d /home/$USERNAME/.emacs.d ]; then
  79. mkdir /home/$USERNAME/.emacs.d
  80. fi
  81. cp -r $temp_restore_dir/* /home/$USERNAME/.emacs.d
  82. fi
  83. if [ ! "$?" = "0" ]; then
  84. rm -rf $temp_restore_dir
  85. function_check set_user_permissions
  86. set_user_permissions
  87. function_check backup_unmount_drive
  88. backup_unmount_drive
  89. exit 664
  90. fi
  91. if [ -d $temp_restore_dir/home/$USERNAME/.emacs.d ]; then
  92. cp -f $temp_restore_dir/home/$USERNAME/.emacs.d/dotemacs /home/$USERNAME/.emacs
  93. else
  94. cp -f $temp_restore_dir/dotemacs /home/$USERNAME/.emacs
  95. fi
  96. rm -rf $temp_restore_dir
  97. fi
  98. done
  99. fi
  100. }
  101. function backup_remote_emacs {
  102. for d in /home/*/ ; do
  103. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  104. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  105. if [ -d /home/$USERNAME/.emacs.d ]; then
  106. echo $"Backing up Emacs config for $USERNAME"
  107. if [ -f /home/$USERNAME/.emacs ]; then
  108. cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
  109. fi
  110. function_check backup_directory_to_friend
  111. backup_directory_to_friend /home/$USERNAME/.emacs.d emacs/$USERNAME
  112. fi
  113. fi
  114. done
  115. }
  116. function restore_remote_emacs {
  117. temp_restore_dir=/root/tempemacs
  118. if [ -d $USB_MOUNT/backup/emacs ]; then
  119. for d in $USB_MOUNT/backup/emacs/*/ ; do
  120. USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
  121. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  122. if [ ! -d /home/$USERNAME ]; then
  123. ${PROJECT_NAME}-adduser $USERNAME
  124. fi
  125. echo $"Restoring Emacs config for $USERNAME"
  126. function_check restore_directory_from_friend
  127. restore_directory_from_friend $temp_restore_dir emacs/$USERNAME
  128. if [ -d $temp_restore_dir/home/$USERNAME/.emacs.d ]; then
  129. cp -r $temp_restore_dir/home/$USERNAME/.emacs.d /home/$USERNAME/
  130. else
  131. if [ ! -d /home/$USERNAME/.emacs.d ]; then
  132. mkdir /home/$USERNAME/.emacs.d
  133. fi
  134. cp -r $temp_restore_dir/* /home/$USERNAME/.emacs.d/*
  135. fi
  136. if [ ! "$?" = "0" ]; then
  137. rm -rf $temp_restore_dir
  138. function_check set_user_permissions
  139. set_user_permissions
  140. function_check backup_unmount_drive
  141. backup_unmount_drive
  142. exit 664
  143. fi
  144. if [ -d $temp_restore_dir/home/$USERNAME/.emacs.d ]; then
  145. cp -f $temp_restore_dir/home/$USERNAME/.emacs.d/dotemacs /home/$USERNAME/.emacs
  146. else
  147. cp -f $temp_restore_dir/dotemacs /home/$USERNAME/.emacs
  148. fi
  149. rm -rf $temp_restore_dir
  150. fi
  151. done
  152. fi
  153. }
  154. function remove_emacs {
  155. apt-get -yq remove --purge emacs
  156. update-alternatives --set editor /usr/bin/nano
  157. sed -i '/install_emacs/d' $COMPLETION_FILE
  158. # remove emacs as the mutt email editor
  159. if [ -f /etc/Muttrc ]; then
  160. if grep -q "set editor=" /etc/Muttrc; then
  161. sed -i '/set editor=/d' /etc/Muttrc
  162. fi
  163. for d in /home/*/ ; do
  164. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  165. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  166. if [ -f /home/$USERNAME/.muttrc ]; then
  167. if grep -q "set editor=" /home/$USERNAME/.muttrc; then
  168. sed -i '/set editor=/d' /home/$USERNAME/.muttrc
  169. fi
  170. fi
  171. fi
  172. done
  173. fi
  174. }
  175. function install_emacs {
  176. apt-get -yq install emacs ispell ibritish ifrench ispanish iitalian irussian iswedish inorwegian iirish ingerman iswiss iogerman idutch idanish ibrazilian ibulgarian ipolish iczech iestonian ilithuanian iukrainian icatalan
  177. update-alternatives --set editor /usr/bin/emacs
  178. # A minimal emacs configuration
  179. #echo -n "(add-to-list 'load-path " > /home/$MY_USERNAME/.emacs
  180. #echo '"~/.emacs.d/")' >> /home/$MY_USERNAME/.emacs
  181. #echo '' >> /home/$MY_USERNAME/.emacs
  182. echo $';; ===== Remove trailing whitepace ======================================' >> /home/$MY_USERNAME/.emacs
  183. echo '' >> /home/$MY_USERNAME/.emacs
  184. echo ";;(add-hook 'before-save-hook 'delete-trailing-whitespace)" >> /home/$MY_USERNAME/.emacs
  185. echo '' >> /home/$MY_USERNAME/.emacs
  186. echo ';; Goto a line number with CTRL-l' >> /home/$MY_USERNAME/.emacs
  187. echo -n '(global-set-key "\C-l" ' >> /home/$MY_USERNAME/.emacs
  188. echo "'goto-line)" >> /home/$MY_USERNAME/.emacs
  189. echo '' >> /home/$MY_USERNAME/.emacs
  190. echo $';; ===== Show line numbers ==============================================' >> /home/$MY_USERNAME/.emacs
  191. echo '' >> /home/$MY_USERNAME/.emacs
  192. echo "(add-hook 'find-file-hook (lambda () (linum-mode 1)))" >> /home/$MY_USERNAME/.emacs
  193. echo '' >> /home/$MY_USERNAME/.emacs
  194. echo $';; ===== Enable line wrapping in org-mode ===============================' >> /home/$MY_USERNAME/.emacs
  195. echo '' >> /home/$MY_USERNAME/.emacs
  196. echo " (add-hook 'org-mode-hook" >> /home/$MY_USERNAME/.emacs
  197. echo " '(lambda ()" >> /home/$MY_USERNAME/.emacs
  198. echo " (visual-line-mode 1)))" >> /home/$MY_USERNAME/.emacs
  199. echo '' >> /home/$MY_USERNAME/.emacs
  200. echo $';; ===== Enable shift select in org mode ================================' >> /home/$MY_USERNAME/.emacs
  201. echo '' >> /home/$MY_USERNAME/.emacs
  202. echo '(setq org-support-shift-select t)' >> /home/$MY_USERNAME/.emacs
  203. echo '' >> /home/$MY_USERNAME/.emacs
  204. echo $';; ===== Set standard indent to 4 rather that 4 =========================' >> /home/$MY_USERNAME/.emacs
  205. echo '' >> /home/$MY_USERNAME/.emacs
  206. echo '(setq standard-indent 4)' >> /home/$MY_USERNAME/.emacs
  207. echo '(setq-default tab-width 4)' >> /home/$MY_USERNAME/.emacs
  208. echo '(setq c-basic-offset 4)' >> /home/$MY_USERNAME/.emacs
  209. echo '' >> /home/$MY_USERNAME/.emacs
  210. echo $';; ===== Support Wheel Mouse Scrolling ==================================' >> /home/$MY_USERNAME/.emacs
  211. echo '' >> /home/$MY_USERNAME/.emacs
  212. echo '(mouse-wheel-mode t)' >> /home/$MY_USERNAME/.emacs
  213. echo '' >> /home/$MY_USERNAME/.emacs
  214. echo $';; ===== Place Backup Files in Specific Directory =======================' >> /home/$MY_USERNAME/.emacs
  215. echo '' >> /home/$MY_USERNAME/.emacs
  216. echo '(setq make-backup-files t)' >> /home/$MY_USERNAME/.emacs
  217. echo '(setq version-control t)' >> /home/$MY_USERNAME/.emacs
  218. echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))' >> /home/$MY_USERNAME/.emacs
  219. echo '' >> /home/$MY_USERNAME/.emacs
  220. echo $';; ===== Make Text mode the default mode for new buffers ================' >> /home/$MY_USERNAME/.emacs
  221. echo '' >> /home/$MY_USERNAME/.emacs
  222. echo "(setq default-major-mode 'text-mode)" >> /home/$MY_USERNAME/.emacs
  223. echo '' >> /home/$MY_USERNAME/.emacs
  224. echo $';; ===== Line length ====================================================' >> /home/$MY_USERNAME/.emacs
  225. echo '' >> /home/$MY_USERNAME/.emacs
  226. echo '(setq-default fill-column 72)' >> /home/$MY_USERNAME/.emacs
  227. echo '' >> /home/$MY_USERNAME/.emacs
  228. echo $';; ===== Enable Line and Column Numbering ===============================' >> /home/$MY_USERNAME/.emacs
  229. echo '' >> /home/$MY_USERNAME/.emacs
  230. echo '(line-number-mode 1)' >> /home/$MY_USERNAME/.emacs
  231. echo '(column-number-mode 1)' >> /home/$MY_USERNAME/.emacs
  232. echo '' >> /home/$MY_USERNAME/.emacs
  233. echo $';; ===== Turn on Auto Fill mode automatically in all modes ==============' >> /home/$MY_USERNAME/.emacs
  234. echo '' >> /home/$MY_USERNAME/.emacs
  235. echo ';; Auto-fill-mode the the automatic wrapping of lines and insertion of' >> /home/$MY_USERNAME/.emacs
  236. echo ';; newlines when the cursor goes over the column limit.' >> /home/$MY_USERNAME/.emacs
  237. echo '' >> /home/$MY_USERNAME/.emacs
  238. echo ';; This should actually turn on auto-fill-mode by default in all major' >> /home/$MY_USERNAME/.emacs
  239. echo ';; modes. The other way to do this is to turn on the fill for specific modes' >> /home/$MY_USERNAME/.emacs
  240. echo ';; via hooks.' >> /home/$MY_USERNAME/.emacs
  241. echo '' >> /home/$MY_USERNAME/.emacs
  242. echo '(setq auto-fill-mode 1)' >> /home/$MY_USERNAME/.emacs
  243. echo '' >> /home/$MY_USERNAME/.emacs
  244. echo $';; ===== Enable GPG encryption =========================================' >> /home/$MY_USERNAME/.emacs
  245. echo '' >> /home/$MY_USERNAME/.emacs
  246. echo "(require 'epa)" >> /home/$MY_USERNAME/.emacs
  247. echo '(epa-file-enable)' >> /home/$MY_USERNAME/.emacs
  248. cp /home/$MY_USERNAME/.emacs /root/.emacs
  249. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs
  250. # add a mutt entry to use emacs to compose emails
  251. if [ -f /etc/Muttrc ]; then
  252. if ! grep -q "set editor=" /etc/Muttrc; then
  253. echo 'set editor="emacs -q --load ~/.emacs-mutt"' >> /etc/Muttrc
  254. else
  255. sed -i 's|set editor=.*|set editor="emacs -q --load ~/.emacs-mutt"|g' /etc/Muttrc
  256. fi
  257. for d in /home/*/ ; do
  258. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  259. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  260. if [ -f /home/$USERNAME/.muttrc ]; then
  261. if ! grep -q "set editor=" /home/$USERNAME/.muttrc; then
  262. echo 'set editor="emacs -q --load ~/.emacs-mutt"' >> /home/$USERNAME/.muttrc
  263. else
  264. sed -i 's|set editor=.*|set editor="emacs -q --load ~/.emacs-mutt"|g' /home/$USERNAME/.muttrc
  265. fi
  266. fi
  267. # create an Emacs configuration specifically for use with Mutt, which
  268. # has word wrap and spell checking on by default
  269. if [ ! -f /home/$USERNAME/.emacs-mutt ]; then
  270. echo "(add-hook 'before-save-hook 'delete-trailing-whitespace)" > /home/$USERNAME/.emacs-mutt
  271. echo '(setq org-support-shift-select t)' >> /home/$USERNAME/.emacs-mutt
  272. echo '(setq standard-indent 4)' >> /home/$USERNAME/.emacs-mutt
  273. echo '(setq-default tab-width 4)' >> /home/$USERNAME/.emacs-mutt
  274. echo '(setq c-basic-offset 4)' >> /home/$USERNAME/.emacs-mutt
  275. echo '(mouse-wheel-mode t)' >> /home/$USERNAME/.emacs-mutt
  276. echo '(setq make-backup-files t)' >> /home/$USERNAME/.emacs-mutt
  277. echo '(setq version-control t)' >> /home/$USERNAME/.emacs-mutt
  278. echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))' >> /home/$USERNAME/.emacs-mutt
  279. echo "(setq default-major-mode 'text-mode)" >> /home/$USERNAME/.emacs-mutt
  280. echo "(dolist (hook '(text-mode-hook))" >> /home/$USERNAME/.emacs-mutt
  281. echo ' (add-hook hook (lambda () (flyspell-mode 1))))' >> /home/$USERNAME/.emacs-mutt
  282. echo '(setq-default fill-column 72)' >> /home/$USERNAME/.emacs-mutt
  283. if [[ $DEFAULT_LANGUAGE == 'en_US'* ]]; then
  284. echo '(setq ispell-dictionary "american")' >> /home/$USERNAME/.emacs-mutt
  285. fi
  286. if [[ $DEFAULT_LANGUAGE == 'en_GB'* ]]; then
  287. echo '(setq ispell-dictionary "british")' >> /home/$USERNAME/.emacs-mutt
  288. fi
  289. if [[ $DEFAULT_LANGUAGE == 'fr_FR'* ]]; then
  290. echo '(setq ispell-dictionary "french")' >> /home/$USERNAME/.emacs-mutt
  291. fi
  292. if [[ $DEFAULT_LANGUAGE == 'it_IT'* ]]; then
  293. echo '(setq ispell-dictionary "italian")' >> /home/$USERNAME/.emacs-mutt
  294. fi
  295. if [[ $DEFAULT_LANGUAGE == 'cs_CZ'* ]]; then
  296. echo '(setq ispell-dictionary "czech")' >> /home/$USERNAME/.emacs-mutt
  297. fi
  298. if [[ $DEFAULT_LANGUAGE == 'da_DK'* ]]; then
  299. echo '(setq ispell-dictionary "danish")' >> /home/$USERNAME/.emacs-mutt
  300. fi
  301. if [[ $DEFAULT_LANGUAGE == 'nl_NL'* ]]; then
  302. echo '(setq ispell-dictionary "dutch")' >> /home/$USERNAME/.emacs-mutt
  303. fi
  304. if [[ $DEFAULT_LANGUAGE == 'ru_RU'* ]]; then
  305. echo '(setq ispell-dictionary "russian")' >> /home/$USERNAME/.emacs-mutt
  306. fi
  307. if [[ $DEFAULT_LANGUAGE == 'es_ES'* ]]; then
  308. echo '(setq ispell-dictionary "spanish")' >> /home/$USERNAME/.emacs-mutt
  309. fi
  310. if [[ $DEFAULT_LANGUAGE == 'sv_SE'* ]]; then
  311. echo '(setq ispell-dictionary "swedish")' >> /home/$USERNAME/.emacs-mutt
  312. fi
  313. if [[ $DEFAULT_LANGUAGE == 'no_NO'* ]]; then
  314. echo '(setq ispell-dictionary "norwegian")' >> /home/$USERNAME/.emacs-mutt
  315. fi
  316. if [[ $DEFAULT_LANGUAGE == 'de_DE'* ]]; then
  317. echo '(setq ispell-dictionary "ngerman")' >> /home/$USERNAME/.emacs-mutt
  318. fi
  319. if [[ $DEFAULT_LANGUAGE == 'bg_BG'* ]]; then
  320. echo '(setq ispell-dictionary "bulgarian")' >> /home/$USERNAME/.emacs-mutt
  321. fi
  322. if [[ $DEFAULT_LANGUAGE == 'pl'* ]]; then
  323. echo '(setq ispell-dictionary "polish")' >> /home/$USERNAME/.emacs-mutt
  324. fi
  325. if [[ $DEFAULT_LANGUAGE == 'et_EE'* ]]; then
  326. echo '(setq ispell-dictionary "estonian")' >> /home/$USERNAME/.emacs-mutt
  327. fi
  328. if [[ $DEFAULT_LANGUAGE == 'lt_LT'* ]]; then
  329. echo '(setq ispell-dictionary "lithuanian")' >> /home/$USERNAME/.emacs-mutt
  330. fi
  331. if [[ $DEFAULT_LANGUAGE == 'uk_UA'* ]]; then
  332. echo '(setq ispell-dictionary "ukranian")' >> /home/$USERNAME/.emacs-mutt
  333. fi
  334. if [[ $DEFAULT_LANGUAGE == 'ca_ES'* ]]; then
  335. echo '(setq ispell-dictionary "catalan")' >> /home/$USERNAME/.emacs-mutt
  336. fi
  337. echo '(setq auto-fill-mode 0)' >> /home/$USERNAME/.emacs-mutt
  338. echo "(add-hook 'text-mode-hook 'turn-on-auto-fill)" >> /home/$USERNAME/.emacs-mutt
  339. echo "(setq-default auto-fill-function 'do-auto-fill)" >> /home/$USERNAME/.emacs-mutt
  340. chown $USERNAME:$USERNAME /home/$USERNAME/.emacs-mutt
  341. # add the emacs mutt configuration to the user profile skeleton
  342. if [ ! -f /etc/skel/.emacs-mutt ]; then
  343. cp /home/$USERNAME/.emacs-mutt /etc/skel/.emacs-mutt
  344. chown root:root /etc/skel/.emacs-mutt
  345. fi
  346. fi
  347. fi
  348. done
  349. fi
  350. APP_INSTALLED=1
  351. }
  352. function install_interactive_emacs {
  353. install_emacs
  354. }
  355. # NOTE: deliberately no exit 0