Revert "Revert "oran-shell-release: release image for F""
[pti/rtp.git] / meta-starlingx / meta-stx-integ / recipes-support / openldap / files / sources / libexec-upgrade-db.sh
1 #!/bin/sh
2 # Author: Jan Vcelak <jvcelak@redhat.com>
3
4 . /usr/libexec/openldap/functions
5
6 if [ `id -u` -ne 0 ]; then
7         error "You have to be root to run this command."
8         exit 4
9 fi
10
11 load_sysconfig
12 retcode=0
13
14 for dbdir in `databases`; do
15         upgrade_log="$dbdir/db_upgrade.`date +%Y%m%d%H%M%S`.log"
16         bdb_files=`find "$dbdir" -maxdepth 1 -name "*.bdb" -printf '"%f" '`
17
18         # skip uninitialized database
19         [ -z "$bdb_files"]  || continue
20
21         printf "Updating '%s', logging into '%s'\n" "$dbdir" "$upgrade_log"
22
23         # perform the update
24         for command in \
25                 "/usr/bin/db_recover -v -h \"$dbdir\"" \
26                 "/usr/bin/db_upgrade -v -h \"$dbdir\" $bdb_files" \
27                 "/usr/bin/db_checkpoint -v -h \"$dbdir\" -1" \
28         ; do
29                 printf "Executing: %s\n" "$command" &>>$upgrade_log
30                 run_as_ldap "$command" &>>$upgrade_log
31                 result=$?
32                 printf "Exit code: %d\n" $result >>"$upgrade_log"
33                 if [ $result -ne 0 ]; then
34                         printf "Upgrade failed: %d\n" $result
35                         retcode=1
36                 fi
37         done
38 done
39
40 exit $retcode