kicad/scripts/kicad-install.sh

281 lines
8.1 KiB
Bash
Raw Normal View History

#!/bin/bash
# Install KiCad from source onto either:
# -> a Ubuntu/Debian/Mint or
# -> a Red Hat
# compatible linux system.
#
# The "install_prerequisites" step is the only "distro dependent" one. That step could be modified
# for other linux distros.
#
# There are 3 package groups in a KiCad install:
# 1) Compiled source code in the form of executable programs.
# 2) User manuals and other documentation typically as *.pdf files.
# 3) a) Schematic parts, b) layout footprints, and c) 3D models for footprints.
#
# To achieve 1) source is checked out from its repo and compiled by this script then executables
# are installed using CMake.
# To achieve 2) documentation is checked out from its repo and installed using CMake.
# TO achieve 3a) and 3c) they are checked out from their repos and installed using CMake.
# To achieve 3b) a global fp-lib-table is put into your home directory which points to
# http://github.com/KiCad. No actual footprints are installed locally, internet access is used
# during program operation to fetch footprints from github as if it was a remote drive in the cloud.
# If you want to install those same KiCad footprints locally, you may run a separate script
# named library-repos-install.sh found in this same directory. That script requires that "git" be on
# your system whereas this script does not. The footprints require some means to download them and
# bzr-git seems not up to the task. wget or curl would also work.
2013-10-24 13:57:01 +00:00
# Set where the 3 source trees will go, use a full path
WORKING_TREES=~/kicad_sources
# CMake Options
OPTS="$OPTS -DCMAKE_BUILD_TYPE=Release"
OPTS="$OPTS -DUSE_FP_LIB_TABLE=ON"
OPTS="$OPTS -DBUILD_GITHUB_PLUGIN=ON"
# Python scripting, uncomment to enable
#OPTS="$OPTS -DKICAD_SCRIPTING=ON -DKICAD_SCRIPTING_MODULES=ON -DKICAD_SCRIPTING_WXPYTHON=ON"
LIB_REPO=~kicad-testing-committers/kicad/library
usage()
{
echo ""
echo " usage:"
echo ""
echo "./kicad-install.sh <cmd>"
echo " where <cmd> is one of:"
echo " --install-or-update (does full installation or update.)"
echo " --remove-sources (removes source trees for another attempt.)"
echo " --uninstall-libraries (removes KiCad supplied libraries.)"
echo " --uninstall-kicad (uninstalls all of KiCad but leaves source trees.)"
echo ""
echo "example:"
echo ' $ ./kicad-install.sh --install-or-update'
}
install_prerequisites()
{
# Find a package manager, PM
PM=$( command -v yum || command -v apt-get )
# assume all these Debian, Mint, Ubuntu systems have same prerequisites
if [ "$(expr match "$PM" '.*\(apt-get\)')" == "apt-get" ]; then
#echo "debian compatible system"
sudo apt-get install \
bzr \
bzrtools \
build-essential \
cmake \
cmake-curses-gui \
debhelper \
doxygen \
2013-10-23 11:40:17 +00:00
libbz2-dev \
libcairo2-dev \
libglew-dev \
libssl-dev \
libwxgtk2.8-dev \
python-wxgtk2.8
# assume all yum systems have same prerequisites
elif [ "$(expr match "$PM" '.*\(yum\)')" == "yum" ]; then
#echo "red hat compatible system"
# Note: if you find this list not to be accurate, please submit a patch:
sudo yum groupinstall "Development Tools"
sudo yum install \
bzr \
bzrtools \
cmake \
cmake-gui \
doxygen \
bzip2-libs \
bzip2-devel \
cairo-devel \
glew-devel \
openssl-devel \
wxGTK-devel \
wxPython
else
echo
echo "Incompatible System. Neither 'yum' nor 'apt-get' found. Not possible to continue."
echo
exit 1
fi
2013-11-07 18:15:58 +00:00
# ensure bzr name and email are set. No message since bzr prints an excellent diagnostic.
bzr whoami || exit 2
}
2013-10-24 13:57:01 +00:00
rm_build_dir()
{
local dir="$1"
# this file is often created as root, so remove as root
sudo rm "$dir/install_manifest.txt" 2> /dev/null
rm -rf "$dir"
}
cmake_uninstall()
{
# assume caller set the CWD, and is only telling us about it in $1
local dir="$1"
cwd=`pwd`
if [ "$cwd" != "$dir" ]; then
echo "missing dir $dir"
elif [ ! -e install_manifest.txt ]; then
echo
echo "Missing file $dir/install_manifest.txt."
else
echo "uninstalling from $dir"
sudo make uninstall
sudo rm install_manifest.txt
fi
}
install_or_update()
{
echo "step 1) installing pre-requisites"
install_prerequisites
echo "step 2) make $WORKING_TREES if it does not exist"
if [ ! -d "$WORKING_TREES" ]; then
sudo mkdir -p "$WORKING_TREES"
echo " mark $WORKING_TREES as owned by me"
sudo chown -R `whoami` "$WORKING_TREES"
fi
cd $WORKING_TREES
echo "step 3) checking out the source code from launchpad repo..."
if [ ! -d "$WORKING_TREES/kicad.bzr" ]; then
bzr checkout lp:kicad kicad.bzr
echo " source repo to local working tree."
else
cd kicad.bzr
bzr up
echo " local source working tree updated."
cd ../
fi
if [ ! -d "$WORKING_TREES/kicad-lib.bzr" ]; then
bzr checkout "lp:$LIB_REPO" kicad-lib.bzr
2013-10-24 13:57:01 +00:00
echo ' kicad-lib checked out.'
else
cd kicad-lib.bzr
bzr up
2013-10-24 13:57:01 +00:00
echo ' kicad-lib repo updated.'
cd ../
fi
echo "step 5) checking out the documentation from launchpad repo..."
if [ ! -d "$WORKING_TREES/kicad-doc.bzr" ]; then
bzr checkout lp:~kicad-developers/kicad/doc kicad-doc.bzr
echo " docs checked out."
else
cd kicad-doc.bzr
bzr up
echo " docs working tree updated."
cd ../
fi
echo "step 6) compiling source code..."
cd kicad.bzr
2013-10-24 13:57:01 +00:00
if [ ! -d "build" ]; then
mkdir build && cd build
cmake $OPTS ../
2013-10-24 13:57:01 +00:00
else
cd build
# Although a "make clean" is sometimes needed, more often than not it slows down the update
# more than it is worth. Do it manually if you need to in this directory.
# make clean
fi
make -j4
echo " kicad compiled."
echo "step 7) installing KiCad program files..."
sudo make install
echo " kicad program files installed."
echo "step 8) installing libraries..."
cd ../../kicad-lib.bzr
2013-10-24 13:57:01 +00:00
rm_build_dir build
mkdir build && cd build
cmake ../
sudo make install
echo " kicad-lib installed."
echo "step 9) as non-root, install user configuration files..."
# install ~/fp-lib-table
make install_github_fp-lib-table
echo " kicad user-configuration files installed."
echo "step 10) installing documentation..."
cd ../../kicad-doc.bzr
2013-10-24 13:57:01 +00:00
rm_build_dir build
mkdir build && cd build
cmake ../
sudo make install
echo " kicad-doc.bzr installed."
2013-10-24 13:57:01 +00:00
echo
echo 'All KiCad "--install-or-update" steps completed, you are up to date.'
if [ -z "${KIGITHUB}" ]; then
echo "Please set an environment variable by adding:"
echo "export KIGITHUB=https://github.com/KiCad"
echo "to your ~/.bashrc file. Then reboot."
fi
}
if [ $# -eq 1 -a "$1" == "--remove-sources" ]; then
echo "deleting $WORKING_TREES"
2013-10-24 13:57:01 +00:00
rm_build_dir "$WORKING_TREES/kicad.bzr/build"
rm_build_dir "$WORKING_TREES/kicad-lib.bzr/build"
rm_build_dir "$WORKING_TREES/kicad-doc.bzr/build"
rm -rf "$WORKING_TREES"
exit
fi
if [ $# -eq 1 -a "$1" == "--install-or-update" ]; then
install_or_update
exit
fi
if [ $# -eq 1 -a "$1" == "--uninstall-libraries" ]; then
cd "$WORKING_TREES/kicad-lib.bzr/build"
cmake_uninstall "$WORKING_TREES/kicad-lib.bzr/build"
exit
fi
if [ $# -eq 1 -a "$1" == "--uninstall-kicad" ]; then
cd "$WORKING_TREES/kicad.bzr/build"
cmake_uninstall "$WORKING_TREES/kicad.bzr/build"
cd "$WORKING_TREES/kicad-lib.bzr/build"
cmake_uninstall "$WORKING_TREES/kicad-lib.bzr/build"
# this may fail since "uninstall" support is a recent feature of this repo:
cd "$WORKING_TREES/kicad-doc.bzr/build"
cmake_uninstall "$WORKING_TREES/kicad-doc.bzr/build"
exit
fi
usage