Skip to content

Commit

Permalink
Fix the app update
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-antonyuk committed Aug 18, 2021
1 parent 102bc5f commit 366f989
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 76 deletions.
83 changes: 57 additions & 26 deletions build/install/OneClickInstall/install-Debian/install-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,13 @@ cat<<EOF
EOF
apt-get -y update

if [ "$COMMUNITY_SERVER_INSTALLED" = "true" ]; then
ENVIRONMENT="$(cat /lib/systemd/system/${product}-api.service | grep -oP 'ENVIRONMENT=\K.*')"
USER_CONNECTIONSTRING=$(json -f /etc/onlyoffice/${product}/appsettings.$ENVIRONMENT.json ConnectionStrings.default.connectionString)
MYSQL_SERVER_HOST=$(echo $USER_CONNECTIONSTRING | grep -oP 'Server=\K.*' | grep -o '^[^;]*')
MYSQL_SERVER_DB_NAME=$(echo $USER_CONNECTIONSTRING | grep -oP 'Database=\K.*' | grep -o '^[^;]*')
MYSQL_SERVER_USER=$(echo $USER_CONNECTIONSTRING | grep -oP 'User ID=\K.*' | grep -o '^[^;]*')
MYSQL_SERVER_PORT=$(echo $USER_CONNECTIONSTRING | grep -oP 'Port=\K.*' | grep -o '^[^;]*')
MYSQL_ROOT_PASS=$(echo $USER_CONNECTIONSTRING | grep -oP 'Password=\K.*' | grep -o '^[^;]*')
fi

if [ "$DOCUMENT_SERVER_INSTALLED" = "false" ]; then
DS_PORT=${DS_PORT:-8083};

DS_DB_HOST=localhost;
DS_DB_NAME=$DS_COMMON_NAME;
DS_DB_USER=$DS_COMMON_NAME;
DS_DB_PWD=$DS_COMMON_NAME;

DS_JWT_ENABLED=${DS_JWT_ENABLED:-true};
DS_JWT_SECRET="$(cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 12)";
DS_JWT_HEADER="AuthorizationJwt";

if ! su - postgres -s /bin/bash -c "psql -lqt" | cut -d \| -f 1 | grep -q ${DS_DB_NAME}; then
su - postgres -s /bin/bash -c "psql -c \"CREATE DATABASE ${DS_DB_NAME};\""
Expand All @@ -43,15 +29,12 @@ if [ "$DOCUMENT_SERVER_INSTALLED" = "false" ]; then
echo ${package_sysname}-documentserver $DS_COMMON_NAME/db-pwd select $DS_DB_PWD | sudo debconf-set-selections
echo ${package_sysname}-documentserver $DS_COMMON_NAME/db-user $DS_DB_USER | sudo debconf-set-selections
echo ${package_sysname}-documentserver $DS_COMMON_NAME/db-name $DS_DB_NAME | sudo debconf-set-selections
echo ${package_sysname}-documentserver-de $DS_COMMON_NAME/jwt-enabled select ${DS_JWT_ENABLED} | sudo debconf-set-selections
echo ${package_sysname}-documentserver-de $DS_COMMON_NAME/jwt-secret select ${DS_JWT_SECRET} | sudo debconf-set-selections
echo ${package_sysname}-documentserver-de $DS_COMMON_NAME/jwt-header select ${DS_JWT_HEADER} | sudo debconf-set-selections
echo ${package_sysname}-documentserver-ee $DS_COMMON_NAME/jwt-enabled select ${DS_JWT_ENABLED} | sudo debconf-set-selections
echo ${package_sysname}-documentserver-ee $DS_COMMON_NAME/jwt-secret select ${DS_JWT_SECRET} | sudo debconf-set-selections
echo ${package_sysname}-documentserver-ee $DS_COMMON_NAME/jwt-header select ${DS_JWT_HEADER} | sudo debconf-set-selections


