Skip to content

Instantly share code, notes, and snippets.

@jamesdlacroix
Last active June 11, 2018 19:59
Show Gist options
  • Save jamesdlacroix/02c0ec5c42750bfad8d9a88c8e1faf7f to your computer and use it in GitHub Desktop.
Save jamesdlacroix/02c0ec5c42750bfad8d9a88c8e1faf7f to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
establishDirectories () {
# Create templates directory if it does not exist
mkdir -p "$SKETCH_TEMPLATES"
# Create plugins directory if it does not exist
mkdir -p "$SKETCH_PLUGINS"
}
clean () {
# Use mv to test and then switch to rm -rf when directories are correct
if [ -e "$FEATHER_DESTINATION" ]
then
# mv "$FEATHER_DESTINATION" "$TRASH"
rm -rf "$FEATHER_DESTINATION"
fi
if [ -e "$HORIZON_DESTINATION" ]
then
# mv "$HORIZON_DESTINATION" "$TRASH"
rm -rf "$HORIZON_DESTINATION"
fi
}
install () {
# Symlink Feather templates
ln -s "$FEATHER_SOURCE" "$FEATHER_DESTINATION"
# Symlink Horizon templates
ln -s "$HORIZON_SOURCE" "$HORIZON_DESTINATION"
# Copy Paddy plugin
/bin/cp -rf "$PLUGIN_SOURCE/Paddy.sketchplugin" "$SKETCH_PLUGINS"
# Copy Sketch Palettes plugin
/bin/cp -rf "$PLUGIN_SOURCE/Sketch Palettes.sketchplugin" "$SKETCH_PLUGINS"
# Copy SendToSlack plugin
/bin/cp -rf "$PLUGIN_SOURCE/SendToSlack.sketchplugin" "$SKETCH_PLUGINS"
# Copy color palette to desktop
/bin/cp -rf "$COLOR_PALETTE_SOURCE" "$DESKTOP"
# Copy icon fonts
/bin/cp -rf "$EDGE_ICONS_SOURCE"/*.ttf "$FONTS_DESTINATION"
}
cleanInstall () {
# Set Source Variables
DESIGN_PATH=$1
FEATHER_SOURCE=$DESIGN_PATH/Feather
HORIZON_SOURCE=$DESIGN_PATH/Horizon
PLUGIN_SOURCE=$DESIGN_PATH/Plugins
ICON_SOURCE=$DESIGN_PATH/Tools/"Install Script"/Icon.png
COLOR_PALETTE_SOURCE=$DESIGN_PATH/Colors/twittercolors.sketchpalette
EDGE_ICONS_SOURCE=$DESIGN_PATH/Fonts/"Edge Icons"
# Set Destination Variables
SKETCH_TEMPLATES=$HOME/Library/"Application Support"/com.bohemiancoding.sketch3/Templates
SKETCH_PLUGINS=$HOME/Library/"Application Support"/com.bohemiancoding.sketch3/Plugins
FEATHER_DESTINATION=$SKETCH_TEMPLATES/Feather
HORIZON_DESTINATION=$SKETCH_TEMPLATES/Horizon
FONTS_DESTINATION=$HOME/Library/Fonts
DESKTOP=$HOME/Desktop
TRASH=$HOME/.Trash
# Set messaging
SUCCESS_TITLE="🤘 You did it!"
SUCCESS_MESSAGE="Twitter design assets have been successfully installed."
# Make sure directories exist
establishDirectories
# Clean previous installations
clean
# Install the assets
install
# Open Font Book to recognize new fonts
open -a "Font Book"
# Success Message
terminal-notifier -title "$SUCCESS_TITLE" -message "$SUCCESS_MESSAGE" -appIcon "$ICON_SOURCE"
echo "$SUCCESS_TITLE"
echo "$SUCCESS_MESSAGE"
exit
}
checkCleanInstall () {
# Set variables
GOOGLE_DRIVE_FILE_STREAM_LOCATION="/Volumes/GoogleDrive/My Drive"
GOOGLE_DRIVE_LOCATION=$HOME/"Google Drive"
DIRECTORY_FAIL_TITLE="🤔 Hmm…It appears that you haven't added the assets to your drive."
DIRECTORY_FAIL_MESSAGE="Make sure to add the .Design directory to your drive."
DIRECTORY_FAIL_URL="https://drive.google.com/open?id=0B9fABTNKWq4TRTFGZkhYcTFkMlk"
SYNC_FAIL_TITLE="🤔 Hmm…It appears that you haven't installed Google Drive File Stream."
SYNC_FAIL_MESSAGE="Install Google Drive File Stream and add the .Design directory to your drive."
SYNC_FAIL_URL="https://dl.google.com/drive-file-stream/googledrivefilestream.dmg"
# Check to see if .Design directory exists in Google Drive File Stream
if [ -e "$GOOGLE_DRIVE_FILE_STREAM_LOCATION" ] && [ -e "$GOOGLE_DRIVE_FILE_STREAM_LOCATION/.Design" ];
then
# .Design directory exists in Google Drive File Stream, proceed with install
cleanInstall "$GOOGLE_DRIVE_FILE_STREAM_LOCATION/.Design"
# Check to see if .Design directory exists in Google Backup & Sync
elif [ -e "$GOOGLE_DRIVE_LOCATION" ] && [ -e "$GOOGLE_DRIVE_LOCATION/.Design" ];
then
# .Design directory exists in Google Backup & Sync, proceed with install
cleanInstall "$GOOGLE_DRIVE_LOCATION/.Design";
elif [ -e "$GOOGLE_DRIVE_FILE_STREAM_LOCATION" ] || [ -e "$GOOGLE_DRIVE_LOCATION" ];
then
terminal-notifier -title "$DIRECTORY_FAIL_TITLE" -message "$DIRECTORY_FAIL_MESSAGE" -appIcon "$ICON_SOURCE" -timeout "30" -open "$DIRECTORY_FAIL_URL"
echo "$DIRECTORY_FAIL_TITLE"
echo "$DIRECTORY_FAIL_MESSAGE"
echo "$DIRECTORY_FAIL_URL"
else
terminal-notifier -title "$SYNC_FAIL_TITLE" -message "$SYNC_FAIL_MESSAGE" -appIcon "$ICON_SOURCE" -timeout "30" -open "https://dl.google.com/drive-file-stream/googledrivefilestream.dmg"
echo "$SYNC_FAIL_TITLE"
echo "$SYNC_FAIL_MESSAGE"
echo "Google Drive File Stream: $SYNC_FAIL_URL"
echo ".Design Directory: $DIRECTORY_FAIL_URL"
fi
}
checkCleanInstall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment