1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/bin/bash
die()
{
  echo "FATAL ERROR: $* (status $?)" 1>&2
  exit 1
}

usage()
{
cat<<EOF
usage: $0 options

The script installs a Salome virtual application in a specified directory.
A desktop shortcut and a menu entry are added.

Options:
 -h    Show this message
 -a    Application directory (default is $HOME/salome/appli_V6_6_0)
 -d    Do not install desktop file
 -m    Do not install menu entry
 -D    Equivalent to -dm. Do not install desktop file and menu entry
 -l    Choose language (English or French, default is English)
 -p    Do not install default preference file
 -q    Quiet installation
 -v    Verbose mode
EOF
}

check_path()
{
  if test ! -z $1 ; then
    arr=$(echo $1 | tr ":" "
")
    for x in $arr 
    do
      if test ! -d $x ; then
       echo "Missing repertory: $x" 
      fi
    done
  fi
}

APPLIDIR=""
DESKTOP="y"
MENU="y"
LANGUAGE=""
PREFS="y"
QUIET=""
VERBOSE=""
while getopts ":ha:dmDl:pqv" OPTION
do
  case $OPTION in
    h)
      usage
      exit 1
      ;;
    a)
      APPLIDIR=$OPTARG
      ;;
    d)
      DESKTOP=""
      ;;
    m)
      MENU=""
      ;;
    D)
      DESKTOP=""
      MENU=""
      ;;
    l)
      LANGUAGE=$OPTARG
      ;;
    p)
      PREFS=""
      ;;
    q)
      QUIET="y"
      ;;
    v)
      VERBOSE="y"
      ;;
    \?)
      usage
      exit 1
      ;;
    :)
      echo "Option -$OPTARG requires an argument." >&2
      exit 1
      ;;
  esac
done

if test -z "$SALOMEDIR"; then
  SALOMEDIR=`python2 -c "import os; print os.path.normpath(os.path.dirname(os.path.abspath(os.path.realpath('$0'))))" 2>/dev/null`
fi

# Change this directory as wanted
DEFAULTAPPLIDIR=$HOME/salome/appli/V6_6_0

test -z "$APPLIDIR" && echo -n "Enter Salome virtual application directory [default=$DEFAULTAPPLIDIR] : " && read -e -p "" APPLIDIR
test -z "$APPLIDIR" && APPLIDIR=$DEFAULTAPPLIDIR
if test "$QUIET" = ""; then
  echo "Creating SALOME application in $APPLIDIR ..."
fi
mkdir -p $APPLIDIR || die "mkdir failed"

cd $APPLIDIR
sed "s#\${ROOT_SALOME}#${SALOMEDIR}#g" ${SALOMEDIR}/salome_prerequisites.sh > ${SALOMEDIR}/salome_prerequisites_appli.sh
sed "s#\${ROOT_SALOME}#${SALOMEDIR}#g" ${SALOMEDIR}/.config_appli_template.xml > config_appli.xml

KERNELDIR=`cat config_appli.xml |grep KERNEL|awk -v FS=\" '{print $4}'`
if test "${VERBOSE}" = "y"; then
  python2 ${KERNELDIR}/bin/salome/appli_gen.py
else
  python2 ${KERNELDIR}/bin/salome/appli_gen.py > appli_V6_6_0.log 2>&1
fi

cd $SALOMEDIR

# Install the menu and desktop files if requested
if test -e ${SALOMEDIR}/.salome_V6_6_0.desktop; then
  sed "s#SALOMEDIR#${SALOMEDIR}#g" ${SALOMEDIR}/.salome_V6_6_0.desktop > ${SALOMEDIR}/salome_V6_6_0.desktop
  sed -i "s#APPLIDIR#${APPLIDIR}#g" ${SALOMEDIR}/salome_V6_6_0.desktop
  sed -i "s#HOME#${HOME}#g" ${SALOMEDIR}/salome_V6_6_0.desktop
fi

if test -n "$MENU"; then
  if test -e ${SALOMEDIR}/salome_V6_6_0.desktop; then
    if test ! -d $HOME/.local/share/applications; then
      mkdir -p $HOME/.local/share/applications  || die "mkdir failed"
    fi
    desktop-file-install --dir=$HOME/.local/share/applications --vendor=salome --copy-name-to-generic-name                          --add-category=Education --add-category=Science --add-mime-type=application/x-hdf                           ${SALOMEDIR}/salome_V6_6_0.desktop > desktop-file-install-menu.log 2>&1
    chmod +x $HOME/.local/share/applications/salome_V6_6_0.desktop
  fi
