r0adkll
5/8/2015 - 8:46 PM

52inc lolcommits install and configure script

52inc lolcommits install and configure script

#!/bin/bash

# Post-Commit hook text
post_commit_hook_base='#!/bin/sh
### lolcommits hook (begin) ###
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export PATH="/usr/bin:/usr/local/bin:$PATH"\n'
post_commit_hook_suffix='\n###  lolcommits hook (end)  ###'
lolcommits='lolcommits --capture --fork'
animate=' --animate='
post_commit_hook_file="$HOME/.git_template/hooks/post-commit"

echo ""
echo "###############################################"
echo "#        You are now installing 52inc         #"
echo "#               lolcommit setup               #"
echo "#                                             #"
echo "#                  ENJOY :D                   #"
echo "###############################################"
echo ""

# Here we go.. ask for the administrator password upfront and run a
# keep-alive to update existing `sudo` time stamp until script has finished
sudo -v
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &

# Check for Homebrew,
# Install if we don't have it
if test ! $(which brew); then
  echo "Installing homebrew..."
  ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi

# Update homebrew recipes
brew update

# Install imagemagick
echo "Installing Imagemagick..."
brew install imagemagick

# Install FFMpeg
echo "Installing ffmpeg..."
brew install ffmpeg

# Install LOLCommits: NEEDS TO BE RAN AS SUDO
if test ! $(which lolcommits); then
  echo "Installing lolcommits..."
  sudo gem install lolcommits
fi

echo "Configuring Git..."

# Create GIT Template directory
mkdir -p ~/.git_template/hooks
git config --global init.templatedir '~/.git_template'

# Get user's animation count in seconds
echo ""
echo "Enter the duration of the animation (<= 0 for images only): "
read input
if [ $input -eq $input 2>/dev/null ]
then
     githook=$post_commit_hook_base$lolcommits

     if [ $input -gt 0 ]
     then
          githook+=$animate$input
     fi

     githook+=$post_commit_hook_suffix

     echo -e "$githook" > $post_commit_hook_file

     echo "Git hook post-commit template created @ $post_commit_hook_file"

else
  echo "Error: Invalid animation duration"
  exit 1
fi

################################################################################
# Save plugin setup script to a runnable directory, then export it onto the path
################################################################################

# Now we want to generate and save the plugin setup script to the .lolcommits dir
# and export an alias/path

# Set the lolcommit dir
script_dir="$HOME/bin"

# Create directory if it doesn't exist
mkdir -p $script_dir

# Set the lol52 script filename
lol52=$script_dir'/lol52.sh'

# Compose the 52inc Lolcommits plugin configuration script
script_text="#!/bin/bash

# The webhook URL to configure with
webhook_url='http://r0adkll.com:8321/lolcommits/webhook'

# Prepare uploldz configuration
################################################################################

# Build the configuration text to write
uploldz_config=\"---
uploldz:
  enabled: true
  endpoint: \$webhook_url
  optional_key: \"

# Get user's animation count in seconds
echo \"\"
echo \"Enter the name of your repository: \"
read input

# Concatenate input to config string for output
config=\$uploldz_config\$input
config_file_name='config.yml'

# Re-initialize Git on this repo and setup lolcommits
################################################################################

echo \"Enabling lolcommits...\"
lolcommits --enable

echo \"Re-configuring Git Hook...\"
cp -f ~/.git_template/hooks/post-commit .git/hooks/post-commit

# Calculate the location of the configuration
################################################################################

# Get the name of the working directory, ideally this script should be executed
# in the directory of the project you are trying to setup
project=\${PWD##*/}

# Concatentate the lol project directory
lolcommit_dir=\"\$HOME/.lolcommits/\$project\"

# Create the directory
mkdir -p \$lolcommit_dir

# Now write the configuration to the config.yml file
config_file=\$lolcommit_dir'/'\$config_file_name

# Write the uploldz configuration to the lolcommits directory

echo \"\$config\" > \$config_file

echo \"Uploldz configuration created!\""

# Write script to file
echo -e "$script_text" > $lol52

# Make executable
chmod a+x $lol52

# Now add to path and update bash profile appending your bash profile
echo "alias lol52='sh $HOME/bin/lol52.sh'" >> ~/.bash_profile

# Now reload the bash profile
source ~/.bash_profile

echo ""
echo "#########################################################################"
echo "#                                                                       #"
echo "#   52inc lolcommit install & configuration complete!                   #"
echo "#                                                                       #"
echo "#########################################################################"
echo ""
echo "To configure your projects to upload to the 52inc lolcommit service"
echo "please execute 'lol52' in the directory of your project"
echo ""

# Fin
exit