Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.framework / org.gvsig.andami / src / main / resources-application / tools / make-portable @ 42970

History | View | Annotate | Download (11.3 KB)

1 41792 jjdelcerro
#!/bin/bash
2
#############################################################################
3
# Require la siguiente estructura de carpetas:
4
#
5
# - packages
6
#   - custom (carpeta con los paquetes adicionales a incluir en la portable)
7
#   - exclude (fichero con los codigos de paquetes a excluir)
8
# - standard
9 42767 jjdelcerro
#   - gvSIG-desktop*-lin-x86-online.zip
10
#   - gvSIG-desktop*-lin-x86_64-online.zip
11
#   - gvSIG-desktop*-win-x86-online.zip
12
#   - gvSIG-desktop*-win-x86_64-online.zip
13 41792 jjdelcerro
#   - gvSIG-desktop*-lin-x86.gvspkg
14
#   - gvSIG-desktop*-lin-x86_64.gvspkg
15
#   - gvSIG-desktop*-win-x86.gvspkg
16 42767 jjdelcerro
#   - gvSIG-desktop*-win-x86_64.gvspkg
17 42759 jjdelcerro
# - patchs
18 41792 jjdelcerro
#   - patchs.sh (se ejecuta antes que los scripts de ant y zipear la instalacion)
19
# - make-portable
20
#
21
# Y se ejecutara el archivo "make-portable" desde ese directorio.
22
#
23
# Al final se crean las carpetas y archivos:
24
#
25
# - target/gvsig-desktop-VERSION-lin-x86
26
# - target/gvsig-desktop-VERSION-lin-x86_64
27
# - target/gvsig-desktop-VERSION-win-x86
28
#
29
# - target/gvsig-desktop-VERSION-lin-x86.zip
30
# - target/gvsig-desktop-VERSION-lin-x86_64.zip
31
# - target/gvsig-desktop-VERSION-win-x86.zip
32
#
33
##############################################################################
34
35 42948 jjdelcerro
#set -x
36 41792 jjdelcerro
37
#function handle_error() {
38
#    echo "FAILED: line $1, exit code $2"
39
#    exit 1
40
#}
41
#
42 42759 jjdelcerro
#trap 'handle_error $LINENO $?' ERR
43 41792 jjdelcerro
44
set -e
45
46
cd "$(dirname $0)"
47
SCRIPT_NAME=$(basename $0)
48
49
export BASEFOLDER="$PWD"
50
export TARGET="$BASEFOLDER/target"
51
export PATCHSFOLDER=$BASEFOLDER/patchs
52
53
function logger_info() {
54
    echo $*
55
}
56
57
function logger_warn() {
58
    echo $*
59
}
60
61
function get_package_info() {
62 42947 jjdelcerro
  PACKAGE_PATH="$1"
63
64
  #
65
  # A veces en el zip los archivos comienzan por "/" y otras no.
66
  # Asi que lo primero que hacemos es comprobar eso.
67
  #
68
  local prefix=""
69
  local line=""
70
  # El flag -Z1 muestra los ficheros unicamente, similar a -l pero
71
  # sin ningun tipo de cabezaras, resumenes o informacion adicional
72
  # por cada fichero. Solo el nombre con ruta de cada fichero.
73
  local x=$(unzip -Z1 "$PACKAGE_PATH" "*/package.info")
74
  if [ "${x:0:1}" == "/" ] ; then
75
    prefix="/"
76
  fi
77
  #
78
  # Usamos una redireccion y no un pipe ya que los elementos de un pipe se
79
  # ejecutan en un subshell separado y la asignacion a las variables dentro del
80
  # while solo tendria efecto en ese subshell.
81
  #
82
  # Atencion al parametro W del unzip, ya que si lo quitamos y en el zip hay
83
  # mas de un "package.info" nos los sacaria todos, y los resultados no serian
84
  # los esperados. Solo tenemos que leer el "package.info" que hay en el primer
85
  # subdirectorio del zip.
86
  # Con el tr intentamos eliminar lo \r ya que algunos package.info generados
87
  # desde windows tienen \r.
88
  #
89
  PACKE_INFO_CONTENTS=$(unzip -lpWc "$PACKAGE_PATH" "${prefix}*/package.info" | tr -d '\r')
90
  while read line ; do
91
    case "$line" in
92
    type=*)
