Skip to content

Commit

Permalink
Set -e and trap the error for exit
Browse files Browse the repository at this point in the history
  • Loading branch information
stephdl committed Jun 4, 2021
1 parent a8685dc commit d627139
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
# You should have received a copy of the GNU General Public License
# along with NethServer. If not, see <http://www.gnu.org/licenses/>.
#
# exit when any command fails
set -e

# keep track of the last executed command
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
# echo an error message before exiting
trap 'echo "Error while restoring nextcloud database to SCL mariadb105: \"${last_command}\" command filed with exit code $?."' EXIT

source /opt/rh/rh-mariadb105/enable

Expand All @@ -33,9 +40,4 @@ mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "ALTER DATABAS
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "grant all on nextcloud.* to 'nextcloud'@'localhost' identified by '$password';"
mysql --socket=/run/rh-mariadb105-mariadb/nextcloud-mysql.sock -e "FLUSH PRIVILEGES"

if [[ $? -ne 0 ]]; then
echo "[ERROR] Error while restoring nextcloud database to SCL mariadb105"
exit 1
fi

rm -f /var/lib/nethserver/backup/rh-mariadb105/nextcloud.sql

0 comments on commit d627139

Please sign in to comment.