summaryrefslogtreecommitdiff
path: root/setup_native/scripts/install_linux.sh
blob: 7face6a570e432501197e1f9b7cccded80654716 (plain)
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
#!/bin/bash

error()
{
    echo
    printf "ERROR:\t$1\n"
    echo
    echo "User Mode Installation script for developer and knowledgeable early access tester"
    echo
    echo "This installation method is not intended for use in a production environment!"
    echo "Using this script is unsupported and completely at your own risk"
    echo
    echo "Usage:" $0 "<rpm-source-dir> <office-installation-dir> [-l]"
    echo "    <rpm-source-dir>:       directory *only* containing the Linux rpm packages to be installed"
    echo "    <inst-destination-dir>: directory to where the office will get installed into"
    echo "    -l:                     optional parameter to create a link \"soffice\" in $HOME"
    echo
    exit 2
}

cannot_install()
{
    echo
    printf "ERROR:\tCannot proceed with the installation\n"
    printf "\t$1\n"
    echo
    exit 2
}

#
# expect either two or three arguments
#

if [ \( $# -ne 2 -a $# -ne 3 \) -o -z "$1" -o -z "$2" ]
then
    error "Wrong number of arguments"
fi

#
# this script is for userland not for root
#

if [ $UID -eq 0 ]
then
    error "This script is for installation without administrative rights only\n\tPlease use rpm to install as root"
fi

#
# Evaluate command line arguments
#

PACKAGE_PATH=$1
INSTALLDIR=$2

LINK="nolink"
if [ $# -eq 3 ]
then
  LINK=$3
fi

if [ ! -d $PACKAGE_PATH ]
then
    error "Directory $PACKAGE_PATH does not exist"
fi

if [ ! "${INSTALLDIR:0:1}" = "/" ]
then
    error "Invalid installation directory $INSTALLDIR, has to be an absolute path"
fi

#
# Check and get the list of packages to install
#

RPMLIST=`find $PACKAGE_PATH -type f -name "*.rpm" ! -name "*-core*" ! -name "*-menus-*" ! -name "adabas*" ! -name "jre*" ! -name "*-gnome*" -print`
CORERPMLIST=`find $PACKAGE_PATH -type f -name "*.rpm" -name "*-core*" -print`
CORERPM01=`find $PACKAGE_PATH -type f -name "*.rpm" -name "*-core01-*" -print`
PREFIX=`rpm -qlp $CORERPM01 | head -n1`

if [ -z "$CORERPM01" ]
then
    error "No core package found in directory $PACKAGE_PATH"
fi

# Do not install gnome-integration package on systems without GNOME
# check for /bin/rpm first, otherwise the rpm database is most likly empty anyway
if [ -x /bin/rpm ]
then
  GNOMERPM=`find $PACKAGE_PATH -type f -name "*.rpm" -name "*-gnome*" -print`
  /bin/rpm -i --test $GNOMERPM $CORERPM 2>/dev/null || GNOMERPM=""
fi

echo "Packages found:"
for i in $CORERPMLIST $RPMLIST $GNOMERPM; do
  echo `basename $i`
done

#
# Check/Create installation directory
#

# We expect that $INSTALLDIR does not exist, however if it is empty we ignore it
if [ -d $INSTALLDIR ]
then
    # if it is not empty we cannot rm it (might be a permission problem as well)
    rmdir $INSTALLDIR
fi
if [ -d $INSTALLDIR ]
then
    cannot_install "Directory $INSTALLDIR exists and is not empty or cannot be removed"
fi

# We expect that rpm_DB_PATH does not exist, however if it is empty we ignore it
#RPM_DB_PATH=$HOME/.RPM_OFFICEDATABASE
RPM_DB_PATH=$INSTALLDIR/.RPM_OFFICEDATABASE

#
# Perform the installation
#

echo "####################################################################"
echo "#     Installation of the found packages                           #"
echo "####################################################################"
echo
echo "Path to the database:       " $RPM_DB_PATH
echo "Path to the packages:       " $PACKAGE_PATH
echo "Path to the installation:   " $INSTALLDIR

# Creating directories
mkdir -p $RPM_DB_PATH
# XXX why ? XXX
chmod 700 $RPM_DB_PATH
if [ ! -d $RPM_DB_PATH ]
then
    cannot_install "Unable to create directory $RPM_DB_PATH"
fi

# Creating RPM database and initializing
rpm --initdb --dbpath $RPM_DB_PATH
echo "Installing the RPMs"

# inject a second slash to the last path segment to avoid rpm 3 concatination bug
NEWPREFIX=`echo $INSTALLDIR | sed -e 's|\(.*\)\/\(.*\)|\1\/\/\2|'`
rpm --install --nodeps -vh --relocate $PREFIX=$NEWPREFIX --dbpath $RPM_DB_PATH $CORERPMLIST
rpm --install --nodeps -vh --relocate $PREFIX=$NEWPREFIX --dbpath $RPM_DB_PATH $RPMLIST $GNOMERPM

#
# Create a link into the users home directory
#

if [ "$LINK" = "-l" ]
then
  echo
  echo "Creating link from $INSTALLDIR/program/soffice to $HOME/soffice"
  rm -f $HOME/soffice
  ln -s $INSTALLDIR/program/soffice $HOME/soffice
fi

# patch the "bootstraprc" to create a self-containing installation
mv $INSTALLDIR/program/bootstraprc $INSTALLDIR/program/bootstraprc.orig
sed 's/UserInstallation=$SYSUSERCONFIG\/.staroffice8/UserInstallation=$ORIGIN\/..\/UserInstallation/g' $INSTALLDIR/program/bootstraprc.orig > $INSTALLDIR/program/bootstraprc

echo
echo "Installation done ..."

exit 0