93
      PACKAGE_TYPE=${line#type=}
94
      ;;
95
    version=*)
96
      PACKAGE_VERSION=${line#version=}
97
      ;;
98
    code=*)
99
      PACKAGE_CODE=${line#code=}
100
      ;;
101
    esac
102
  done <<END_OF_PACKAGE_INFO_CONTENTS
103
$PACKE_INFO_CONTENTS
104
END_OF_PACKAGE_INFO_CONTENTS
105 41792 jjdelcerro
}
106
107 42947 jjdelcerro
108 41792 jjdelcerro
function install_symbols() {
109
    INSTALL_FOLDER="$1"
110
111
    cd "$INSTALL_FOLDER"
112
    mkdir -p "home/gvSIG/plugins/org.gvsig.app.mainplugin/Symbols"
113
    cd "home/gvSIG/plugins/org.gvsig.app.mainplugin/Symbols"
114
    rm -rf "$PACKAGE_CODE"
115 42934 jjdelcerro
    logger_info "Install symbols $PACKAGE_CODE $PACKAGE_VERSION"
116
    unzip -qq "$PACKAGE_PATH" 2>&1 | sed "/warning:  stripped absolute path/d"
117 41792 jjdelcerro
}
118
119 42934 jjdelcerro
function install_script() {
120
    INSTALL_FOLDER="$1"
121
122
    cd "$INSTALL_FOLDER"
123
    mkdir -p "home/gvSIG/plugins/org.gvsig.scripting.app.mainplugin/scripts/addons"
124
    cd "home/gvSIG/plugins/org.gvsig.scripting.app.mainplugin/scripts/addons"
125
    rm -rf "$PACKAGE_CODE"
126
    logger_info "Install script $PACKAGE_CODE $PACKAGE_VERSION"
127
    unzip -qq "$PACKAGE_PATH" 2>&1 | sed "/warning:  stripped absolute path/d"
128
}
129
130 41792 jjdelcerro
function install_jCRS_EPSG() {
131
    INSTALL_FOLDER="$1"
132
133
    cd "$INSTALL_FOLDER"
134
    mkdir -p "gvSIG/extensiones/org.gvsig.projection.app.jcrs/db/EPSG"
135
    cd "gvSIG/extensiones/org.gvsig.projection.app.jcrs/db/EPSG"
136
    rm -rf "$PACKAGE_CODE"
137 42934 jjdelcerro
    logger_info "Install jCRS EPSG data base $PACKAGE_CODE $PACKAGE_VERSION"
138
    unzip -qq "$PACKAGE_PATH" 2>&1 | sed "/warning:  stripped absolute path/d"
139 41792 jjdelcerro
}
140
141
function install_plugin() {
142
    INSTALL_FOLDER="$1"
143
144
    cd "$INSTALL_FOLDER/gvSIG/extensiones"
145
    rm -rf "$PACKAGE_CODE"
146 42934 jjdelcerro
    logger_info "Install plugin $PACKAGE_CODE $PACKAGE_VERSION"
147
    unzip -qq "$PACKAGE_PATH" 2>&1 | sed "/warning:  stripped absolute path/d"
148 41792 jjdelcerro
}
149
150
function install_translations() {
151
    INSTALL_FOLDER="$1"
152
153
    cd "$INSTALL_FOLDER/i18n"
154
    rm -rf "$PACKAGE_CODE"
155 42934 jjdelcerro
    logger_info "Install translations $PACKAGE_CODE $PACKAGE_VERSION"
156
    unzip -qq "$PACKAGE_PATH" 2>&1 | sed "/warning:  stripped absolute path/d"
157 41792 jjdelcerro
}
158
159
function run_plugins_install_scripts() {
160
    INSTALL_FOLDER="$1"
161 42759 jjdelcerro
162 41792 jjdelcerro
    logger_info ""
163
    logger_info "Running plugins install scripts"
164
    cd "$INSTALL_FOLDER/gvSIG/extensiones"
165
    for PLUGIN_CODE in *
166
    do
167
        if [ -f "$INSTALL_FOLDER/gvSIG/extensiones/$PLUGIN_CODE/install/install.xml" ] ; then
168
            logger_info "Running custom install script of $PLUGIN_CODE"
169
            cd $INSTALL_FOLDER
170
            ant -Dgvsig_dir="$INSTALL_FOLDER" -Dextensions_dir="$INSTALL_FOLDER/gvSIG/extensiones" -f "$INSTALL_FOLDER/gvSIG/extensiones/$PLUGIN_CODE/install/install.xml"
171
        fi
172
    done
173
}
174
175
function install_packages() {
176
    INSTALL_FOLDER="$1"
177
    PACKAGES_FOLDER="$2"
178 42759 jjdelcerro
179 41792 jjdelcerro
    logger_info ""
180
    logger_info "Processing $(basename $PACKAGES_FOLDER) packages"
181
    for PACKAGE_PATH in $PACKAGES_FOLDER/*.gvspkg
182
    do
183 41933 jjdelcerro
      if [ -f "$PACKAGE_PATH" ] ; then
184
        PACKAGE_NAME="$(basename $PACKAGE_PATH)"
185 42947 jjdelcerro
        get_package_info $PACKAGE_PATH
186 42934 jjdelcerro
        if include_package $PACKAGE_CODE ; then
187
          case $PACKAGE_TYPE in
188
          plugin)
189
            install_plugin "$INSTALL_FOLDER"
190
            ;;
191
          jCRS_EPSG)
192
            install_jCRS_EPSG "$INSTALL_FOLDER"
193
            ;;
194
          symbols)
195
            install_symbols "$INSTALL_FOLDER"
196
            ;;
197
          Script)
198
            install_script "$INSTALL_FOLDER"
199
            ;;
200
          translations)
201
            install_translations "$INSTALL_FOLDER"
202
            ;;
203 42935 jjdelcerro
          *)
204
            echo "ERROR: Type of package $PACKAGE_TYPE of $PACKAGE_NAME not supported."
205
            exit 1
206
            ;;
207 42934 jjdelcerro
          esac
208 41933 jjdelcerro
        else
209 42934 jjdelcerro
          logger_info "Exclude package $PACKAGE_CODE"
210
          cp "$PACKAGE_PATH" "$INSTALL_FOLDER/install"
211 41933 jjdelcerro
        fi
212 41792 jjdelcerro
      fi
213
    done
214
}
215
216
function include_package() {
217
    set +e
218
    egrep  "^$1\$" "$BASEFOLDER/packages/excludes" >/dev/null
219
    FOUND=$?
220
    set -e
221
    if [ "$FOUND" == 1 ] ; then
222
        return 0
223
    fi
224
    return 1
225
}
226
227
228
function remove_excluded_packages() {
229
    logger_info "Checking plugins to remove"
230
    cd "$INSTALL_FOLDER/gvSIG/extensiones"
231
    while read line; do
232 42759 jjdelcerro
        if [ -d "$line" ] ; then
233 41792 jjdelcerro
            logger_info "Removing plugin $line"
234
            rm -rf "$line"
235
        fi
236
    done < "$BASEFOLDER/packages/excludes"
237
}
238
239 42759 jjdelcerro
function install_portable_configuration_files() {
240 41792 jjdelcerro
    logger_info "Install portable configuration file (gvSIG.config)"
241
    chmod a+x "$INSTALL_FOLDER/gvSIG.sh"
242
}
243
244 41933 jjdelcerro
function zipfolder() {
245
    echo zip -qyr9 "$1" "$2"
246
    if type zip >/dev/null 2>/dev/null
247
    then
248 42767 jjdelcerro
  zip -qyr9 "$1" "$2"
249 41933 jjdelcerro
    else
250
      echo "
251 42759 jjdelcerro
252 42767 jjdelcerro
  WARNING: zip command not found.
253
           $1 not compressed.
254 42759 jjdelcerro
255 41933 jjdelcerro
"
256
    fi
257
}
258
259 42952 jjdelcerro
function expandsVarsOnFile() {
260
  sed 's/\${INSTALL_DRIVE}/./
261
s/\${INSTALL_PATH}/./' "$1" >"$1.tmp"
262
  mv "$1.tmp" "$1"
263
}
264
265 41792 jjdelcerro
function mkdist() {
266
    cd $BASEFOLDER/standard
267
268 42947 jjdelcerro
    # OS code (lin/win/darwin) + distribution + version
269 41792 jjdelcerro
    export PORTABLE_OS="$1"
270 42947 jjdelcerro
271
    # OS name (linux/windows/darwin) for show only
272 42932 jjdelcerro
    export PORTABLE_OSNAME="$2"
273 42947 jjdelcerro
274
    # Architectute X86, x86_64
275 42932 jjdelcerro
    export PORTABLE_PLATFORM="$3"
276 42912 fdiaz
277 42947 jjdelcerro
    # OS used to locate the online zip
278
    export ONLINE_OS
279
    case "$PORTABLE_OSNAME" in
280
    darwin)
281
        ONLINE_OS="lin"
282
        ;;
283
    linux)
284
        ONLINE_OS="lin"
285
        ;;
286
    windows)
287
        ONLINE_OS="win"
288
        ;;
289
    *)
290
        ONLINE_OS="$PORTABLE_OS"
291
        ;;
292
    esac
293 42912 fdiaz
294
    export PORTABLE_VERSION=$(expr *${ONLINE_OS}-${PORTABLE_PLATFORM}-online.zip : "gvSIG-desktop-\\([0-9.]*-[0-9]*\\)")
295
    export PORTABLE_STATUS=$(expr *${ONLINE_OS}-${PORTABLE_PLATFORM}-online.zip : "gvSIG-desktop-[0-9.]*-[0-9]*-\\([a-zA-Z]*[0-9]*\)")
296 42769 jjdelcerro
    export PORTABLE_NAME="gvSIG-desktop-$PORTABLE_VERSION-${PORTABLE_STATUS}-${PORTABLE_OS}-${PORTABLE_PLATFORM}"
297 42759 jjdelcerro
298 41792 jjdelcerro
    export INSTALL_FOLDER="$TARGET/$PORTABLE_NAME"
299
300
    logger_info "Removing previous files"
301
    rm -rf "$TARGET/gvsig-desktop"
302
    rm -rf "$INSTALL_FOLDER"
303
    rm -f  "$TARGET/${PORTABLE_NAME}.zip"
304
    rm -rf "$TARGET/packages-${PORTABLE_OS}-${PORTABLE_PLATFORM}"
305 42759 jjdelcerro
306 41792 jjdelcerro
    logger_info "Uncompressing ${PORTABLE_OSNAME} base files"
307
    cd $TARGET
308 42759 jjdelcerro
    mkdir $PORTABLE_NAME
309
    cd $PORTABLE_NAME
310 42912 fdiaz
    unzip -qq "$BASEFOLDER/standard/gvSIG-desktop-$PORTABLE_VERSION-$PORTABLE_STATUS-${ONLINE_OS}-${PORTABLE_PLATFORM}-online.zip"
311 42769 jjdelcerro
    #mv gvSIG-desktop-${PORTABLE_VERSION} $PORTABLE_NAME
312 41792 jjdelcerro
313
    logger_info "Uncompressing ${PORTABLE_OSNAME}-${PORTABLE_PLATFORM} package set"
314
    mkdir -p "$TARGET/packages-${PORTABLE_OS}-${PORTABLE_PLATFORM}"
315
    cd "$TARGET/packages-${PORTABLE_OS}-${PORTABLE_PLATFORM}"
316
    unzip -qq "$BASEFOLDER/standard/gvSIG-desktop-${PORTABLE_VERSION}-${PORTABLE_STATUS}-${PORTABLE_OS}-${PORTABLE_PLATFORM}.gvspks"
317 42759 jjdelcerro
318 42767 jjdelcerro
    echo Removing package "$TARGET/packages-${PORTABLE_OS}-${PORTABLE_PLATFORM}/gvSIG-desktop-2.3.0-org.gvsig.gdal.app.mainplugin-"*-all-all-j1_7.gvspkg
319
    rm -f "$TARGET/packages-${PORTABLE_OS}-${PORTABLE_PLATFORM}/gvSIG-desktop-2.3.0-org.gvsig.gdal.app.mainplugin-"*-all-all-j1_7.gvspkg
320 42912 fdiaz
321 41792 jjdelcerro
    install_packages "$INSTALL_FOLDER" "$TARGET/packages-${PORTABLE_OS}-${PORTABLE_PLATFORM}"
322
323
    install_packages "$INSTALL_FOLDER" "$BASEFOLDER/packages/custom"
324
325 42759 jjdelcerro
    install_portable_configuration_files
326 41792 jjdelcerro
327
    remove_excluded_packages
328 42759 jjdelcerro
329 41792 jjdelcerro
    if [ -f $PATCHSFOLDER/patchs.sh ] ; then
330
        chmod a+x $PATCHSFOLDER/patchs.sh
331
        logger_info "Appling patch to the instalation."
332
        source $PATCHSFOLDER/patchs.sh
333
    fi
334 42759 jjdelcerro
335 41792 jjdelcerro
    run_plugins_install_scripts $INSTALL_FOLDER
336 42759 jjdelcerro
337 42952 jjdelcerro
    case "$PORTABLE_OSNAME" in
338
    darwin)
339 42932 jjdelcerro
        mkdir "$INSTALL_FOLDER/Contents"
340
        mkdir "$INSTALL_FOLDER/Contents/MacOS"
341
        echo '#!/bin/bash
342
x=$(dirname $0)
343
x=$(dirname $x)
344
x=$(dirname $x)
345
exec "$x/gvSIG.sh"
346
' >"$INSTALL_FOLDER/Contents/MacOS/${PORTABLE_NAME}"
347
        chmod a+x "$INSTALL_FOLDER/Contents/MacOS/${PORTABLE_NAME}"
348
        mv "$INSTALL_FOLDER" "${INSTALL_FOLDER}.app"
349
        INSTALL_FOLDER="${INSTALL_FOLDER}.app"
350
        PORTABLE_NAME="${PORTABLE_NAME}.app"
351 42952 jjdelcerro
        ;;
352
    win)
353 42970 fdiaz
        expandsVarsOnFile "${INSTALL_FOLDER}/gvsig-desktop.vbs"
354
        expandsVarsOnFile "${INSTALL_FOLDER}/gvsig-desktop.cmd"
355
        expandsVarsOnFile "${INSTALL_FOLDER}/gvsig-package-installer.cmd"
356 42952 jjdelcerro
        ;;
357
    esac
358 42970 fdiaz
359 41792 jjdelcerro
    logger_info "Compresing ${PORTABLE_OSNAME}-${PORTABLE_PLATFORM} portable (this take a moment)"
360
    cd "$TARGET"
361 41933 jjdelcerro
    zipfolder "${PORTABLE_NAME}.zip" "${PORTABLE_NAME}"
362 42759 jjdelcerro
363 41792 jjdelcerro
    logger_info "Removing temporary package folder"
364
    rm -rf $TARGET/packages-${PORTABLE_OS}-${PORTABLE_PLATFORM}
365 42759 jjdelcerro
366 41792 jjdelcerro
    logger_info "${PORTABLE_OSNAME}-${PORTABLE_PLATFORM} portable created."
367
}
368
369
370
function main() {
371 42947 jjdelcerro
    mkdist win windows x86
372
    mkdist darwin_macos_10.11 darwin x86_64
373
    mkdist lin_ubuntu_16.04 linux x86_64
374 41792 jjdelcerro
    mkdist lin linux x86
375 42759 jjdelcerro
    mkdist lin linux x86_64
376
    mkdist win windows x86_64
377 41792 jjdelcerro
    echo "Creation ended"
378
}
379
380
mkdir -p "$TARGET"
381
main | tee "$TARGET/${SCRIPT_NAME}.log"