postgresql-setup: lint

Rather use the --ignore-space-change when showing differences.

Version: 9.3.2-2
This commit is contained in:
Pavel Raiskup 2013-12-13 09:36:08 +01:00
parent 85e0b076bc
commit 4c6bd5df12
2 changed files with 96 additions and 104 deletions

View File

@ -1,16 +1,19 @@
#!/bin/sh #!/bin/sh
# #
# postgresql-setup Initialization and upgrade operations for PostgreSQL # postgresql-setup - Initialization and upgrade operations for PostgreSQL
# PGVERSION is the full package version, e.g., 9.0.2 # PGVERSION is the full package version, e.g., 9.0.2
# Note: the specfile inserts the correct value during package build # Note: the specfile inserts the correct value during package build
PGVERSION=xxxx PGVERSION=xxxx
# PGENGINE is the directory containing the postmaster executable # PGENGINE is the directory containing the postmaster executable
# Note: the specfile inserts the correct value during package build # Note: the specfile inserts the correct value during package build
PGENGINE=xxxx PGENGINE=xxxx
# PREVMAJORVERSION is the previous major version, e.g., 8.4, for upgrades # PREVMAJORVERSION is the previous major version, e.g., 8.4, for upgrades
# Note: the specfile inserts the correct value during package build # Note: the specfile inserts the correct value during package build
PREVMAJORVERSION=xxxx PREVMAJORVERSION=xxxx
# PREVPGENGINE is the directory containing the previous postmaster executable # PREVPGENGINE is the directory containing the previous postmaster executable
# Note: the specfile inserts the correct value during package build # Note: the specfile inserts the correct value during package build
PREVPGENGINE=xxxx PREVPGENGINE=xxxx
@ -18,8 +21,7 @@ PREVPGENGINE=xxxx
# Absorb configuration settings from the specified systemd service file, # Absorb configuration settings from the specified systemd service file,
# or the default "postgresql" service if not specified # or the default "postgresql" service if not specified
SERVICE_NAME="$2" SERVICE_NAME="$2"
if [ x"$SERVICE_NAME" = x ] if [ x"$SERVICE_NAME" = x ]; then
then
SERVICE_NAME=postgresql SERVICE_NAME=postgresql
fi fi
@ -28,9 +30,7 @@ fi
PGDATA=`systemctl show -p Environment "${SERVICE_NAME}.service" | PGDATA=`systemctl show -p Environment "${SERVICE_NAME}.service" |
sed 's/^Environment=//' | tr ' ' '\n' | sed 's/^Environment=//' | tr ' ' '\n' |
sed -n 's/^PGDATA=//p' | tail -n 1` sed -n 's/^PGDATA=//p' | tail -n 1`
if [ x"$PGDATA" = x ]; then
if [ x"$PGDATA" = x ]
then
echo "failed to find PGDATA setting in ${SERVICE_NAME}.service" echo "failed to find PGDATA setting in ${SERVICE_NAME}.service"
exit 1 exit 1
fi fi
@ -38,9 +38,7 @@ fi
PGPORT=`systemctl show -p Environment "${SERVICE_NAME}.service" | PGPORT=`systemctl show -p Environment "${SERVICE_NAME}.service" |
sed 's/^Environment=//' | tr ' ' '\n' | sed 's/^Environment=//' | tr ' ' '\n' |
sed -n 's/^PGPORT=//p' | tail -n 1` sed -n 's/^PGPORT=//p' | tail -n 1`
if [ x"$PGPORT" = x ]; then
if [ x"$PGPORT" = x ]
then
echo "failed to find PGPORT setting in ${SERVICE_NAME}.service" echo "failed to find PGPORT setting in ${SERVICE_NAME}.service"
exit 1 exit 1
fi fi
@ -55,8 +53,7 @@ export PGDATA
export PGPORT export PGPORT
# For SELinux we need to use 'runuser' not 'su' # For SELinux we need to use 'runuser' not 'su'
if [ -x /sbin/runuser ] if [ -x /sbin/runuser ]; then
then
SU=runuser SU=runuser
else else
SU=su SU=su
@ -66,8 +63,7 @@ script_result=0
# code shared between initdb and upgrade actions # code shared between initdb and upgrade actions
perform_initdb(){ perform_initdb(){
if [ ! -e "$PGDATA" ] if [ ! -e "$PGDATA" ]; then
then
mkdir "$PGDATA" || return 1 mkdir "$PGDATA" || return 1
chown postgres:postgres "$PGDATA" chown postgres:postgres "$PGDATA"
chmod go-rwx "$PGDATA" chmod go-rwx "$PGDATA"
@ -76,8 +72,7 @@ perform_initdb(){
[ -x /sbin/restorecon ] && /sbin/restorecon "$PGDATA" [ -x /sbin/restorecon ] && /sbin/restorecon "$PGDATA"
# Create the initdb log file if needed # Create the initdb log file if needed
if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ] if [ ! -e "$PGLOG" -a ! -h "$PGLOG" ]; then
then
touch "$PGLOG" || return 1 touch "$PGLOG" || return 1
chown postgres:postgres "$PGLOG" chown postgres:postgres "$PGLOG"
chmod go-rwx "$PGLOG" chmod go-rwx "$PGLOG"
@ -85,7 +80,8 @@ perform_initdb(){
fi fi
# Initialize the database # Initialize the database
$SU -l postgres -c "$PGENGINE/initdb --pgdata='$PGDATA' --auth='ident'" >> "$PGLOG" 2>&1 < /dev/null $SU -l postgres -c "$PGENGINE/initdb --pgdata='$PGDATA' --auth='ident'" \
>> "$PGLOG" 2>&1 < /dev/null
# Create directory for postmaster log files # Create directory for postmaster log files
mkdir "$PGDATA/pg_log" mkdir "$PGDATA/pg_log"
@ -93,23 +89,20 @@ perform_initdb(){
chmod go-rwx "$PGDATA/pg_log" chmod go-rwx "$PGDATA/pg_log"
[ -x /sbin/restorecon ] && /sbin/restorecon "$PGDATA/pg_log" [ -x /sbin/restorecon ] && /sbin/restorecon "$PGDATA/pg_log"
if [ -f "$PGDATA/PG_VERSION" ] if [ -f "$PGDATA/PG_VERSION" ]; then
then
return 0 return 0
fi fi
return 1 return 1
} }
initdb(){ initdb(){
if [ -f "$PGDATA/PG_VERSION" ] if [ -f "$PGDATA/PG_VERSION" ]; then
then
echo $"Data directory is not empty!" echo $"Data directory is not empty!"
echo echo
script_result=1 script_result=1
else else
echo -n $"Initializing database ... " echo -n $"Initializing database ... "
if perform_initdb if perform_initdb; then
then
echo $"OK" echo $"OK"
else else
echo $"failed, see $PGLOG" echo $"failed, see $PGLOG"
@ -125,12 +118,12 @@ upgrade(){
x`cat "$PGDATA/PG_VERSION"` != x"$PREVMAJORVERSION" ] x`cat "$PGDATA/PG_VERSION"` != x"$PREVMAJORVERSION" ]
then then
echo echo
echo $"Cannot upgrade because database is not of version $PREVMAJORVERSION." echo $"Cannot upgrade because the database in $PGDATA is not of"
echo $"compatible previous version $PREVMAJORVERSION."
echo echo
exit 1 exit 1
fi fi
if [ ! -x "$PGENGINE/pg_upgrade" ] if [ ! -x "$PGENGINE/pg_upgrade" ]; then
then
echo echo
echo $"Please install the postgresql-upgrade RPM." echo $"Please install the postgresql-upgrade RPM."
echo echo
@ -164,14 +157,13 @@ upgrade(){
# For fluent upgrade 'postgres' user should be able to connect # For fluent upgrade 'postgres' user should be able to connect
# to any database without password. Temporarily, no other type # to any database without password. Temporarily, no other type
# of connection is needed. # of connection is needed.
/usr/bin/echo -e "local all postgres ident" > "$PGDATAOLD/pg_hba.conf" echo "local all postgres ident" > "$PGDATAOLD/pg_hba.conf"
fi fi
echo -n $"Upgrading database: " echo -n $"Upgrading database: "
# Create empty new-format database # Create empty new-format database
if perform_initdb if perform_initdb; then
then
# Do the upgrade # Do the upgrade
$SU -l postgres -c "$PGENGINE/pg_upgrade \ $SU -l postgres -c "$PGENGINE/pg_upgrade \
'--old-bindir=$PREVPGENGINE' \ '--old-bindir=$PREVPGENGINE' \
@ -181,8 +173,7 @@ upgrade(){
--link \ --link \
'--old-port=$PGPORT' '--new-port=$PGPORT' \ '--old-port=$PGPORT' '--new-port=$PGPORT' \
--user=postgres" >> "$PGUPLOG" 2>&1 < /dev/null --user=postgres" >> "$PGUPLOG" 2>&1 < /dev/null
if [ $? -ne 0 ] if [ $? -ne 0 ]; then
then
# pg_upgrade failed # pg_upgrade failed
script_result=1 script_result=1
fi fi
@ -191,13 +182,12 @@ upgrade(){
script_result=1 script_result=1
fi fi
# Move back the backed-up pg_hba.conf regardless of the script_result.
if [ x$HBA_CONF_BACKUP_EXISTS = x1 ]; then if [ x$HBA_CONF_BACKUP_EXISTS = x1 ]; then
mv -f "$HBA_CONF_BACKUP" "$PGDATAOLD/pg_hba.conf" mv -f "$HBA_CONF_BACKUP" "$PGDATAOLD/pg_hba.conf"
fi fi
if [ $script_result -eq 0 ]; then
if [ $script_result -eq 0 ]
then
echo $"OK" echo $"OK"
echo echo
echo $"The configuration files was replaced by default configuration." echo $"The configuration files was replaced by default configuration."
@ -207,7 +197,6 @@ upgrade(){
# Clean up after failure # Clean up after failure
rm -rf "$PGDATA" rm -rf "$PGDATA"
mv "$PGDATAOLD" "$PGDATA" mv "$PGDATAOLD" "$PGDATA"
echo $"failed" echo $"failed"
fi fi
echo echo

View File

@ -1122,6 +1122,9 @@ fi
%endif %endif
%changelog %changelog
* Fri Dec 13 2013 Pavel Raiskup <praiskup@redhat.com> - 9.3.2-2
- lint the postgresql-setup script
* Thu Dec 12 2013 Jozef Mlich <jmlich@redhat.com> - 9.3.2-2 * Thu Dec 12 2013 Jozef Mlich <jmlich@redhat.com> - 9.3.2-2
- don't fail if user has badly configure 'postgres' user access (#1040364) - don't fail if user has badly configure 'postgres' user access (#1040364)