apt-get install -yq ${package_sysname}-documentserver
elif [ "$UPDATE" = "true" ] && [ "$DOCUMENT_SERVER_INSTALLED" = "true" ]; then
apt-get install -y --only-upgrade ${package_sysname}-documentserver
fi

NGINX_ROOT_DIR="/etc/nginx"

NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-$(grep processor /proc/cpuinfo | wc -l)};
Expand All @@ -72,16 +55,63 @@ else
systemctl reload nginx
fi

if [ "$APPSERVER_INSTALLED" = "false" ]; then
APPSERVER_INSTALLED_VERSION=$(apt-cache policy ${product} | awk 'NR==2{print $2}')
APPSERVER_LATEST_VERSION=$(apt-cache policy ${product} | awk 'NR==3{print $2}')
if [ "$APPSERVER_INSTALLED_VERSION" != "$APPSERVER_LATEST_VERSION" ]; then
APPSERVER_NEED_UPDATE="true"
fi


apt-get install -y ${product}
apt-get install -y ${product} #Fix error 'Failed to fetch'
if [ "$APPSERVER_INSTALLED" = "false" ]; then
${package_manager} install -y ${product}
${package_manager} install -y ${product} #Fix error 'Failed to fetch'
elif [ "$APPSERVER_NEED_UPDATE" = "true" ];
ENVIRONMENT="$(cat /lib/systemd/system/${product}-api.service | grep -oP 'ENVIRONMENT=\K.*')"
USER_CONNECTIONSTRING=$(json -f /etc/onlyoffice/${product}/appsettings.$ENVIRONMENT.json ConnectionStrings.default.connectionString)
MYSQL_SERVER_HOST=$(echo $USER_CONNECTIONSTRING | grep -oP 'Server=\K.*' | grep -o '^[^;]*')
MYSQL_SERVER_DB_NAME=$(echo $USER_CONNECTIONSTRING | grep -oP 'Database=\K.*' | grep -o '^[^;]*')
MYSQL_SERVER_USER=$(echo $USER_CONNECTIONSTRING | grep -oP 'User ID=\K.*' | grep -o '^[^;]*')
MYSQL_SERVER_PORT=$(echo $USER_CONNECTIONSTRING | grep -oP 'Port=\K.*' | grep -o '^[^;]*')
MYSQL_ROOT_PASS=$(echo $USER_CONNECTIONSTRING | grep -oP 'Password=\K.*' | grep -o '^[^;]*')

expect << EOF || true
set timeout -1
log_user 1
spawn ${package_manager} install -y --only-upgrade ${product} elasticsearch=${ELASTIC_VERSION}
expect {
"*** elasticsearch.yml (Y/I/N/O/D/Z)" {
send "\025Y\r"
expect {
"*** jvm.options (Y/I/N/O/D/Z)" {
send "\025Y\r"
}
"/etc/elasticsearch/elasticsearch.yml" {}
}
}
"*** jvm.options (Y/I/N/O/D/Z)" {
send "\025Y\r"
}
}
expect eof
EOF
fi

if [ "${APPSERVER_INSTALLED}" = "false" ] || ["$APPSERVER_NEED_UPDATE" = "true"]; then
expect << EOF
set timeout -1
log_user 1
spawn /usr/bin/${product}-configuration.sh
if { "${UPDATE}" == "true" } {
spawn ${product}-configuration.sh -e ${ENVIRONMENT}
} else {
spawn ${product}-configuration.sh
}
expect -re "Database host:"
send "\025$MYSQL_SERVER_HOST\r"
Expand All @@ -92,10 +122,11 @@ expect << EOF
send "\025$MYSQL_SERVER_USER\r"
expect -re "Database password:"
send "\025$MYSQL_SERVER_PASS\r"
send "\025$MYSQL_ROOT_PASS\r"
expect eof
EOF
APPSERVER_INSTALLED="true";
fi

echo ""
Expand Down
6 changes: 4 additions & 2 deletions build/install/OneClickInstall/install-Debian/install-preq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ fi
locale-gen en_US.UTF-8

