Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to set up the Electric Book tools on a USB drive running Ubuntu 18.04
#!/bin/bash
# This script sets up the Electric Book tools on an Ubuntu 18.04 USB drive.
# It assumes a fresh Ubuntu 18.04 install. Anywhere else, use at your own risk.
# Tested on a 32GB Sandisk Cruzer Blade drive.
#
# Before using this script, to create a bootable USB drive:
# - On Windows, use Rufus, but changes to the USB will not be saved:
# https://tutorials.ubuntu.com/tutorial/tutorial-create-a-usb-stick-on-windows
# - On Ubuntu, optionally with the ability to save ('persistence'), use mkusb:
# https://help.ubuntu.com/community/mkusb
# https://help.ubuntu.com/community/mkusb/persistent
#
# Once you have created your USB drive:
# 1. Search online to find out how to boot from USB on your particular machine.
# 2. Boot from the USB drive, then run this script from the Ubuntu Terminal. To do this:
# a. Connect to WIFI, open Firefox, and go to http://bit.ly/ebw-usb-setup to copy the text of this script.
# b. Open Text Editor ('gedit'), paste this script, and save to the home directory as setup.sh.
# c. To allow the script to run, open Terminal and enter: chmod +x setup.sh
# d. To run the script, in Terminal enter: ./setup.sh
# If asked anything by the install process, accept the defaults.
# 3. If everything installs correctly, the Electric Book tools are ready to use.
# User guidance
echo 'This process will set up the Electric Book workflow tools on Ubuntu.'
echo 'This may take a while. You should get some tea.'
# Hide 'Install Ubuntu' icons
sudo mkdir /usr/share/applications/launcher_backup
sudo mv /usr/share/applications/ubiquity.desktop /usr/share/applications/launcher_backup/
sudo mv /home/ubuntu/Desktop/ubiquity.desktop /usr/share/applications/launcher_backup/
# Get user info for Git config
echo '------------------------------------'
echo 'To configure Git version control, we need your name and email address.'
read -p "Enter your full name: " name
read -p "Enter your email address: " email
# Get user to set folder name for new project
echo '------------------------------------'
echo 'We will create a new Electric Book project to work in.'
read -p "Folder name for new project (no spaces or punctuation): " projectFolder
if [ "$projectFolder" == "" ]; then
echo 'Using "new-electric-book" as the folder name.'
projectFolder='new-electric-book'
fi
# Update apt repository index
echo '------------------------------------'
echo 'Updating packages...'
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe" -y
sudo apt update -y
# Set up Ruby and dependencies for native gems
echo '------------------------------------'
echo 'Installing Ruby and its dependencies...'
sudo apt install ruby -y
sudo apt install ruby-dev -y
sudo apt install make -y
sudo apt install gcc -y
sudo apt install build-essential -y
# Update gems
echo '------------------------------------'
echo 'Updating Ruby gems...'
sudo gem update --system --no-ri --no-rdoc
# Install Jekyll
echo '------------------------------------'
echo 'Installing Jekyll...'
sudo gem install jekyll
# Install Bundler
echo '------------------------------------'
echo 'Installing Bundler...'
sudo gem install bundler
# Install and configure Git and Git GUI
# (Using specific PPA for latest version)
echo '------------------------------------'
echo 'Installing Git and gitg (a Git GUI)...'
sudo apt install git -y
sudo apt install gitg -y
git config --global user.name $name
git config --global user.email $email
# Install Prince
echo '------------------------------------'
echo 'Installing PrinceXML...'
sudo apt install gdebi -y
wget https://www.princexml.com/download/prince_11.4-1_ubuntu18.04_amd64.deb
sudo gdebi prince_11.4-1_ubuntu18.04_amd64.deb --non-interactive
# Install PhantomJS
# (Adapted from https://www.vultr.com/docs/how-to-install-phantomjs-on-ubuntu-16-04
# Another option: https://gist.github.com/telbiyski/ec56a92d7114b8631c906c18064ce620)
echo '------------------------------------'
echo 'Installing PhantomJS...'
sudo apt install chrpath libssl-dev libxft-dev libfreetype6-dev libfreetype6 libfontconfig1-dev libfontconfig1 -y
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
sudo tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /usr/local/share/
sudo ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/
# Install Pandoc
echo '------------------------------------'
echo 'Installing Pandoc...'
wget https://github.com/jgm/pandoc/releases/download/2.5/pandoc-2.5-1-amd64.deb
sudo dpkg -i pandoc-2.5-1-amd64.deb
# Install Node
echo '------------------------------------'
echo 'Installing Node...'
sudo snap install node --classic --channel=10
# Install Gulp
echo '------------------------------------'
echo 'Installing Gulp...'
sudo npm install --global gulp-cli
# Install GraphicsMagick
# (Thanks https://gist.github.com/witooh/089eeac4165dfb5ccf3d)
echo '------------------------------------'
echo 'Installing GraphicsMagick...'
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:rwky/graphicsmagick -y
sudo apt update
sudo apt install graphicsmagick -y
# Install VS Code
echo '------------------------------------'
echo 'Installing VS Code...'
sudo snap install vscode --classic
# Install better PDF viewer and make it default
# (Because sometimes evince has 'permission denied' issues.)
echo '------------------------------------'
echo 'Installing xPDF...'
sudo apt install xpdf -y
sudo sed -i '/pdf/s/evince./xpdf./g' /etc/gnome/defaults.list
# Install an epub reader
echo '------------------------------------'
echo 'Installing Calibre...'
wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin
# Clone the Electric Book template
echo '------------------------------------'
echo 'Cloning the electric-book template repository...'
git clone https://github.com/electricbookworks/electric-book.git
# Allow run-linux.sh to execute
echo '------------------------------------'
echo 'Giving the Electric Book run script permission to execute...'
cd electric-book
chmod +x run-linux.sh
cd ..
# Install EB template dependencies
echo '------------------------------------'
echo 'Installing the Electric Book template dependencies...'
cd electric-book
bundle update
bundle install
npm install
cd ..
# Rename template and reset git history for a new project
echo '------------------------------------'
echo 'Creating a new, blank project from the template...'
mv electric-book $projectFolder
cd $projectFolder
rm -rf .git
git init
git add .
git commit -m "New project created"
cd ..
# Check installations
echo '------------------------------------'
echo 'Done. Listing installed versions:'
echo '------------------------------------'
echo 'Ruby version installed?' && ruby --version
echo '------------------------------------'
echo 'Jekyll version installed?' && jekyll --version
echo '------------------------------------'
echo 'Bundler version installed?' && bundler --version
echo '------------------------------------'
echo 'Git version installed?' && git --version
git config --list
echo '------------------------------------'
echo 'gitg version installed?' && gitg --version
echo '------------------------------------'
echo 'PrinceXML version installed?' && prince --version
echo '------------------------------------'
echo 'PhantomJS version installed?' && phantomjs --version
echo '------------------------------------'
echo 'Pandoc version installed?' && pandoc --version
echo '------------------------------------'
echo 'Node version installed?' && node --version
echo '------------------------------------'
echo 'Gulp version installed?' && gulp --version
echo '------------------------------------'
echo 'GraphicsMagick version installed?' && gm -version
echo '------------------------------------'
echo 'VS Code version installed?' && vscode --version
echo '------------------------------------'
echo 'XPDF version installed?' && xpdf -v
echo '------------------------------------'
echo 'Calibre version installed?' && calibre --version
installError=0
function isInstalled {
if hash $1 2>/dev/null; then
echo "$1 is installed."
else
echo "$1 is not installed, sorry."
installError=1
fi
}
# Check that everything is installed
echo '------------------------------------'
echo 'Done. Checking installs:'
isInstalled ruby
isInstalled jekyll
isInstalled bundler
isInstalled git
isInstalled gitg
isInstalled prince
isInstalled phantomjs
isInstalled pandoc
isInstalled node
isInstalled gulp
isInstalled gm
isInstalled vscode
isInstalled xpdf
isInstalled calibre
if [ $installError == 1 ]; then
echo '------------------------------------'
echo 'There were errors installing tools, sorry.'
echo 'Please check the logs above to find what went wrong.'
else
echo '------------------------------------'
echo 'Everything is installed, the Electric Book tools are ready to use.'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.