|
| 1 | +#!/bin/bash - |
| 2 | +# |
| 3 | +# File: intstall.sh |
| 4 | +# |
| 5 | +# Description: A utility script that builds FORESEER project |
| 6 | +# |
| 7 | +# License: GPL3+ |
| 8 | +# |
| 9 | +# This program is free software; you can redistribute it and/or modify |
| 10 | +# it under the terms of the GNU General Public License as published by |
| 11 | +# the Free Software Foundation; either version 3 of the License, or |
| 12 | +# (at your option) any later version. |
| 13 | +# |
| 14 | +# This program is distributed in the hope that it will be useful, |
| 15 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | +# GNU General Public License for more details. |
| 18 | +# |
| 19 | +# You should have received a copy of the GNU General Public License |
| 20 | +# along with this program; if not, write to the Free Software |
| 21 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | +# |
| 23 | + |
| 24 | +# DEBUGGING |
| 25 | +set -e |
| 26 | +set -C # noclobber |
| 27 | + |
| 28 | +# INTERNAL VARIABLES AND INITIALIZATIONS |
| 29 | +readonly USERNAME="Fortran-FOSS-Programmers" |
| 30 | +readonly PROJECT="FOODIE" |
| 31 | +readonly GITHUB="https://github.com/$USERNAME/$PROJECT" |
| 32 | +readonly PROGRAM=`basename "$0"` |
| 33 | + |
| 34 | +function projectdownload () { |
| 35 | + if [ $VERBOSE -eq 1 ]; then |
| 36 | + echo "download project" |
| 37 | + fi |
| 38 | + |
| 39 | + if command -v $DOWNLOAD >/dev/null 2>&1; then |
| 40 | + if [ $VERBOSE -eq 1 ]; then |
| 41 | + echo " using $DOWNLOAD" |
| 42 | + fi |
| 43 | + else |
| 44 | + echo "error: $DOWNLOAD tool (to download project) not found" |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + |
| 48 | + if [ "$DOWNLOAD" == "git" ]; then |
| 49 | + git clone $GITHUB |
| 50 | + cd $PROJECT |
| 51 | + git submodule update --init |
| 52 | + cd - |
| 53 | + elif [ "$DOWNLOAD" == "wget" ]; then |
| 54 | + wget $(curl -s https://api.github.com/repos/$USERNAME/$PROJECT/releases/latest | grep 'browser_' | cut -d\" -f4) |
| 55 | + tar xf $PROJECT.tar.gz |
| 56 | + rm -f $PROJECT.tar.gz |
| 57 | + fi |
| 58 | + |
| 59 | + if [ $VERBOSE -eq 1 ]; then |
| 60 | + echo "project downloaded into: $PROJECT" |
| 61 | + fi |
| 62 | +} |
| 63 | + |
| 64 | +function projectbuild () { |
| 65 | + if [ $VERBOSE -eq 1 ]; then |
| 66 | + echo "build project" |
| 67 | + fi |
| 68 | + |
| 69 | + if [ "$BUILD" == "fobis" ]; then |
| 70 | + BUILD="FoBiS.py" |
| 71 | + fi |
| 72 | + |
| 73 | + if command -v $BUILD >/dev/null 2>&1; then |
| 74 | + if [ $VERBOSE -eq 1 ]; then |
| 75 | + echo " using $BUILD" |
| 76 | + fi |
| 77 | + else |
| 78 | + echo "error: $BUILD tool (to build project) not found" |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | + |
| 82 | + if [ "$BUILD" == "FoBiS.py" ]; then |
| 83 | + FoBiS.py build -mode static-gnu |
| 84 | + elif [ "$BUILD" == "make" ]; then |
| 85 | + make -j 1 STATIC=yes |
| 86 | + elif [ "$BUILD" == "cmake" ]; then |
| 87 | + mkdir -p static |
| 88 | + cd static |
| 89 | + cmake ../ |
| 90 | + cmake --build . |
| 91 | + cd ../ |
| 92 | + fi |
| 93 | +} |
| 94 | + |
| 95 | +function usage () { |
| 96 | + echo "Install script of $PROJECT" |
| 97 | + echo "Usage:" |
| 98 | + echo |
| 99 | + echo "$PROGRAM --help|-?" |
| 100 | + echo " Print this usage output and exit" |
| 101 | + echo |
| 102 | + echo "$PROGRAM --download|-d <arg> [--verbose|-v]" |
| 103 | + echo " Download the project" |
| 104 | + echo |
| 105 | + echo " --download|-d [arg] Download the project, arg=git|wget to download with git or wget respectively" |
| 106 | + echo " --verbose|-v Output verbose mode activation" |
| 107 | + echo |
| 108 | + echo "$PROGRAM --build|-b <arg> [--verbose|-v]" |
| 109 | + echo " Build the project" |
| 110 | + echo |
| 111 | + echo " --build|-b [arg] Build the project, arg=fobis|make|cmake to build with FoBiS.py, GNU Make or CMake respectively" |
| 112 | + echo " --verbose|-v Output verbose mode activation" |
| 113 | + echo |
| 114 | + echo "Examples:" |
| 115 | + echo |
| 116 | + echo "$PROGRAM --download git" |
| 117 | + echo "$PROGRAM --build make" |
| 118 | + echo "$PROGRAM --download wget --build cmake" |
| 119 | +} |
| 120 | + |
| 121 | +DOWNLOAD=0 |
| 122 | +BUILD=0 |
| 123 | +VERBOSE=0 |
| 124 | + |
| 125 | +# RETURN VALUES/EXIT STATUS CODES |
| 126 | +readonly E_BAD_OPTION=254 |
| 127 | + |
| 128 | +# PROCESS COMMAND-LINE ARGUMENTS |
| 129 | +if [ $# -eq 0 ]; then |
| 130 | + usage |
| 131 | + exit 0 |
| 132 | +fi |
| 133 | +while test $# -gt 0; do |
| 134 | + if [ x"$1" == x"--" ]; then |
| 135 | + # detect argument termination |
| 136 | + shift |
| 137 | + break |
| 138 | + fi |
| 139 | + case $1 in |
| 140 | + --download | -d ) |
| 141 | + shift |
| 142 | + DOWNLOAD="$1" |
| 143 | + shift |
| 144 | + ;; |
| 145 | + |
| 146 | + --build | -b ) |
| 147 | + shift |
| 148 | + BUILD="$1" |
| 149 | + shift |
| 150 | + ;; |
| 151 | + |
| 152 | + --verbose | -v ) |
| 153 | + shift |
| 154 | + VERBOSE=1 |
| 155 | + ;; |
| 156 | + |
| 157 | + -? | --help ) |
| 158 | + usage |
| 159 | + exit |
| 160 | + ;; |
| 161 | + |
| 162 | + -* ) |
| 163 | + echo "Unrecognized option: $1" >&2 |
| 164 | + usage |
| 165 | + exit $E_BAD_OPTION |
| 166 | + ;; |
| 167 | + |
| 168 | + * ) |
| 169 | + break |
| 170 | + ;; |
| 171 | + esac |
| 172 | +done |
| 173 | + |
| 174 | +if [ "$DOWNLOAD" != "0" ] && [ "$BUILD" == "0" ]; then |
| 175 | + projectdownload |
| 176 | +elif [ "$DOWNLOAD" == "0" ] && [ "$BUILD" != "0" ]; then |
| 177 | + projectbuild |
| 178 | +elif [ "$DOWNLOAD" != "0" ] && [ "$BUILD" != "0" ]; then |
| 179 | + projectdownload |
| 180 | + cd $PROJECT |
| 181 | + projectbuild |
| 182 | +fi |
| 183 | + |
| 184 | +exit 0 |
0 commit comments