Skip to content

Instantly share code, notes, and snippets.

@someburner
Created September 24, 2017 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save someburner/373e05391cd4a707b896888029c8c028 to your computer and use it in GitHub Desktop.
Save someburner/373e05391cd4a707b896888029c8c028 to your computer and use it in GitHub Desktop.
Install script for binary version of laverna on linux, ubuntu
#!/bin/bash
## Notes:
## (1) written/tested on ubuntu 17 gnome, likely works for other versions
## (2) Assumes 'unzip' command available + Bash 4.x, dunno about others
## (3) Does not delete data dir by default, should be fine to re-use for updates
## (4) See bottom for uninstall. basically just removes stuff
## Usage:
## 1. Download somewhere, review/edit install options below
## 2. chmod +x laverna-ubuntu.sh
## 3. ./laverna-ubuntu.sh
#########################################
# Install options
#########################################
# change to ABSOLUTE path of wherever your zip is downloaded
LAVERNA_ZIP="/full/path/to/laverna-0.7.4-RC1-linux-x64.zip"
## version, used to name folder for extraction
LAVERNA_VERSION="0.7.4"
## install location (creates if necessary)
LAVERNA_DIR="$HOME/.laverna"
LINUX_APPS_DIR="$HOME/.local/share/applications"
## data dir to use (comment out to not use)
LAVERNA_DATA_DIR="$LAVERNA_DIR/data"
LAVERNA_INSTALL_DIR="$LAVERNA_DIR/laverna-$LAVERNA_VERSION"
## laverna icon - update if needed
LAVERNA_ICON="$LAVERNA_INSTALL_DIR/resources/app/dist/images/icon/icon-48x48.png"
#########################################
# Utilities
#########################################
should_exit () { if ! [[ $1 -eq 0 ]]; then echo "Non-zero exit code: $1"; exit $1; fi }
folder_exists() { printf "$1.."; if [ -d "$1" ]; then echo "Exists"; return 0; else echo "DNE"; return 1; fi }
file_exists() { printf "$1.."; if [ -f "$1" ]; then echo "Exists"; return 0; else echo "DNE"; return 1; fi }
#########################################
# a few checks, setup
#########################################
# Check zip exists - exit if fail
file_exists "$LAVERNA_ZIP";
should_exit "$?";
# make dir - exit if fail
mkdir -p $LAVERNA_DIR;
folder_exists "$LAVERNA_DIR";
should_exit "$?";
# generate command string
LAVERNA_EXEC="$LAVERNA_INSTALL_DIR/laverna"
# Append data dir to cmd if its set
if [ -n "$LAVERNA_DATA_DIR" ]; then
mkdir -p $LAVERNA_DATA_DIR;
LAVERNA_EXEC+=" --data-dir=$LAVERNA_DATA_DIR";
fi
#########################################
# methods
#########################################
setupDirs() {
# Create dirs + extract
echo "Setting up directories..";
rm -rf $LAVERNA_INSTALL_DIR;
mkdir -p $LAVERNA_INSTALL_DIR;
echo "unzipping $LAVERNA_ZIP --> $LAVERNA_INSTALL_DIR";
unzip -q "$LAVERNA_ZIP" -d "$LAVERNA_INSTALL_DIR";
}
createExecScript() {
# create exec script
echo "Generating .sh exec script ($LAVERNA_DIR/laverna.sh)";
rm -f $LAVERNA_DIR/laverna.sh;
touch $LAVERNA_DIR/laverna.sh;
echo '#!/bin/bash' >> $LAVERNA_DIR/laverna.sh;
echo "$LAVERNA_EXEC" >> $LAVERNA_DIR/laverna.sh;
chmod +x $LAVERNA_DIR/laverna.sh;
}
createDesktopEntry() {
echo "Creating desktop entry:";
echo "$LINUX_APPS_DIR/laverna.desktop";
# Create desktop icon
rm -f $LINUX_APPS_DIR/laverna.desktop;
touch $LINUX_APPS_DIR/laverna.desktop;
# Escaped cat for entry info
cat > $LINUX_APPS_DIR/laverna.desktop <<EOF
[Desktop Entry]
Version=$LAVERNA_VERSION
Name=laverna
GenericName=Laverna
Exec=$LAVERNA_DIR/laverna.sh
Terminal=false
Icon=$LAVERNA_ICON
Type=Application
Categories=Application
Comment=Laverna notes
Keywords=laverna;notes;text;markdown;editor;
EOF
chmod +x $LINUX_APPS_DIR/laverna.desktop;
}
uninstall() {
local RM_DATA_DIR=$1;
# remove desktop entry
rm -f $LINUX_APPS_DIR/laverna.desktop;
if [ $RM_DATA_DIR -eq 1 ]; then
# remove the whole thing
rm -rf $LAVERNA_DIR;
else
# just remove install dir + shell script
rm -rf $LAVERNA_INSTALL_DIR;
rm -f $LAVERNA_DIR/laverna.sh;
fi
}
#########################################
# Runner
#########################################
setupDirs;
createExecScript;
createDesktopEntry;
# uncomment to remove most stuff, but not data dir
## uninstall "0";
# uncomment to remove data dir too
## uninstall "1";
echo "all done"
### end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment