2016-07-03 17:13:34 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
2016-07-05 21:07:43 +02:00
|
|
|
# Emacs application
|
2016-07-03 17:13:34 +02:00
|
|
|
#
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
|
|
|
# Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-10-09 23:25:47 +02:00
|
|
|
VARIANTS='full'
|
2016-07-06 17:47:55 +02:00
|
|
|
|
2016-10-05 23:33:41 +02:00
|
|
|
emacs_variables=(USB_MOUNT
|
|
|
|
MY_USERNAME)
|
|
|
|
|
2016-09-25 12:20:41 +02:00
|
|
|
function change_password_emacs {
|
|
|
|
echo -n ''
|
|
|
|
}
|
|
|
|
|
2016-07-09 12:36:12 +02:00
|
|
|
function reconfigure_emacs {
|
2016-08-29 11:48:49 +02:00
|
|
|
echo -n ''
|
2016-07-09 12:36:12 +02:00
|
|
|
}
|
|
|
|
|
2016-07-06 16:01:28 +02:00
|
|
|
function upgrade_emacs {
|
2016-08-29 11:48:49 +02:00
|
|
|
echo -n ''
|
2016-07-06 16:01:28 +02:00
|
|
|
}
|
|
|
|
|
2016-07-06 15:55:09 +02:00
|
|
|
function backup_local_emacs {
|
2016-08-29 11:48:49 +02:00
|
|
|
for d in /home/*/ ; do
|
|
|
|
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
|
2016-10-01 11:48:07 +02:00
|
|
|
if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
|
2016-08-29 11:48:49 +02:00
|
|
|
if [ -d /home/$USERNAME/.emacs.d ]; then
|
|
|
|
echo $"Backing up Emacs config for $USERNAME"
|
|
|
|
if [ -f /home/$USERNAME/.emacs ]; then
|
|
|
|
cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
|
|
|
|
fi
|
|
|
|
function_check backup_directory_to_usb
|
2016-10-12 11:49:12 +02:00
|
|
|
backup_directory_to_usb /home/$USERNAME/.emacs.d emacs/$USERNAME
|
2016-08-29 11:48:49 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2016-07-06 15:55:09 +02:00
|
|
|
}
|
|
|
|
|
2016-07-09 12:15:41 +02:00
|
|
|
function restore_local_emacs {
|
2016-08-29 11:48:49 +02:00
|
|
|
temp_restore_dir=/root/tempemacs
|
|
|
|
if [ -d $USB_MOUNT/backup/emacs ]; then
|
|
|
|
for d in $USB_MOUNT/backup/emacs/*/ ; do
|
|
|
|
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
|
2016-10-01 11:48:07 +02:00
|
|
|
if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
|
2016-08-29 11:48:49 +02:00
|
|
|
if [ ! -d /home/$USERNAME ]; then
|
|
|
|
${PROJECT_NAME}-adduser $USERNAME
|
|
|
|
fi
|
|
|
|
echo $"Restoring Emacs config for $USERNAME"
|
|
|
|
function_check restore_directory_from_usb
|
|
|
|
restore_directory_from_usb $temp_restore_dir emacs/$USERNAME
|
|
|
|
cp -r $temp_restore_dir/home/$USERNAME/.emacs.d /home/$USERNAME/
|
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
rm -rf $temp_restore_dir
|
|
|
|
function_check set_user_permissions
|
|
|
|
set_user_permissions
|
|
|
|
function_check backup_unmount_drive
|
|
|
|
backup_unmount_drive
|
|
|
|
exit 664
|
|
|
|
fi
|
|
|
|
cp -f $temp_restore_dir/home/$USERNAME/.emacs.d/dotemacs /home/$USERNAME/.emacs
|
|
|
|
rm -rf $temp_restore_dir
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2016-07-09 12:15:41 +02:00
|
|
|
}
|
|
|
|
|
2016-07-06 15:55:09 +02:00
|
|
|
function backup_remote_emacs {
|
2016-08-29 11:48:49 +02:00
|
|
|
echo -n ''
|
2016-07-05 21:07:43 +02:00
|
|
|
}
|
|
|
|
|
2016-07-09 12:15:41 +02:00
|
|
|
function restore_remote_emacs {
|
2016-08-29 11:48:49 +02:00
|
|
|
echo -n ''
|
2016-07-09 12:15:41 +02:00
|
|
|
}
|
|
|
|
|
2016-07-05 21:07:43 +02:00
|
|
|
function remove_emacs {
|
2016-08-29 11:48:49 +02:00
|
|
|
apt-get -y remove --purge emacs24
|
|
|
|
update-alternatives --set editor /usr/bin/nano
|
|
|
|
sed -i '/install_emacs/d' $COMPLETION_FILE
|
2016-10-11 13:05:34 +02:00
|
|
|
|
|
|
|
# remove emacs as the mutt email editor
|
|
|
|
if [ -f /etc/Muttrc ]; then
|
|
|
|
if grep -q "set editor=" /etc/Muttrc; then
|
|
|
|
sed -i '/set editor=/d' /etc/Muttrc
|
|
|
|
fi
|
|
|
|
for d in /home/*/ ; do
|
|
|
|
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
|
|
|
|
if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
|
|
|
|
if [ -f /home/$USERNAME/.muttrc ]; then
|
|
|
|
if grep -q "set editor=" /home/$USERNAME/.muttrc; then
|
|
|
|
sed -i '/set editor=/d' /home/$USERNAME/.muttrc
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2016-07-05 21:07:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function install_emacs {
|
2016-10-11 13:05:34 +02:00
|
|
|
apt-get -y install emacs24
|
2016-08-29 11:48:49 +02:00
|
|
|
update-alternatives --set editor /usr/bin/emacs24
|
2016-07-03 17:13:34 +02:00
|
|
|
|
2016-08-29 11:48:49 +02:00
|
|
|
# A minimal emacs configuration
|
|
|
|
#echo -n "(add-to-list 'load-path " > /home/$MY_USERNAME/.emacs
|
|
|
|
#echo '"~/.emacs.d/")' >> /home/$MY_USERNAME/.emacs
|
|
|
|
#echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo $';; ===== Remove trailing whitepace ======================================' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo ";;(add-hook 'before-save-hook 'delete-trailing-whitespace)" >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo ';; Goto a line number with CTRL-l' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo -n '(global-set-key "\C-l" ' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo "'goto-line)" >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo $';; ===== Show line numbers ==============================================' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo "(add-hook 'find-file-hook (lambda () (linum-mode 1)))" >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo $';; ===== Enable line wrapping in org-mode ===============================' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo " (add-hook 'org-mode-hook" >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo " '(lambda ()" >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo " (visual-line-mode 1)))" >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo $';; ===== Enable shift select in org mode ================================' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '(setq org-support-shift-select t)' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo $';; ===== Set standard indent to 4 rather that 4 =========================' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '(setq standard-indent 4)' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '(setq-default tab-width 4)' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '(setq c-basic-offset 4)' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo $';; ===== Support Wheel Mouse Scrolling ==================================' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '(mouse-wheel-mode t)' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo $';; ===== Place Backup Files in Specific Directory =======================' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '(setq make-backup-files t)' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '(setq version-control t)' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo $';; ===== Make Text mode the default mode for new buffers ================' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo "(setq default-major-mode 'text-mode)" >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo $';; ===== Line length ====================================================' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '(setq-default fill-column 72)' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo $';; ===== Enable Line and Column Numbering ===============================' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '(line-number-mode 1)' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '(column-number-mode 1)' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo $';; ===== Turn on Auto Fill mode automatically in all modes ==============' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo ';; Auto-fill-mode the the automatic wrapping of lines and insertion of' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo ';; newlines when the cursor goes over the column limit.' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo ';; This should actually turn on auto-fill-mode by default in all major' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo ';; modes. The other way to do this is to turn on the fill for specific modes' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo ';; via hooks.' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '(setq auto-fill-mode 1)' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo $';; ===== Enable GPG encryption =========================================' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '' >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo "(require 'epa)" >> /home/$MY_USERNAME/.emacs
|
|
|
|
echo '(epa-file-enable)' >> /home/$MY_USERNAME/.emacs
|
|
|
|
cp /home/$MY_USERNAME/.emacs /root/.emacs
|
|
|
|
chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs
|
2016-10-11 13:05:34 +02:00
|
|
|
|
|
|
|
# add a mutt entry to use emacs to compose emails
|
|
|
|
if [ -f /etc/Muttrc ]; then
|
|
|
|
if ! grep -q "set editor=" /etc/Muttrc; then
|
|
|
|
echo 'set editor="emacs -q --load ~/.emacs-mutt"' >> /etc/Muttrc
|
|
|
|
else
|
|
|
|
sed -i 's|set editor=.*|set editor="emacs -q --load ~/.emacs-mutt"|g' /etc/Muttrc
|
|
|
|
fi
|
|
|
|
for d in /home/*/ ; do
|
|
|
|
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
|
|
|
|
if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
|
|
|
|
if [ -f /home/$USERNAME/.muttrc ]; then
|
|
|
|
if ! grep -q "set editor=" /home/$USERNAME/.muttrc; then
|
|
|
|
echo 'set editor="emacs -q --load ~/.emacs-mutt"' >> /home/$USERNAME/.muttrc
|
|
|
|
else
|
|
|
|
sed -i 's|set editor=.*|set editor="emacs -q --load ~/.emacs-mutt"|g' /home/$USERNAME/.muttrc
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# create an Emacs configuration specifically for use with Mutt, which
|
|
|
|
# has word wrap and spell checking on by default
|
|
|
|
if [ ! -f /home/$USERNAME/.emacs-mutt ]; then
|
|
|
|
echo "(add-hook 'before-save-hook 'delete-trailing-whitespace)" > /home/$USERNAME/.emacs-mutt
|
|
|
|
echo '(setq org-support-shift-select t)' >> /home/$USERNAME/.emacs-mutt
|
|
|
|
echo '(setq standard-indent 4)' >> /home/$USERNAME/.emacs-mutt
|
|
|
|
echo '(setq-default tab-width 4)' >> /home/$USERNAME/.emacs-mutt
|
|
|
|
echo '(setq c-basic-offset 4)' >> /home/$USERNAME/.emacs-mutt
|
|
|
|
echo '(mouse-wheel-mode t)' >> /home/$USERNAME/.emacs-mutt
|
|
|
|
echo '(setq make-backup-files t)' >> /home/$USERNAME/.emacs-mutt
|
|
|
|
echo '(setq version-control t)' >> /home/$USERNAME/.emacs-mutt
|
|
|
|
echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))' >> /home/$USERNAME/.emacs-mutt
|
|
|
|
echo "(setq default-major-mode 'text-mode)" >> /home/$USERNAME/.emacs-mutt
|
|
|
|
echo "(dolist (hook '(text-mode-hook))" >> /home/$USERNAME/.emacs-mutt
|
|
|
|
echo ' (add-hook hook (lambda () (flyspell-mode 1))))' >> /home/$USERNAME/.emacs-mutt
|
|
|
|
echo '(setq-default fill-column 72)' >> /home/$USERNAME/.emacs-mutt
|
|
|
|
echo '(setq auto-fill-mode 0)' >> /home/$USERNAME/.emacs-mutt
|
|
|
|
echo "(add-hook 'text-mode-hook 'turn-on-auto-fill)" >> /home/$USERNAME/.emacs-mutt
|
|
|
|
echo "(setq-default auto-fill-function 'do-auto-fill)" >> /home/$USERNAME/.emacs-mutt
|
|
|
|
chown $USERNAME:$USERNAME /home/$USERNAME/.emacs-mutt
|
|
|
|
|
|
|
|
# add the emacs mutt configuration to the user profile skeleton
|
|
|
|
if [ ! -f /etc/skel/.emacs-mutt ]; then
|
|
|
|
cp /home/$USERNAME/.emacs-mutt /etc/skel/.emacs-mutt
|
|
|
|
chown root:root /etc/skel/.emacs-mutt
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2016-10-10 20:11:33 +02:00
|
|
|
APP_INSTALLED=1
|
2016-07-03 17:13:34 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:05:34 +02:00
|
|
|
function install_interactive_emacs {
|
|
|
|
install_emacs
|
|
|
|
}
|
|
|
|
|
2016-07-03 17:13:34 +02:00
|
|
|
# NOTE: deliberately no exit 0
|