# add elasticsearch repo
ELASTIC_VERSION="7.13.1"
ELASTIC_DIST=$(echo $ELASTIC_VERSION | awk '{ print int($1) }')
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | tee /etc/apt/sources.list.d/elastic-7.x.list
echo "deb https://artifacts.elastic.co/packages/${ELASTIC_DIST}.x/apt stable main" | tee /etc/apt/sources.list.d/elastic-${ELASTIC_DIST}.x.list

# add nodejs repo
curl -sL https://deb.nodesource.com/setup_12.x | bash -
Expand Down Expand Up @@ -180,7 +182,7 @@ if [ ! -e /usr/bin/json ]; then
fi
if ! dpkg -l | grep -q "elasticsearch"; then
apt-get install -yq elasticsearch=7.13.1
apt-get install -yq elasticsearch=${ELASTIC_VERSION}
fi
# disable apparmor for mysql
Expand Down
79 changes: 36 additions & 43 deletions build/install/OneClickInstall/install-RedHat/install-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@ if [ "${MYSQL_FIRST_TIME_INSTALL}" = "true" ]; then
fi
fi

if [ "${UPDATE}" = "true" ] && [ "${$APPSERVER_INSTALLED}" = "true" ]; then
ENVIRONMENT="$(cat /lib/systemd/system/${product}-api.service | grep -oP 'ENVIRONMENT=\K.*')"
USER_CONNECTIONSTRING=$(json -f /etc/onlyoffice/${product}/appsettings.$ENVIRONMENT.json ConnectionStrings.default.connectionString)
MYSQL_SERVER_HOST=$(echo $USER_CONNECTIONSTRING | grep -oP 'Server=\K.*' | grep -o '^[^;]*')
MYSQL_SERVER_DB_NAME=$(echo $USER_CONNECTIONSTRING | grep -oP 'Database=\K.*' | grep -o '^[^;]*')
MYSQL_SERVER_USER=$(echo $USER_CONNECTIONSTRING | grep -oP 'User ID=\K.*' | grep -o '^[^;]*')
MYSQL_SERVER_PORT=$(echo $USER_CONNECTIONSTRING | grep -oP 'Port=\K.*' | grep -o '^[^;]*')
MYSQL_ROOT_PASS=$(echo $USER_CONNECTIONSTRING | grep -oP 'Password=\K.*' | grep -o '^[^;]*')
fi

if [ "$DOCUMENT_SERVER_INSTALLED" = "false" ]; then
declare -x DS_PORT=8083

Expand Down Expand Up @@ -117,11 +107,6 @@ expect << EOF
expect -re "Password"
send "\025$DS_DB_PWD\r"
if { "${INSTALLATION_TYPE}" == "ENTERPRISE" || "${INSTALLATION_TYPE}" == "DEVELOPER" } {
expect "Configuring redis access..."
send "\025$DS_REDIS_HOST\r"
}
expect "Configuring AMQP access... "
expect -re "Host"
send "\025$DS_RABBITMQ_HOST\r"
Expand Down Expand Up @@ -154,43 +139,51 @@ if rpm -q "firewalld"; then
systemctl restart firewalld.service
fi

if [ "$APPSERVER_INSTALLED" = "false" ] || [ "$UPDATE" = "true" ]; then
if [ "$APPSERVER_INSTALLED" = "false" ]; then
${package_manager} install -y ${package_sysname}-${product}
else
${package_manager} -y update ${package_sysname}-${product}
fi
{ ${package_manager} check-update ${package_sysname}-${product}; APPSERVER_CHECK_UPDATE=$?; } || true
if [[ $APPSERVER_CHECK_UPDATE -eq $UPDATE_AVAILABLE_CODE ]]; then
APPSERVER_NEED_UPDATE="true"
fi

