summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /scripts
new repository
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build-emacs-from-src.sh102
-rwxr-xr-xscripts/create-elpa-mirrors.sh48
-rwxr-xr-xscripts/profile-dotemacs.sh20
-rwxr-xr-xscripts/reset.sh32
-rwxr-xr-xscripts/setup-email.sh51
5 files changed, 253 insertions, 0 deletions
diff --git a/scripts/build-emacs-from-src.sh b/scripts/build-emacs-from-src.sh
new file mode 100755
index 00000000..a2272838
--- /dev/null
+++ b/scripts/build-emacs-from-src.sh
@@ -0,0 +1,102 @@
+#!/usr/bin/env bash
+# Craig Jennings <c@cjennings.net>
+# Builds Emacs from source using the variables below.
+
+# - creates the directory if needed
+# - uninstalls emacs if it exists
+# - pulls latest source from repo below
+# unless "latest" is passed as parameter
+# - checks out the tag below
+# - uses all available processors when compiling
+
+# NOTES:
+# building xwidgets is broken on Linux in 29/30 tags
+# ./configure --with-xwidgets \
+
+# ...and I'm avoiding native compilation at the moment
+#./configure --with-native-compilation \
+
+set -e
+
+# Review These Variables
+
+src_dir="$HOME/code/emacs"
+emacs_repo="https://github.com/mirrors/emacs.git"
+emacs_tag="emacs-29.1"
+logfile="$HOME/emacs_build.log"
+
+# Function to remove + recreate directory, and clone source
+nuke_and_clone () {
+ cd "$HOME"
+ if [ -d "$src_dir" ]; then
+ printf "...removing directory %s\n\n" "$src_dir"
+ rm -rf "$src_dir" >> "$logfile" 2>&1
+ fi
+
+ printf "...creating directory %s\n" "$src_dir"
+ mkdir -p "$src_dir" >> "$logfile" 2>&1
+ printf "...cloning source files\n"
+ git clone "$emacs_repo" "$src_dir" >> "$logfile" 2>&1
+}
+
+# Script Execution Begins Here
+
+printf "\n\n### BUILDING EMACS FROM SOURCE ###\n\n" > "$logfile"
+
+printf "...checking directory: %s\n" "$src_dir" | tee -a "$logfile"
+
+# if the source directory already exists
+if [ -d "$src_dir" ]; then
+ cd "$src_dir"
+
+ # if emacs was previously built, uninstall it.
+ {
+ if [ -n "$(which emacs)" ]; then
+ printf "...uninstalling previous build\n"
+ sudo make uninstall
+ fi
+ } >> "$logfile" 2>&1
+
+ printf "...cleaning repo\n" | tee -a "$logfile"
+ make clean >> "$logfile" 2>&1
+
+ if [[ -n $(git status --porcelain) ]]; then
+ printf "...repository is dirty. recreating.\n" | tee -a "$logfile"
+ nuke_and_clone
+ else
+ printf "...pulling latest source files\n" | tee -a "$logfile"
+ git pull >> "$logfile" 2>&1
+ fi
+else
+ nuke_and_clone
+fi
+
+if [ ! $1 == "latest" ]; then
+ printf "...checking out tag: %s\n" "$emacs_tag" | tee -a "$logfile"
+ git checkout "$emacs_tag" >> "$logfile" 3>&1
+else
+ printf "...keeping source at latest commit\n" | tee -a "$logfile"
+fi
+
+printf "...building config script\n" | tee -a "$logfile"
+./autogen.sh >> "$logfile" 2>&1
+
+printf "...configuring build\n" | tee -a "$logfile"
+./configure --with-json \
+ --with-x-toolkit=lucid \
+ --with-modules \
+ --with-mailutils \
+ --with-imagemagick\
+ CFLAGS='-O2 -march=native' >> "$logfile" 2>&1
+
+# compile with all available cores
+printf "...compiling Emacs\n" | tee -a "$logfile"
+make -j$(nproc) >> "$logfile" 2>&1
+
+printf "...installing Emacs\n" | tee -a "$logfile"
+sudo make install >> "$logfile" 2>&1
+make clean >> "$logfile" 2>&1
+cd "$HOME"
+
+printf "...done\n" | tee -a "$logfile"
+printf "Please review log at: %s\n" "$logfile"
diff --git a/scripts/create-elpa-mirrors.sh b/scripts/create-elpa-mirrors.sh
new file mode 100755
index 00000000..58d02e07
--- /dev/null
+++ b/scripts/create-elpa-mirrors.sh
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+# Craig Jennings <c@cjennings.net>
+
+# Clones the Elpa mirrors repository to a local directory
+
+ELPA_MIRRORS_REPO="https://github.com/d12frosted/elpa-mirror.git"
+ELPA_MIRRORS_DIR=".elpa-mirrors"
+
+
+# Identify EMACS_CONFIG location
+if [ $# -eq 1 ] && [ -d "$1" ]; then
+ EMACS_CONFIG="$1"
+elif [ -d "$HOME/.emacs.d" ]; then
+ EMACS_CONFIG="$HOME/.emacs.d"
+elif [ -d "$HOME/.config/emacs" ]; then
+ EMACS_CONFIG="$HOME/.config/emacs"
+else
+ echo
+ "Unable to locate Emacs configuration directory. Please check that your Emacs
+ configuration is in ~/.emacs.d/ or ~/.config/emacs/. Alternatively, you can
+ specify a different directory by passing the directory path as an argument."
+ exit 1
+fi
+
+# Check if git is installed
+if ! command -v git &> /dev/null; then
+ echo "git was not found. Please install git first."
+ exit 1
+fi
+
+# Check if the .elpa-mirrors already exists
+if [ -d "$EMACS_CONFIG/$ELPA_MIRRORS_DIR" ]; then
+ echo "The directory $EMACS_CONFIG/$ELPA_MIRRORS_DIR already exists. Please remove or rename this directory and run the script again."
+ exit 1
+fi
+
+# Confirm directory selection
+read -p "The following directory has been selected for cloning ELPA mirror repo: $EMACS_CONFIG. Continue? [y/N] " REPLY
+if ! [[ $REPLY =~ ^[Yy]$ ]]; then
+ echo "Operation cancelled by user."
+ exit 0
+fi
+
+# Proceed with cloning
+git clone --depth 1 "$ELPA_MIRRORS_REPO" "$EMACS_CONFIG/$ELPA_MIRRORS_DIR"
+
+# Display completion notification with location of mirrors.
+printf "\n\nCompleted. Elpa mirrors cloned to %s\n\n" "$EMACS_CONFIG/$ELPA_MIRRORS_DIR"
diff --git a/scripts/profile-dotemacs.sh b/scripts/profile-dotemacs.sh
new file mode 100755
index 00000000..b31d078b
--- /dev/null
+++ b/scripts/profile-dotemacs.sh
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+
+# profile-dotemacs.sh
+# Craig Jennings <c@cjennings.net>
+# a convenience script to load an emacs-lisp file which will
+# startup emacs (with or without an early-init) and provide
+# benchmark information on the Emacs config.
+
+EMACS_HOME="$HOME/.emacs.d/"
+EARLY_INIT_FILE="$EMACS_HOME/early-init.el"
+PROFILE_FILE="$EMACS_HOME/custom/profile-dotemacs.el"
+
+if [ -f "$EARLY_INIT_FILE" ]
+then
+ emacs -Q --load $PROFILE_FILE --eval "(progn (load-file \"~/.emacs.d/early-init.el\") (profile-dotemacs))"
+else
+ echo "No early init found. Proceeding to benchmark init.el."
+ emacs -Q --load $PROFILE_FILE --eval "(profile-dotemacs)"
+fi
+
diff --git a/scripts/reset.sh b/scripts/reset.sh
new file mode 100755
index 00000000..efa15d76
--- /dev/null
+++ b/scripts/reset.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# script for Emacs config testing
+# - clears out all but necessary init/config files
+# - removes native ad bytecode files.
+rm -rf ~/.emacs.d/.cache/
+rm -rf ~/.emacs.d/auto-save-list/
+rm -rf ~/.emacs.d/backups/
+rm -rf ~/.emacs.d/crossword/
+rm -rf ~/.emacs.d/dirvish/
+rm -rf ~/.emacs.d/eln-cache/
+rm -rf ~/.emacs.d/elpa/
+rm -rf ~/.emacs.d/emojis/
+rm -rf ~/.emacs.d/erc/
+rm -rf ~/.emacs.d/eshell/
+rm -rf ~/.emacs.d/localrepo/
+rm -rf ~/.emacs.d/nov-places
+rm -rf ~/.emacs.d/nov-places/
+rm -rf ~/.emacs.d/quelpa/
+rm -rf ~/.emacs.d/transient/
+rm -rf ~/.emacs.d/tree-sitter/
+rm -rf ~/.emacs.d/url/
+rm ~/.emacs.d/.lsp-session*
+rm ~/.emacs.d/.org-id-locations
+rm ~/.emacs.d/.pdf-view-restore
+rm ~/.emacs.d/org-roam.db
+rm ~/.emacs.d/projectile-bookmarks.eld
+rm ~/.emacs.d/projects
+rm ~/.emacs.d/recentf
+rm ~/.emacs.d/tramp-connection-history
+rm ~/sync/org/emacs-theme.persist
+find ~/.emacs.d -name "*.eln" -type f -delete
+find ~/.emacs.d -name "*.elc" -type f -delete
diff --git a/scripts/setup-email.sh b/scripts/setup-email.sh
new file mode 100755
index 00000000..1f0d5bad
--- /dev/null
+++ b/scripts/setup-email.sh
@@ -0,0 +1,51 @@
+#!/usr/bin/env bash
+# ------------------------------ Notes ------------------------------
+# Craig Jennings <c@cjennings.net>
+#
+# this mu4e mail setup script is particular to my own setup
+# ===== this will not work for you =====
+
+MBSYNC=/usr/bin/mbsync
+MBSYNCRC=~/.mbsyncrc
+MU4E_DIR=/usr/share/emacs/site-lisp/mu4e/
+MSMTP=/usr/bin/msmtp
+MSMTPRC=~/.msmtprc
+MU=/usr/bin/mu
+GMAIL=~/.mail/gmail
+CMAIL=~/.mail/cmail
+
+# ----------------------- Preliminary Checks ----------------------
+# is mbsync installed?
+if ! [ -f $MBSYNC ]; then echo "mbsync not installed at $MBSYNC. Install package 'isync' to continue"; exit 1; fi
+if ! [ -f $MU ]; then echo "mu not installed at $MU. Install package 'mu' to continue"; exit 1; fi
+if ! [ -d $MU4E ]; then echo "mu4e elisp files not at $MU4E_DIR. Did you install the 'mu' package?"; exit 1; fi
+
+# does .mbsyncrc exist?
+if ! [ -f $MBSYNCRC ]; then echo "necessary file .mbsyncrc not at $MBSYNCRC"; exit 1; fi
+
+# is msmtp installed?
+if ! [ -f $MSMTP ]; then echo "msmtp not installed at $MSMTP. Install package 'msmtp and msmtp-mta' to continue"; exit 1; fi
+
+# does .msmtprc exist
+if ! [ -f $MSMPTRC ]; then echo "necessary file .msmtprc not at $MBSYNCRC"; exit 1; fi
+
+# if mail directories don't exist, create them
+if ! [ -f $GMAIL ]; then echo "creating gmail directory" && mkdir -p $GMAIL; fi
+if ! [ -f $CMAIL ]; then echo "creating cmail directory" && mkdir -p $CMAIL; fi
+
+# -------------------------- Initial Sync -------------------------
+
+# sync
+echo "syncing email... Note: You will be asked for your password."
+$MBSYNC -aV
+
+# init
+echo "running mu init.."
+$MU init --maildir=~/.mail --my-address=craigmartinjennings@gmail.com --my-address=c@cjennings.net
+
+# index
+echo "running mu index..."
+$MU index
+
+# report completion
+echo "" && echo "Mu4e mail setup script completed." && echo "" && echo ""