2021-02-14 08:51:14 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
echo "Checking the environment..."
|
|
|
|
unameOut="$(uname -s)"
|
|
|
|
case "${unameOut}" in
|
2022-03-26 12:30:24 -07:00
|
|
|
Linux*) machine=linux;;
|
|
|
|
Darwin*) machine=mac;;
|
|
|
|
CYGWIN*) machine=cygwin;;
|
|
|
|
MSYS*) machine=msys;;
|
|
|
|
MINGW32*) machine=mingw32;;
|
|
|
|
MINGW64*) machine=mingw64;;
|
|
|
|
*) machine=unknown;;
|
2021-02-14 08:51:14 -08:00
|
|
|
esac
|
|
|
|
if [ "${machine}" = "unknown" ] ; then
|
|
|
|
echo "* Warning! Unknown environment: ${unameOut}"
|
|
|
|
else
|
|
|
|
echo "* ${machine} environment detected!"
|
|
|
|
fi
|
|
|
|
|
2022-02-03 11:20:08 -08:00
|
|
|
# $1 = url $2 = dst
|
|
|
|
function download_url {
|
|
|
|
url=$1
|
|
|
|
dst=$2
|
|
|
|
# check if wget or curl is installed
|
|
|
|
if [ -x "$(command -v wget)" ] ; then
|
|
|
|
echo "Downloading apt-cyg using wget..."
|
|
|
|
wget $url -O $dst
|
|
|
|
elif [ -x "$(command -v curl)" ]; then
|
|
|
|
echo "Downloading apt-cyg using curl..."
|
|
|
|
curl -o $dst -sfL $url
|
|
|
|
else
|
|
|
|
echo "Could not find curl or wget! Cannot download and install a package manager!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-02-14 08:51:14 -08:00
|
|
|
# $1 = package_name
|
|
|
|
function install_package {
|
|
|
|
# check if the installer (package manager) exists
|
|
|
|
if [ "${machine}" = "cygwin" ] ; then
|
|
|
|
while true; do
|
|
|
|
if [ ! -x "$(command -v apt-cyg --version)" ] ; then
|
|
|
|
# we give it one more chance and try to download the installer
|
|
|
|
echo "Do you want to download the cygwin package manager (apt-cyg) and install the required utilities? (Press 1 or 2)"
|
|
|
|
select yn in "Yes" "No"; do
|
2022-03-26 12:30:24 -07:00
|
|
|
case $yn in
|
|
|
|
Yes )
|
|
|
|
url="rawgit.com/transcode-open/apt-cyg/master/apt-cyg"
|
|
|
|
dst="/tmp/apt-cyg"
|
2022-02-03 11:20:08 -08:00
|
|
|
download_url $url $dst
|
2022-03-26 12:30:24 -07:00
|
|
|
install $dst /bin
|
|
|
|
rm $dst
|
|
|
|
break;;
|
|
|
|
No )
|
2021-02-14 08:51:14 -08:00
|
|
|
echo "Please install it manually using you package manager!" >&2
|
2022-03-26 12:30:24 -07:00
|
|
|
exit 1;
|
2021-02-14 08:51:14 -08:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
elif [ "${machine}" = "msys" ] ; then
|
|
|
|
if [ ! -x "$(command -v pacman)" ] ; then
|
|
|
|
echo "Cannot detect pacman manager. Please install it manually using you package manager!" >&2
|
2022-03-26 12:30:24 -07:00
|
|
|
exit 1;
|
2021-02-14 08:51:14 -08:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# now install
|
|
|
|
echo "Do you want to install '$1' now? (Press 1 or 2)"
|
|
|
|
select yn in "Yes" "No"; do
|
2022-03-26 12:30:24 -07:00
|
|
|
case $yn in
|
2021-02-14 08:51:14 -08:00
|
|
|
Yes )
|
2022-03-26 12:30:24 -07:00
|
|
|
break;;
|
2021-02-14 08:51:14 -08:00
|
|
|
No )
|
|
|
|
echo "Please install it manually using your package manager!" >&2
|
2022-03-26 12:30:24 -07:00
|
|
|
exit 1;
|
2021-02-14 08:51:14 -08:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "${machine}" = "cygwin" ] ; then
|
|
|
|
apt-cyg install $1
|
|
|
|
elif [ "${machine}" = "msys" ] ; then
|
|
|
|
pacman -S mingw-w64-x86_64-$1
|
|
|
|
elif [ "${machine}" = "linux" ] ; then
|
2022-02-03 11:20:08 -08:00
|
|
|
if ! sudo apt-get install $1; then
|
|
|
|
# try updating the apt repo
|
|
|
|
sudo apt update
|
|
|
|
if ! sudo apt-get install $1; then
|
|
|
|
echo "Error! Cannot install the package $1. Please install it manually using your package manager!" >&2
|
2022-03-26 12:30:24 -07:00
|
|
|
exit 1;
|
|
|
|
fi
|
2022-02-03 11:20:08 -08:00
|
|
|
fi
|
2021-02-14 08:51:14 -08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "Checking the Python version..."
|
2022-03-26 12:30:24 -07:00
|
|
|
# check python version - should be 3.x ONLY
|
|
|
|
python_bin="python3"
|
2022-02-03 11:20:08 -08:00
|
|
|
while true; do
|
|
|
|
python_ver=$($python_bin -V 2>&1 | grep -Po '(?<=Python )(.+)')
|
2022-03-26 12:30:24 -07:00
|
|
|
if [[ -z "$python_ver" ]] || [[ ! $python_ver =~ ^3\.[56789].* ]] ; then
|
|
|
|
echo "Error! Python 3.5 or later is required. It should be installed and added to the PATH!"
|
|
|
|
install_package python2
|
|
|
|
if [ "${machine}" = "linux" ] ; then
|
|
|
|
install_package python2-dev
|
|
|
|
fi
|
2022-02-03 11:20:08 -08:00
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2021-02-14 08:51:14 -08:00
|
|
|
|
|
|
|
# $1 = name, $2 = library name, $3 = package name
|
|
|
|
function check_library {
|
|
|
|
echo "* Checking $1..."
|
|
|
|
while true; do
|
2021-11-06 22:06:22 -07:00
|
|
|
if ! command -v pkg-config >/dev/null 2>&1 ; then
|
2022-03-26 12:30:24 -07:00
|
|
|
echo "* Missing pkg-config"
|
2022-02-03 11:20:08 -08:00
|
|
|
echo "Do you want to download and install it now? (Press 1 or 2)"
|
|
|
|
select yn in "Yes" "No"; do
|
2022-03-26 12:30:24 -07:00
|
|
|
case $yn in
|
2022-02-03 11:20:08 -08:00
|
|
|
Yes ) install_package pkg-config; break;;
|
|
|
|
No ) exit 1;
|
|
|
|
esac
|
|
|
|
done
|
2021-11-06 22:06:22 -07:00
|
|
|
fi
|
|
|
|
|
2021-02-14 08:51:14 -08:00
|
|
|
lib=$(pkg-config --libs $2 2>&1 | grep -Po '(\-l'$1')')
|
|
|
|
if [[ -z "$lib" ]] ; then
|
|
|
|
echo "Error! Library $1 NOT FOUND!"
|
|
|
|
else
|
|
|
|
echo "* Library $1 FOUND!"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
install_package $3
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-03-26 12:30:24 -07:00
|
|
|
function install_pip3 {
|
|
|
|
pip3installer="https://bootstrap.pypa.io/pip/3.6/get-pip.py"
|
2022-02-03 11:20:08 -08:00
|
|
|
dst="/tmp/get-pip.py"
|
2022-03-26 12:30:24 -07:00
|
|
|
download_url $pip3installer $dst
|
2022-02-03 11:20:08 -08:00
|
|
|
$python_bin $dst
|
|
|
|
rm $dst
|
|
|
|
}
|
|
|
|
|
2022-03-26 12:30:24 -07:00
|
|
|
function pip3_install_module {
|
|
|
|
# check if pip3 works
|
2022-02-03 11:20:08 -08:00
|
|
|
pip_bin="$python_bin -m pip"
|
|
|
|
while true; do
|
2022-03-26 12:30:24 -07:00
|
|
|
pip3v=$($pip_bin --version 2>&1 | grep -Po '(pip [0-9]+\.[0-9]+.*)')
|
|
|
|
if [[ -z "$pip3v" ]] ; then
|
|
|
|
echo "* Missing pip3"
|
2022-02-03 11:20:08 -08:00
|
|
|
if [ "${machine}" = "linux" ] ; then
|
2022-03-26 12:30:24 -07:00
|
|
|
echo "Do you want to download and install it now? (Press 1 or 2)"
|
|
|
|
select yn in "Yes" "No"; do
|
|
|
|
case $yn in
|
|
|
|
Yes ) install_pip3; break;;
|
|
|
|
No ) exit 1;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
else
|
|
|
|
install_package pip3
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
2022-02-03 11:20:08 -08:00
|
|
|
done
|
|
|
|
|
|
|
|
# check if gnu compiler works (needed by some modules)
|
|
|
|
gcc_bin="gcc"
|
|
|
|
while true; do
|
|
|
|
gccv=$($gcc_bin -v 2>&1 | grep -Po '(version\s+[0-9]+\.[0-9]+.*)')
|
|
|
|
if [[ -z "$gccv" ]] ; then
|
2022-03-26 12:30:24 -07:00
|
|
|
echo "* Missing gcc compiler"
|
|
|
|
install_package gcc
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
2022-02-03 11:20:08 -08:00
|
|
|
done
|
|
|
|
|
2022-03-26 12:30:24 -07:00
|
|
|
echo "* Installing python module $1 using $pip3v and gcc $gccv..."
|
2022-02-03 11:20:08 -08:00
|
|
|
$pip_bin install $pymodule
|
|
|
|
}
|
|
|
|
|
2021-02-14 08:51:14 -08:00
|
|
|
echo "* Python $python_ver detected!"
|
|
|
|
|
2022-02-03 11:20:08 -08:00
|
|
|
echo "Checking git..."
|
|
|
|
git_bin="git"
|
|
|
|
git_ver=0
|
|
|
|
while true; do
|
|
|
|
git_ver=$($git_bin version 2>&1 | grep -Po '(version [0-9]+\.[0-9]+.*)')
|
|
|
|
if [[ -z "$git_ver" ]] ; then
|
2022-03-26 12:30:24 -07:00
|
|
|
echo "Error! Git not found! We need it to update submodules."
|
|
|
|
install_package git
|
2022-02-03 11:20:08 -08:00
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "* Git $git_ver detected!"
|
|
|
|
|
2021-02-14 08:51:14 -08:00
|
|
|
echo "Updating git submodules for scripts..."
|
2022-03-26 12:30:24 -07:00
|
|
|
#git submodule update --init -- bin/gerbmerge bin/python-combine-pdfs bin/InteractiveHtmlBom bin/pcb-tools
|
2021-02-14 08:51:14 -08:00
|
|
|
|
|
|
|
echo "Checking the Python modules..."
|
|
|
|
declare -A modules
|
|
|
|
modules[simpleparse]=simpleparse
|
2022-03-26 12:30:24 -07:00
|
|
|
modules[moderngl]=ModernGL
|
|
|
|
modules[PIL]=Pillow
|
|
|
|
modules[pyrr]=Pyrr
|
|
|
|
modules[numpy]=NumPy
|
|
|
|
modules[vrml.vrml97]=PyVRML97
|
2021-02-14 08:51:14 -08:00
|
|
|
modules[contextlib2]=contextlib2
|
|
|
|
modules[PyPDF2]=PyPDF2
|
|
|
|
modules[gerber]=gerber
|
|
|
|
modules[configparser]=configparser
|
|
|
|
modules[gzip]=gzip
|
|
|
|
modules[cairocffi]=cairocffi
|
|
|
|
|
|
|
|
# check modules
|
|
|
|
for module in "${!modules[@]}"; do
|
|
|
|
pymodule=${modules[$module]}
|
|
|
|
while true; do
|
|
|
|
$python_bin -c "import sys, pkgutil; sys.path.append('./bin/pcb-tools'); sys.exit(0 if (pkgutil.find_loader('$module')) else 1)"
|
|
|
|
if [ $? -eq 0 ]; then
|
2022-03-26 12:30:24 -07:00
|
|
|
echo "* Checking Python module '$pymodule': OK"
|
|
|
|
break
|
2021-02-14 08:51:14 -08:00
|
|
|
else
|
2022-03-26 12:30:24 -07:00
|
|
|
echo "* Checking Python module '$pymodule': ERROR!"
|
|
|
|
echo " Python module '$pymodule' is required and NOT found!"
|
|
|
|
|
|
|
|
# some modules have dependencies
|
2021-02-14 08:51:14 -08:00
|
|
|
if [ "$pymodule" = "cairocffi" ]; then
|
2022-02-03 11:20:08 -08:00
|
|
|
if [ "${machine}" = "linux" ] ; then
|
|
|
|
devname="dev"
|
|
|
|
else
|
|
|
|
devname="devel"
|
|
|
|
fi
|
|
|
|
check_library ffi libffi libffi-${devname}
|
|
|
|
check_library cairo cairo libcairo-${devname}
|
2021-02-14 08:51:14 -08:00
|
|
|
fi
|
|
|
|
|
2022-03-26 12:30:24 -07:00
|
|
|
if [ ]; then
|
|
|
|
echo "Please use 'pip3 install $pymodule' to install it manually!"
|
|
|
|
exit 1;
|
|
|
|
else
|
2021-02-14 08:51:14 -08:00
|
|
|
echo "Do you want to download and install it now? (Press 1 or 2)"
|
|
|
|
select yn in "Yes" "No"; do
|
2022-03-26 12:30:24 -07:00
|
|
|
case $yn in
|
|
|
|
Yes ) pip3_install_module $pymodule; break;;
|
|
|
|
No ) exit 1;
|
2021-02-14 08:51:14 -08:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "All checks done!"
|
|
|
|
|
|
|
|
exit 0
|