blob: 4e1ee3afe4f21b9874b90226febd3547739e5856 (
plain) (
blame)
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
|
#!/bin/sh
# First we define the function
ConfirmOrExit ()
{
while true
do
echo -n "Please confirm (y or n) :"
read CONFIRM
case $CONFIRM in
y|Y|YES|yes|Yes) break ;;
n|N|no|NO|No)
echo "Aborting - you entered $CONFIRM"
exit
;;
*) echo "Please enter only y or n"
esac
done
echo "You entered $CONFIRM. Continuing ..."
}
# Absolute path to this script, e.g. /home/user/bin/foo.sh
SCRIPT=$(readlink -f "$0")
# Absolute path this script is in, thus /home/user/bin
SCRIPTPATH=$(dirname "$SCRIPT")
DIR=$(dirname "$SCRIPTPATH");
DIR_CONF=$DIR"/conf"
echo "SCRIPT=$SCRIPT";
echo "SCRIPTPATH=$SCRIPTPATH";
echo "DIR=$DIR";
echo "DIR_CONF=$DIR_CONF";
ConfirmOrExit
IS_INSTALL=$(prt-get isinst postgresql);
echo $IS_INSTALL;
if [ "$IS_INSTALL" = "package postgresql is installed" ]
then
echo "updating postgresql"
OLD_VERSION=$(prt-get current postgresql);
echo $OLD_VERSION;
sudo -u postgres pg_dumpall > /srv/pgsql/dump-$OLD_VERSION.sql
sh /etc/rc.d/postgresql stop
#extra backup, in case ...
tar --xattrs -zcpf /srv/pgsql/data-$OLD_VERSION.tar.gz \
--directory=/srv/pgsql/data .
rm -R /srv/pgsql/data
prt-get update postgresql
NEW_VERSION=$(prt-get current postgresql);
echo $NEW_VERSION;
sudo -u postgres initdb -D /srv/pgsql/data
rejmerge
#installer overwrite system init script
cp -R $DIR_CONF/etc/rc.d/postgresql /etc/rc.d/
sh /etc/rc.d/postgresql start
sleep 5
sudo -u postgres psql -d postgres -f /srv/pgsql/dump-$OLD_VERSION.sql
else
echo "install postgresql and dependencies"
prt-get depinst postgresql
cp -R $DIR_CONF/etc/rc.d/postgresql /etc/rc.d/
mkdir /srv/pgsql/
touch /var/log/postgresql
chown postgres:postgres /srv/pgsql /var/log/postgresql
sudo -u postgres initdb -D /srv/pgsql/data
cp $DIR_CONF/srv/pgsql/data/pg_hba.conf /srv/pgsql/data/
chown postgres:postgres /srv/pgsql/data/pg_hba.conf
fi
exit 0;
|