#!/bin/bash ######################################## # # Origin of function: https://github.com/matthuisman/files.matthuisman.nz # Function: gdrivedl # Description: Downloads a file from googledrive given a URL or fileid # ######################################## gdrivedl() { url=$1 filename=$2 [ -z "$url" ] && echo A URL or ID is required first argument && exit 1 fileid="" declare -a patterns=("s/.*\/file\/d\/\(.*\)\/.*/\1/p" "s/.*id\=\(.*\)/\1/p" "s/\(.*\)/\1/p") for i in "${patterns[@]}" do fileid=$(echo $url | sed -n $i) [ ! -z "$fileid" ] && break done [ -z "$fileid" ] && echo Could not find Google ID && exit 1 echo File ID: $fileid tmp_file="$filename.$$.file" tmp_cookies="$filename.$$.cookies" tmp_headers="$filename.$$.headers" ### STDOUT to STATUSFILE, stderr to LOGFILE and all output to the screen #exec > >(tee ${STATUSFILE}) 2> >(tee ${LOGFILE} >&2) url='https://docs.google.com/uc?export=download&id='$fileid echo Downloading: Stage 1 "$url > $tmp_file" wget --save-cookies "$tmp_cookies" -q -S -O - $url 2> "$tmp_headers" 1> "$tmp_file" if [[ ! $(find "$tmp_file" -type f -size +10000c 2>/dev/null) ]]; then confirm=`$cat "$tmp_file" | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1/p'` fi if [ ! -z "$confirm" ]; then url='https://docs.google.com/uc?export=download&id='$fileid'&confirm='$confirm echo Downloading: Stage 2 "$url > $tmp_file" wget --load-cookies "$tmp_cookies" -q -S -O - $url 2> "$tmp_headers" 1> "$tmp_file" fi [ -z "$filename" ] && filename=`cat "$tmp_headers" | sed -rn 's/.*filename=\"(.*)\".*/\1/p'` [ -z "$filename" ] && filename="google_drive.file" echo Moving: "$tmp_file > $filename" mv "$tmp_file" "$filename" rm -f "$tmp_cookies" "$tmp_headers" echo Saved: "$filename" echo DONE! } ######################################## # # Origin of Function: https://stackoverflow.com/a/32708121 # Function: prompt_confirm # Description: Ask user user for Y or N asks again if Yy or Nn not given # Color escape codes can be give to colourise text # ######################################## prompt_confirm() { while true; do read -r -n 1 -p "$(echo -e ${1:-Continue?} [y/n]: )" REPLY case $REPLY in [yY]) echo ; return 0 ;; [nN]) echo ; return 1 ;; *) printf " \033[31m %s \n\033[0m" "invalid input" esac done } # END OF FUNCTIONS ######################################## # # Main section of script starts here # ######################################## # Escape codes for colour of text # Black 0;30 Dark Gray 1;30 # Red 0;31 Light Red 1;31 # Green 0;32 Light Green 1;32 # Brown/Orange 0;33 Yellow 1;33 # Blue 0;34 Light Blue 1;34 # Purple 0;35 Light Purple 1;35 # Cyan 0;36 Light Cyan 1;36 # Light Gray 0;37 White 1;37 RED='\033[0;31m' GREEN='\033[0;32m' LT_RED='\033[1;31m' LT_GREEN='\033[1;32m' LT_BLUE='\033[1;34m' YELLOW='\033[1;33m' NC='\033[0m' # user & group stuff SUDO_USER_GROUP=`id -gn ${SUDO_USER}` SUDO_HOME_DIR=`getent passwd ${SUDO_USER} | cut -d: -f6` # Options for apt APT_OPTIONS="install --show-progress -y" # GDrive kernel fileids G_IMAGE="1MTigCV53dDRaw67dVQ47R7wGieU1WXkH" G_HEADERS="1PEk3M6Lr-iHqWOmyixmefdUSCe6kqN1Z" G_LIBC_DEV="1jxCxAxkv-yoEOK-M4qNeUk642szgDX84" # GDrive linuxcnc fileids G_USPACE="1kAVSKZmNt2NsgdEuq7KNJRnFYVEm_utQ" G_USPACE_DEV="1ti6O1QFBUNaimC_6SloXCvq0BjkCLeRZ" G_DOC_EN="1FxOQpyhge4xeEGaKGcvlJF5JRQD3hdbZ" G_DOC_HTML="1Mq_V04ReoEIbPAxU18ZHAum_UrO-xamw" # Stuff for kernel KERNEL_VERSION="4.19.106-rt44-lcnc" KERNEL_DEB_VERSION="4.19.106-rt44-lcnc-1" KERNEL_ARCH="amd64" LINUX_IMAGE="linux-image-${KERNEL_VERSION}_${KERNEL_DEB_VERSION}_${KERNEL_ARCH}.deb" LINUX_HEADERS="linux-headers-${KERNEL_VERSION}_${KERNEL_DEB_VERSION}_${KERNEL_ARCH}.deb" LINUX_LIBC_DEV="linux-libc-dev_${KERNEL_DEB_VERSION}_${KERNEL_ARCH}.deb" declare -a KERNEL_PACKAGES=("./${LINUX_IMAGE}" \ "./${LINUX_HEADERS}" ) #"./${LINUX_LIBC_DEV}" ) #Stuff for Linuxcnc LINUXCNC_VERSION="2.8.0~pre1~rmurphy.htmldocs~1c3c94442" LINUXCNC_USPACE="linuxcnc-uspace_${LINUXCNC_VERSION}_${KERNEL_ARCH}.deb" LINUXCNC_USPACE_DEV="linuxcnc-uspace-dev_${LINUXCNC_VERSION}_${KERNEL_ARCH}.deb" LINUXCNC_DOC_EN="linuxcnc-doc-en_${LINUXCNC_VERSION}_all.deb" LINUXCNC_DOC_HTML="linuxcnc-doc-html_${LINUXCNC_VERSION}_all.deb" declare -a USPACE_PACKAGES=( "./${LINUXCNC_USPACE}" \ "./${LINUXCNC_USPACE_DEV}" \ "./${LINUXCNC_DOC_EN}" \ "./${LINUXCNC_DOC_HTML}" ) # Check if running as root. if [ $(id -u) != "0" ]; then echo -e "${LT_RED}You must be the superuser to run this script${NC}" >&2 exit 1 fi echo -e "${YELLOW}This will download Kernel ${KERNEL_VERSION} and Linuxcnc-uspace ${LINUXCNC_VERSION}" echo -e "Later you will be asked if you want to install the packages" echo -e "Additionally you will be asked if you wish to install qtvcp dependencies" echo -e "& dependencies to build linuxcnc from source." echo -e "Not this script does not clone the linuxcnc git sources${NC}" prompt_confirm "${LT_BLUE}Continue with download of packages ?${NC}" || { echo -e "${LT_RED}Installation Aborted${NC}" exit 0 } # Download Packages if [ ! -f "${LINUX_IMAGE}" ]; then echo -e "${YELLOW}Downloading linux-image${NC}" gdrivedl https://drive.google.com/open?id=${G_IMAGE} fi if [ ! -f "${LINUX_HEADERS}" ]; then echo -e "${YELLOW}Downloading linux-headers${NC}" gdrivedl https://drive.google.com/open?id=${G_HEADERS} fi if [ ! -f "${LINUX_LIBC_DEV}" ]; then echo -e "${YELLOW}Downloading linux-libc-dev${NC}" gdrivedl https://drive.google.com/open?id=${G_LIBC_DEV} fi if [ ! -f "${LINUXCNC_USPACE}" ]; then echo -e "${YELLOW}Downloading linuxcnc-uspace${NC}" gdrivedl https://drive.google.com/open?id=${G_USPACE} fi if [ ! -f "${LINUXCNC_USPACE_DEV}" ]; then echo -e "${YELLOW}Downloading linuxcnc-uspace-dev${NC}" gdrivedl https://drive.google.com/open?id=${G_USPACE_DEV} fi if [ ! -f "${LINUXCNC_DOC_EN}" ]; then echo -e "${YELLOW}Downloading linuxcnc-doc-en${NC}" gdrivedl https://drive.google.com/open?id=${G_DOC_EN} fi if [ ! -f "${LINUXCNC_DOC_HTML}" ]; then echo -e "${YELLOW}Downloading linuxcnc-doc-html${NC}" gdrivedl https://drive.google.com/open?id=${G_DOC_HTML} fi # Checking echo -e "${YELLOW}Checking for kernel package files${NC}" for FILE_NAME in "${KERNEL_PACKAGES[@]}"; do if [ -f "${FILE_NAME}" ]; then echo -e "${LT_GREEN}$FILE_NAME found ${NC}" else echo -e "${LT_RED}$FILE_NAME not found${NC}" exit 1 fi done echo -e "${YELLOW}Checking for linuxcnc package files${NC}" for FILE_NAME in "${USPACE_PACKAGES[@]}"; do if [ -f "${FILE_NAME}" ]; then echo -e "${LT_GREEN}$FILE_NAME found ${NC}" else echo -e "${LT_RED}$FILE_NAME not found${NC}" exit 1 fi done # Install RT Kernel prompt_confirm "${LT_BLUE}Conitune and install the Realtime kernel ?${NC}" || { echo -e "${LT_RED}Kernel Installation Aborted exiting script${NC}" exit 0 } apt ${APT_OPTIONS} ${KERNEL_PACKAGES[@]} # Install Linuxcnc-uspace prompt_confirm "${LT_BLUE}Conitune and install Linuxcnc ?${NC}" || { echo -e "${LT_RED}Linuxcnc Installation Aborted exiting script${NC}" exit 0 } apt ${APT_OPTIONS} ${USPACE_PACKAGES[@]} # Install qtvcp prompt_confirm "${LT_BLUE}Do you want to install packages for qtvcp ?${NC}" if [ $? -eq 0 ]; then { apt ${APT_OPTIONS} python-pyqt5 \ python-pyqt5.qsci \ python.pyqt5.qtopengl \ python-pyqt5.qtsvg \ python-opengl \ python-opencv \ python-dbus.mainloop.pyqt \ qttools5-dev-tools \ qttools5-dev \ python-pyqt5.qtmultimedia \ qml-module-qtquick-controls \ gstreamer1.0-plugins-bad \ libqt5multimedia5-plugins \ python-dev \ python-setuptools \ python-pip git \ python-pyqtgraph PYQTLIB="/usr/lib/x86_64-linux-gnu/qt5/plugins/designer/libpyqt5_py2.so" PYQTPYDIR="/usr/lib/x86_64-linux-gnu/qt5/plugins/designer/python" if [ -f $PYQTLIB ]; then echo -e "${YELLOW}Deleting plugin library${NC}" rm -v $PYQTLIB fi if [ -d $PYQTPYDIR ]; then echo -e "${YELLOW}Deleting plugin link & directory${NC}" rm -r -v $PYQTPYDIR fi echo -e "${YELLOW}Setting up QTVCP Plugins${NC}" tar -C /usr/lib/x86_64-linux-gnu/qt5/plugins/designer/ \ -xvzf /usr/lib/python2.7/dist-packages/qtvcp/designer/x86_64/qt5.9/libpyqt5_py2.so.tar.gz mkdir /usr/lib/x86_64-linux-gnu/qt5/plugins/designer/python ln -s /usr/lib/python2.7/dist-packages/qtvcp/plugins/qtvcp_plugin.py \ /usr/lib/x86_64-linux-gnu/qt5/plugins/designer/python/ } else echo -e "${LT_RED}Installation of qtvcp aborted${NC}" fi # Install packages to rebuild linuxcnc from git prompt_confirm "${LT_BLUE}Do you want to install dependencies for building linuxcnc from source ?${NC}" && if [ $? -eq 0 ]; then { apt ${APT_OPTIONS} devscripts build-essential \ debhelper dh-python libudev-dev libxenomai-dev \ tcl8.6-dev tk8.6-dev libreadline-gplv2-dev \ asciidoc dblatex dvipng graphviz groff \ imagemagick inkscape python-lxml source-highlight \ texlive-extra-utils texlive-font-utils \ texlive-fonts-recommended texlive-lang-cyrillic \ texlive-lang-french texlive-lang-german \ texlive-lang-polish texlive-lang-spanish \ texlive-latex-recommended w3c-linkchecker \ asciidoc-dblatex python-dev python-tk \ libxmu-dev libglu1-mesa-dev libgl1-mesa-dev \ libgtk2.0-dev libboost-python-dev \ libmodbus-dev libusb-1.0-0-dev yapps2 } else echo -e "${LT_RED}Build dependencies nstallation aborted${NC}" fi prompt_confirm "${LT_BLUE}Do wish to keep downloaded Kernel & Linuxcnc packages ?${NC}" if [ $? -eq 0 ]; then { if [ ! -d ${SUDO_HOME_DIR}/linuxcnc-uspace ]; then mkdir ${SUDO_HOME_DIR}/linuxcnc-uspace fi mv *.deb ${SUDO_HOME_DIR}/linuxcnc-uspace chown -R "$SUDO_USER":"$SUDO_USER_GROUP" ${SUDO_HOME_DIR}/linuxcnc-uspace echo -e "${YELLOW}Packages have been saved to ${SUDO_HOME_DIR}/linuxcnc-uspace${NC}" } else { echo -e "${YELLOW}Deleting downloaded packages${NC}" rm *.deb } fi exit 0