Set up GIS software on multiple computers (Windows & Linux) simultaneosly using SaltStack
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

452 lines
14 KiB

6 years ago
  1. #!/bin/bash
  2. # Salt Master/Minion preconfiguration script
  3. # Copyright (C) 2018 Pekka Helenius
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. ###########################################################
  18. # Run on Ubuntu 18.04 LTS Salt master
  19. # Compiles LAS tools and CloudCompare for GIS workstation (Ubuntu & Windows)
  20. # Downloads necessary GIS tools
  21. OSES=(windows ubuntu-1804)
  22. # Required OS to run this script
  23. REQUIRED_OS="Ubuntu"
  24. # Compile CloudCompare for Ubuntu?
  25. # TODO: support false option
  26. CC_GET_UBUNTU=true
  27. # Get this variable from the main script runme.sh
  28. # The variable defined whether we should only run local Salt minion (which is running
  29. # on Ubuntu 18.04 LTS) or not
  30. #
  31. if [[ $1 == "true" ]]; then
  32. local_only=""
  33. fi
  34. if [[ $2 == "true" ]]; then
  35. winminions_present=''
  36. fi
  37. ########################
  38. # INSTALL DEV PACKAGES
  39. function devPackages() {
  40. if [[ -f /etc/os-release ]]; then
  41. DISTRO=$(grep ^PRETTY_NAME /etc/os-release | grep -oP '(?<=")[^\s]*')
  42. if [[ $DISTRO == ${REQUIRED_OS} ]]; then
  43. # for LAStools
  44. echo -e "Updating local package databases & installing necessary dev tools for LASTools & CloudCompare\n"
  45. apt-get update
  46. apt-get install -y make git build-essential
  47. if [[ $CC_GET_UBUNTU == "true" ]]; then
  48. # for CloudCompare
  49. apt-get install -y cmake libhpdf-dev debhelper fakeroot
  50. CC_DEVDEPENDS=(
  51. libhpdf-dev
  52. libqt5opengl5-dev
  53. libcgal-dev
  54. libdxflib-dev
  55. libglew-dev
  56. libfreenect-dev
  57. libgdal-dev
  58. liblas-c-dev
  59. liblas-dev
  60. libboost-all-dev
  61. libjsoncpp-dev
  62. libpdal-dev
  63. libcurl4-gnutls-dev
  64. )
  65. function checkDevVersions() {
  66. function generateDevVersions() {
  67. if [[ ! -f compiled/cc_devpkg_versions ]]; then
  68. touch compiled/cc_devpkg_versions
  69. fi
  70. for devpkg_version in ${CC_DEVDEPENDS[@]}; do
  71. echo -e "$(dpkg -s $devpkg_version | grep -E '^Package:|^Version:' | awk '{print $2}' | tr '\n' ' ')" \
  72. >> compiled/cc_devpkg_versions
  73. if [[ $? -ne 0 ]]; then
  74. exit 1
  75. fi
  76. done
  77. }
  78. # Check if we need to update our CloudCompare makedepend packages
  79. if [[ -f compiled/cc_devpkg_versions ]]; then
  80. local IFS=$'\n'
  81. for devpackage in $(cat compiled/cc_devpkg_versions); do
  82. if [[ $(apt-cache policy $(echo $devpackage | awk '{print $1}') | grep 'Candidate' | awk '{print $2}') != $(echo $devpackage | awk '{print $2}') ]]; then
  83. LOCAL_DEVPKG_OLD_FLAG=""
  84. fi
  85. done
  86. if [[ -v LOCAL_DEVPKG_OLD_FLAG ]]; then
  87. apt-get install -y ${CC_DEVDEPENDS[*]}
  88. rm compiled/cc_devpkg_versions
  89. fi
  90. else
  91. touch compiled/cc_devpkg_versions
  92. apt-get install -y ${CC_DEVDEPENDS[*]}
  93. generateDevVersions
  94. fi
  95. if [[ ! -f compiled/cc_devpkg_versions ]]; then
  96. generateDevVersions
  97. fi
  98. }
  99. checkDevVersions
  100. fi
  101. else
  102. echo -e "This is not ${REQUIRED_OS} Linux distribution. Aborting.\n"
  103. exit 1
  104. fi
  105. else
  106. echo -e "Can't recognize your Linux distribution. Aborting.\n"
  107. exit 1
  108. fi
  109. }
  110. ########################
  111. # COMPILE LASTOOLS
  112. # Compile open-source LAS tools
  113. # Q: What is this?
  114. # A: See descriptions of binaries below
  115. # Main reason for this: Not available from software repositories but
  116. # still an essential toolset for GIS workflow
  117. # las2las: extracts last returns, clips, subsamples, translates, etc ...
  118. # las2txt: turns LAS into human-readable and easy-to-parse ASCII
  119. # lasdiff: compares the LIDAR data of two LAS/LAZ/ASCII files and reports whether they are identical or whether they are different.
  120. # lasindex: creates a spatial index LAX file for fast spatial queries
  121. # lasinfo: prints out a quick overview of the contents of a LAS file
  122. # lasmerge: merges several LAS or LAZ files into a single LAS or LAZ file
  123. # lasprecision: analyses the actual precision of the LIDAR points
  124. # laszip: compresses the LAS files in a completely lossless manner
  125. # txt2las: converts LIDAR data from ASCII text to binary LAS format
  126. LASTOOLS=(
  127. las2las
  128. las2txt
  129. lasdiff
  130. lasindex
  131. lasinfo
  132. lasmerge
  133. lasprecision
  134. laszip
  135. txt2las
  136. )
  137. # There are closed source LAS tools available for Windows platform
  138. LASTOOLS_WIN=(
  139. blast2dem
  140. blast2iso
  141. bytecopy
  142. bytediff
  143. e572las
  144. las2dem
  145. las2iso
  146. las2shp
  147. las2tin
  148. lasboundary
  149. lascanopy
  150. lasclassify
  151. lasclip
  152. lascolor
  153. lascontrol
  154. lascopy
  155. lasduplicate
  156. lasgrid
  157. lasground
  158. lasground_new
  159. lasheight
  160. laslayers
  161. lasnoise
  162. lasoptimize
  163. lasoverage
  164. lasoverlap
  165. lasplanes
  166. laspublish
  167. lasreturn
  168. lassort
  169. lassplit
  170. lasthin
  171. lastile
  172. lastool
  173. lastrack
  174. lasvalidate
  175. lasview
  176. lasvoxel
  177. shp2las
  178. sonarnoiseblaster
  179. )
  180. function compileLAStools() {
  181. if [[ ! -d $1/files/lastools ]]; then
  182. mkdir -p $1/files/lastools
  183. fi
  184. if [[ $(ls $1/files/lastools | wc -l) -eq 0 ]]; then
  185. if [[ ! -d compiled/LAStools ]]; then
  186. git clone https://github.com/LAStools/LAStools
  187. cd LAStools/
  188. make -j$(nproc --ignore 1)
  189. if [[ $? -eq 0 ]]; then
  190. cd ..
  191. mv LAStools compiled/
  192. fi
  193. fi
  194. if [[ $? -eq 0 ]]; then
  195. if [[ $1 = *"ubuntu"* ]]; then
  196. for lastool in ${LASTOOLS[*]}; do
  197. cp ./compiled/LAStools/src/$lastool \
  198. $1/files/lastools/
  199. done
  200. elif [[ $1 = *"windows"* ]]; then
  201. if [[ ! -v local_only ]] && [[ -v winminions_present ]]; then
  202. for lastool_win1 in ${LASTOOLS[*]}; do
  203. cp ./compiled/LAStools/bin/$lastool_win1.exe \
  204. $1/files/lastools/
  205. done
  206. for lastool_win2 in ${LASTOOLS_WIN[*]}; do
  207. cp ./compiled/LAStools/bin/$lastool_win2.exe \
  208. $1/files/lastools/
  209. done
  210. fi
  211. fi
  212. fi
  213. fi
  214. }
  215. ########################
  216. function getOtherGIS() {
  217. if [[ $CC_GET_UBUNTU == "true" ]]; then
  218. if [[ $1 = *"ubuntu"* ]]; then
  219. # Compile CloudCompare for Ubuntu
  220. #
  221. # Main reason for this: Not yet available as a binary download for Ubuntu 18.04 LTS
  222. # BREAKS EASILY!
  223. # Issues: compatibility with other Linux distros may not be stable.
  224. # Currently available only for Ubuntu
  225. if [[ ! -f compiled/cloudcompare_${CC_VERSION_UBUNTU}-1_amd64.deb ]] || [[ -v LOCAL_DEVPKG_OLD_FLAG ]] ; then
  226. # Get CloudCompare source files & Debian control files
  227. wget http://http.debian.net/debian/pool/main/c/cloudcompare/cloudcompare_${CC_VERSION_UBUNTU}.orig.tar.gz
  228. wget http://http.debian.net/debian/pool/main/c/cloudcompare/cloudcompare_${CC_VERSION_UBUNTU}-1.debian.tar.xz
  229. # Extract CloudCompare source files
  230. tar xf cloudcompare_${CC_VERSION_UBUNTU}.orig.tar.gz
  231. # Make CloudCompare source root directory compatible with dpkg-buildpackage command
  232. mv CloudCompare-master cloudcompare-${CC_SHORT_UBUNTU}
  233. # Extract Debian control files
  234. tar xf cloudcompare_${CC_VERSION_UBUNTU}-1.debian.tar.xz --directory cloudcompare-${CC_SHORT_UBUNTU}/
  235. # Compile CloudCompare
  236. cd cloudcompare-${CC_SHORT_UBUNTU}
  237. dpkg-buildpackage -rfakeroot -b -us -uc -j$(nproc --ignore 1)
  238. if [[ $? -eq 0 ]]; then
  239. cd ..
  240. mv ./{*.tar.*,*.buildinfo,*.changes,*.deb} compiled/
  241. rm -Rf cloudcompare-${CC_SHORT_UBUNTU}
  242. fi
  243. fi
  244. if [[ ! -f $1/files/cloudcompare_${CC_VERSION_UBUNTU}-1_amd64.deb ]]; then
  245. cp compiled/cloudcompare_${CC_VERSION_UBUNTU}-1_amd64.deb $1/files/
  246. fi
  247. fi
  248. fi
  249. if [[ $1 == *"windows"* ]]; then
  250. if [[ ! -v local_only ]] && [[ -v winminions_present ]]; then
  251. if [[ ! -d compiled/windows ]]; then
  252. mkdir -p compiled/windows
  253. fi
  254. # Download Visual C++ Redistributable Packages for Visual Studio 2013 for Windows
  255. # Required by CloudCompare
  256. if [[ ! -f compiled/windows/vcrun2013_64.exe ]]; then
  257. wget https://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe -O \
  258. compiled/windows/vcrun2013_64.exe
  259. fi
  260. # Download CloudCompare for Windows
  261. if [[ ! -f compiled/windows/CloudCompare_${CC_VERSION_WIN}_setup_x64.exe ]]; then
  262. wget http://cloudcompare.org/release/CloudCompare_${CC_VERSION_WIN}_setup_x64.exe -O \
  263. compiled/windows/CloudCompare_${CC_VERSION_WIN}_setup_x64.exe
  264. fi
  265. # Download QGIS for Windows
  266. if [[ ! -f compiled/windows/QGIS-OSGeo4W-${QGIS_VERSION_WIN}-Setup-x86_64.exe ]]; then
  267. wget http://qgis.org/downloads/QGIS-OSGeo4W-${QGIS_VERSION_WIN}-Setup-x86_64.exe -O \
  268. compiled/windows/QGIS-OSGeo4W-${QGIS_VERSION_WIN}-Setup-x86_64.exe
  269. fi
  270. # Download gpx2shp. NOTE: Outdated version, but only out-of-the-box binary for Windows available
  271. GPX2SHP_WIN_1="gpx2shp-0.69_win_notest"
  272. GPX2SHP_WIN_2="gpx2shp-0.69_wintest"
  273. if [[ ! -f compiled/windows/gpx2shp.exe ]]; then
  274. wget https://dotsrc.dl.osdn.net/osdn/gpx2shp/13458/${GPX2SHP_WIN_1}.zip -O \
  275. compiled/windows/${GPX2SHP_WIN_1}.zip
  276. unzip -j compiled/windows/${GPX2SHP_WIN_1}.zip ${GPX2SHP_WIN_2}/gpx2shp.exe -d compiled/windows/ &> /dev/null
  277. rm compiled/windows/${GPX2SHP_WIN_1}.zip
  278. fi
  279. # Download Merkaartor
  280. if [[ ! -f compiled/windows/merkaartor-${MERK_VERSION_WIN}-64bit.exe ]]; then
  281. wget http://merkaartor.be/files/merkaartor-${MERK_VERSION_WIN}-64bit.exe -O \
  282. compiled/windows/merkaartor-${MERK_VERSION_WIN}-64bit.exe
  283. fi
  284. # Download Quickroute GPS
  285. # NOTE: Get MSI GUID for 32-bit uninstaller (for sls) by running the following in Windows Powershell:
  286. # get-wmiobject Win32_Product | Format-Table IdentifyingNumber, Name
  287. if [[ ! -f compiled/windows/QuickRoute_${QR_VERSION_WIN}_Setup.msi ]]; then
  288. wget http://www.matstroeng.se/quickroute/download/QuickRoute_${QR_VERSION_WIN}_Setup.msi -O \
  289. compiled/windows/QuickRoute_${QR_VERSION_WIN}_Setup.msi
  290. fi
  291. # Download GPS Daemon
  292. # NOTE: Deprecated version. Newer version is available for Unix platforms
  293. if [[ ! -f compiled/windows/GPSd-4-win_${GPSD_VERSION_WIN}.exe ]]; then
  294. wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/gpsd-4-win/GPSd-4-win_${GPSD_VERSION_WIN}.exe -O \
  295. compiled/windows/GPSd-4-win_${GPSD_VERSION_WIN}.exe
  296. fi
  297. ## GPSBabel
  298. #
  299. #wget https://www.gpsbabel.org/plan9.php
  300. #
  301. #GPSBabel-1.5.4-Setup.exe
  302. for win_installer in compiled/windows/*; do
  303. cp $win_installer /srv/salt/win/repo-ng/installers/
  304. done
  305. cp compiled/windows/gpx2shp.exe /srv/salt/gis_windows/files/
  306. rm /srv/salt/win/repo-ng/installers/gpx2shp.exe
  307. fi
  308. fi
  309. }
  310. ########################
  311. devPackages
  312. # Create directory for compiled programs
  313. if [[ ! -d compiled ]]; then
  314. mkdir compiled
  315. fi
  316. for OS in ${OSES[*]}; do
  317. if [[ $OS = *"ubuntu"* ]]; then
  318. CC_VERSION_UBUNTU="2.9.1+git20180223"
  319. CC_SHORT_UBUNTU="2.9.1"
  320. elif [[ $OS == *"windows"* ]] && [[ ! -v $skip_windows ]]; then
  321. CC_VERSION_WIN="v2.10.alpha"
  322. CC_SHORT_WIN="2.10"
  323. MERK_VERSION_WIN="0.18.3"
  324. QGIS_VERSION_WIN="2.18.19-1"
  325. QR_VERSION_WIN="2.4"
  326. GPSD_VERSION_WIN="0.2.0.0"
  327. fi
  328. OS_SALT_PATH="/srv/salt/gis_${OS}"
  329. compileLAStools ${OS_SALT_PATH}
  330. getOtherGIS ${OS_SALT_PATH}
  331. done
  332. unset LOCAL_DEVPKG_OLD_FLAG
  333. unset local_only
  334. unset winminions_present