fi

if test -n "$DESKTOP"; then
  DESKTOPDIR="$HOME/Desktop"
  if test ! -e "$DESKTOPDIR"; then
    DESKTOPDIR="$HOME/Bureau"
    if test ! -e "$DESKTOPDIR"; then
      echo "Desktop directory not found."
      DESKTOPDIR=""
    fi
  fi
  if test -n "${DESKTOPDIR}"; then
    if test -e ${SALOMEDIR}/salome_V6_6_0.desktop; then
    desktop-file-install --dir=${DESKTOPDIR} --vendor=salome --copy-name-to-generic-name                          --add-category=Education --add-category=Science --add-mime-type=application/x-hdf                           ${SALOMEDIR}/salome_V6_6_0.desktop > desktop-file-install-desktop.log 2>&1
    chmod +x ${DESKTOPDIR}/salome_V6_6_0.desktop
    fi
  fi
fi

# Install the preferences file if requested
if test -n "$PREFS"; then
  if test -e ${SALOMEDIR}/.config/SalomeApprc.6.6.0.default; then
    if test ! -d $HOME/.config/salome; then
      mkdir -p $HOME/.config/salome  || die "mkdir failed"
    else
      if test -e $HOME/.config/salome/SalomeApprc.6.6.0; then
        cp $HOME/.config/salome/SalomeApprc.6.6.0 $HOME/.config/salome/SalomeApprc.6.6.0.backup
      fi
      if test -e $HOME/.config/salome/SalomeMaterialrc; then
        cp $HOME/.config/salome/SalomeMaterialrc $HOME/.config/salome/SalomeMaterialrc.backup
      fi
    fi
    if test "$QUIET" = ""; then
      echo "Installing the preferences file in $HOME/.config/salome/SalomeApprc.6.6.0"
    fi
    cp ${SALOMEDIR}/.config/SalomeApprc.6.6.0.default $HOME/.config/salome
    cp ${SALOMEDIR}/.config/SalomeApprc.6.6.0.default $HOME/.config/salome/SalomeApprc.6.6.0
    echo "Installing the custom materials file in $HOME/.config/salome/SalomeApprc.6.6.0"
    cp ${SALOMEDIR}/.config/SalomeMaterialrc.default $HOME/.config/salome
    cp ${SALOMEDIR}/.config/SalomeMaterialrc.default $HOME/.config/salome/SalomeMaterialrc
  fi
fi

# Install CatalogResources file
if test "$QUIET" = ""; then
  echo "Installing the CatalogResources file in ${APPLIDIR}/CatalogResources.xml"
fi
cp ${SALOMEDIR}/.config/CatalogResources.xml.default ${APPLIDIR}
cp ${SALOMEDIR}/.config/CatalogResources.xml.default ${APPLIDIR}/CatalogResources.xml

# Change language if requested anf if the preferences file is installed
if test -n "$LANGUAGE" && test -n "$PREFS"; then
  if test -e $HOME/.config/salome/SalomeApprc.6.6.0; then
    if test "$QUIET" = ""; then
      echo "Changing the language to $LANGUAGE in the preferences file"
    fi
    sed -i -e 's#value="en"#value="'${LANGUAGE}'"#g' $HOME/.config/salome/SalomeApprc.6.6.0
  fi
fi

. salome_prerequisites.sh
. salome_modules.sh

# Put here additional commands after creation of the appli
# Replace the keyword: #APPLI_CUSTOM_COMMANDS

python2.6 ${SALOMEMECA_EXTRA_ROOT_DIR}/custom/postinstall_appli.py ${APPLIDIR}

# End of additional commands

# check paths
if test "$QUIET" = ""; then
  check_path ${LD_LIBRARY_PATH}
  check_path ${PATH}
  check_path ${PYTHONPATH}
else
  check_path ${LD_LIBRARY_PATH} 1>/dev/null 2>&1
  check_path ${PATH} 1>/dev/null 2>&1
  check_path ${PYTHONPATH} 1>/dev/null 2>&1
fi

# apply patches
if test -d .patches; then
  ./.patches/patch.sh
  # remove patch directory
  rm -rf .patches
fi

# apply post install script
python2.6 ./salome_post_install.py

if test "$QUIET" = ""; then
  echo "The SALOME application was successfully created."
  echo "To run the application:"
  echo "\$ ${APPLIDIR}/runAppli"
fi

#./runAppli $*