if [ "${MYSQL_FIRST_TIME_INSTALL}" = "true" ] || [ "$UPDATE" = "true" ]; then
if [ "$APPSERVER_INSTALLED" = "false" ]; then
${package_manager} install -y ${package_sysname}-${product}
elif ["$APPSERVER_NEED_UPDATE" = "true"] then
ENVIRONMENT="$(cat /lib/systemd/system/${product}-api.service | grep -oP 'ENVIRONMENT=\K.*')"
USER_CONNECTIONSTRING=$(json -f /etc/onlyoffice/${product}/appsettings.$ENVIRONMENT.json ConnectionStrings.default.connectionString)
MYSQL_SERVER_HOST=$(echo $USER_CONNECTIONSTRING | grep -oP 'Server=\K.*' | grep -o '^[^;]*')
MYSQL_SERVER_DB_NAME=$(echo $USER_CONNECTIONSTRING | grep -oP 'Database=\K.*' | grep -o '^[^;]*')
MYSQL_SERVER_USER=$(echo $USER_CONNECTIONSTRING | grep -oP 'User ID=\K.*' | grep -o '^[^;]*')
MYSQL_SERVER_PORT=$(echo $USER_CONNECTIONSTRING | grep -oP 'Port=\K.*' | grep -o '^[^;]*')
MYSQL_ROOT_PASS=$(echo $USER_CONNECTIONSTRING | grep -oP 'Password=\K.*' | grep -o '^[^;]*')

${package_manager} -y update ${package_sysname}-${product}
fi

if [ "${APPSERVER_INSTALLED}" = "false" ] || ["$APPSERVER_NEED_UPDATE" = "true"]; then
expect << EOF
set timeout -1
log_user 1
set timeout -1
log_user 1
if { "${UPDATE}" == "true" } {
spawn ${product}-configuration.sh -e ${ENVIRONMENT}
} else {
spawn ${product}-configuration.sh
}
if { "${UPDATE}" == "true" } {
spawn ${product}-configuration.sh -e ${ENVIRONMENT}
} else {
spawn ${product}-configuration.sh
}
expect -re "Database host:"
send "\025$MYSQL_SERVER_HOST\r"
expect -re "Database host:"
send "\025$MYSQL_SERVER_HOST\r"
expect -re "Database name:"
send "\025$MYSQL_SERVER_DB_NAME\r"
expect -re "Database name:"
send "\025$MYSQL_SERVER_DB_NAME\r"
expect -re "Database user:"
send "\025$MYSQL_SERVER_USER\r"
expect -re "Database user:"
send "\025$MYSQL_SERVER_USER\r"
expect -re "Database password:"
send "\025$MYSQL_ROOT_PASS\r"
expect -re "Database password:"
send "\025$MYSQL_ROOT_PASS\r"
expect eof
expect eof
EOF
APPSERVER_INSTALLED="true";
else
bash ${product}-configuration.sh
APPSERVER_INSTALLED="true";
fi
APPSERVER_INSTALLED="true";
fi

echo ""
Expand Down
8 changes: 5 additions & 3 deletions build/install/OneClickInstall/install-RedHat/install-preq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ if ! rpm -q mysql-community-server; then
fi

#add elasticsearch repo
ELASTIC_VERSION="7.13.1"
ELASTIC_DIST=$(echo $ELASTIC_VERSION | awk '{ print int($1) }')
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
cat > /etc/yum.repos.d/elasticsearch.repo <<END
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
name=Elasticsearch repository for ${ELASTIC_DIST}.x packages
baseurl=https://artifacts.elastic.co/packages/${ELASTIC_DIST}.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
Expand Down Expand Up @@ -175,7 +177,7 @@ ${package_manager} -y install epel-release \
make \
yarn \
dotnet-sdk-5.0 \
elasticsearch-7.13.1 --enablerepo=elasticsearch \
elasticsearch-${ELASTIC_VERSION} --enablerepo=elasticsearch \
mysql-server \
nginx \
supervisor \
Expand Down
3 changes: 1 addition & 2 deletions build/install/deb/debian/templates
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ Default: root
Description: MySQL user:

Template: appserver/db-pwd
Type: string
Default: my-secret-pw
Type: password
Description: MySQL password:

Template: appserver/db-name
Expand Down

0 comments on commit 366f989

Please sign in to comment.