Skip to content

Commit 0af664e

Browse files
committed
Configure MD5 login for postgres users. Fix sed replacing Apache port
1 parent 1b6e0db commit 0af664e

File tree

2 files changed

+61
-58
lines changed

2 files changed

+61
-58
lines changed

bootstrap/manage_django_db_postgres.sh

Lines changed: 60 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -73,55 +73,63 @@ function assign_user_to_db(){
7373
fi
7474
}
7575

76+
function configure_md5_login(){
77+
echo -e ${BYELLOW}Update password for user "postgres"${NIL}
78+
# Create a new password for user "postgres"
79+
sudo -u postgres psql -tAc "\password postgres"
80+
sudo sed -i "s/\s*local\s*all\s*all\s*peer/local all all md5/" /etc/postgresql/9.3/main/pg_hba.conf
81+
sudo service postgresql restart
82+
}
7683

7784
function update_app_settings(){
7885

7986
change_your_dir
8087
continue_update_app_settings ${1}
88+
configure_md5_login
8189
}
8290

8391
### USER INPUT METHODS ###
84-
function update_data()
85-
{
92+
function update_data(){
8693

8794
case ${1} in
8895
db_alias)
89-
if [ -z ${2+x} ]; then
90-
DB_ALIAS='default'
91-
else
92-
DB_ALIAS=${2}
93-
fi
94-
echo -e ${BGREEN}using ALIAS: $DB_ALIAS ${NIL}
95-
;;
96-
engine)
97-
sed -i "/^DATABASES/ {:loop n; /'$DB_ALIAS'/{:moop n; /'ENGINE':/{s/\s\+'ENGINE':.*/'ENGINE': 'django.db.backends.postgresql',/g}; t loop; /}/{s/\s\+}.*/'ENGINE': 'django.db.backends.postgresql',\\n },/}; t loop; b moop} ;b loop}" settings.py
98-
autopep8 --in-place --aggressive --aggressive settings.py
99-
;;
100-
name)
101-
DB_NAME=${2}
102-
sed -i "/^DATABASES/ {:loop n; /'$DB_ALIAS'/{:moop n; /'NAME':/{s/\s\+'NAME':.*/'NAME': '${2}',/g}; t loop; /}/{s/\s\+}.*/'NAME': '${2}',\\n },/}; t loop; b moop} ;b loop}" settings.py
103-
autopep8 --in-place --aggressive --aggressive settings.py
104-
;;
105-
user)
106-
DB_USER=${2}
107-
sed -i "/^DATABASES/ {:loop n; /'$DB_ALIAS'/{:moop n; /'USER':/{s/\s\+'USER':.*/'USER': '${2}',/g}; t loop; /}/{s/\s\+}.*/'USER': '${2}',\\n },/}; t loop; b moop} ;b loop}" settings.py
108-
autopep8 --in-place --aggressive --aggressive settings.py
109-
;;
110-
password)
111-
sed -i "/^DATABASES/ {:loop n; /'$DB_ALIAS'/{:moop n; /'PASSWORD':/{s/\s\+'PASSWORD':.*/'PASSWORD': '${2}',/g}; t loop; /}/{s/\s\+}.*/'PASSWORD': '${2}',\\n },/}; t loop; b moop} ;b loop}" settings.py
112-
autopep8 --in-place --aggressive --aggressive settings.py
113-
;;
114-
host)
115-
DB_HOST=${2}
116-
sed -i "/^DATABASES/ {:loop n; /'$DB_ALIAS}'/{:moop n; /'HOST':/{s/\s\+'HOST':.*/'HOST': '${2}',/g}; t loop; /}/{s/\s\+}.*/'HOST': '${2}',\\n },/}; t loop; b moop} ;b loop}" settings.py
117-
autopep8 --in-place --aggressive --aggressive settings.py
118-
;;
119-
port)
120-
DB_PORT=${2}
121-
sed -i "/^DATABASES/ {:loop n; /'$DB_ALIAS'/{:moop n; /'PORT':/{s/\s\+'PORT':.*/'PORT': '${2}',/g}; t loop; /}/{s/\s\+}.*/'PORT': '${2}',\\n },/}; t loop; b moop} ;b loop}" settings.py
122-
autopep8 --in-place --aggressive --aggressive settings.py
123-
;;
124-
esac
96+
if [ -z ${2+x} ]; then
97+
DB_ALIAS='default'
98+
else
99+
DB_ALIAS=${2}
100+
fi
101+
echo -e ${BGREEN}using ALIAS: $DB_ALIAS ${NIL}
102+
;;
103+
engine)
104+
sed -i "/^DATABASES/ {:loop n; /'$DB_ALIAS'/{:moop n; /'ENGINE':/{s/\s\+'ENGINE':.*/'ENGINE': 'django.db.backends.postgresql',/g}; t loop; /}/{s/\s\+}.*/'ENGINE': 'django.db.backends.postgresql',\\n },/}; t loop; b moop} ;b loop}" settings.py
105+
autopep8 --in-place --aggressive --aggressive settings.py
106+
;;
107+
name)
108+
DB_NAME=${2}
109+
sed -i "/^DATABASES/ {:loop n; /'$DB_ALIAS'/{:moop n; /'NAME':/{s/\s\+'NAME':.*/'NAME': '${2}',/g}; t loop; /}/{s/\s\+}.*/'NAME': '${2}',\\n },/}; t loop; b moop} ;b loop}" settings.py
110+
autopep8 --in-place --aggressive --aggressive settings.py
111+
;;
112+
user)
113+
DB_USER=${2}
114+
sed -i "/^DATABASES/ {:loop n; /'$DB_ALIAS'/{:moop n; /'USER':/{s/\s\+'USER':.*/'USER': '${2}',/g}; t loop; /}/{s/\s\+}.*/'USER': '${2}',\\n },/}; t loop; b moop} ;b loop}" settings.py
115+
autopep8 --in-place --aggressive --aggressive settings.py
116+
;;
117+
password)
118+
sed -i "/^DATABASES/ {:loop n; /'$DB_ALIAS'/{:moop n; /'PASSWORD':/{s/\s\+'PASSWORD':.*/'PASSWORD': '${2}',/g}; t loop; /}/{s/\s\+}.*/'PASSWORD': '${2}',\\n },/}; t loop; b moop} ;b loop}" settings.py
119+
autopep8 --in-place --aggressive --aggressive settings.py
120+
;;
121+
host)
122+
DB_HOST=${2}
123+
sed -i "/^DATABASES/ {:loop n; /'$DB_ALIAS'/{:moop n; /'HOST':/{s/\s\+'HOST':.*/'HOST': '${2}',/g}; t loop; /}/{s/\s\+}.*/'HOST': '${2}',\\n },/}; t loop; b moop} ;b loop}" settings.py
124+
autopep8 --in-place --aggressive --aggressive settings.py
125+
;;
126+
port)
127+
DB_PORT=${2}
128+
sed -i "/^DATABASES/ {:loop n; /'$DB_ALIAS'/{:moop n; /'PORT':/{s/\s\+'PORT':.*/'PORT': '${2}',/g}; t loop; /}/{s/\s\+}.*/'PORT': '${2}',\\n },/}; t loop; b moop} ;b loop}" settings.py
129+
autopep8 --in-place --aggressive --aggressive settings.py
130+
;;
131+
esac
132+
125133

126134
}
127135

@@ -169,20 +177,20 @@ function continue_update_app_settings(){
169177
}
170178
### DATABASE PASSWORD
171179
function enter_db_pass(){
172-
# read -p "Auto-import password? [y/n] " prompt
173-
# if [[ ${prompt,,} =~ ^(yes|y)$ ]]; then
174-
# update_data password $NEW_DB_PASS
175-
# else
176-
echo "Enter the PASSWORD for $DB_USER: "
177-
read -s DB_PASS
178-
if [ -z ${DB_PASS} ]; then
179-
echo -e ${RED}Invalid Input${NIL}
180-
enter_db_pass
181-
else
182-
update_data password $DB_PASS
183-
fi
184-
# fi
185-
}
180+
# read -p "Auto-import password? [y/n] " prompt
181+
# if [[ ${prompt,,} =~ ^(yes|y)$ ]]; then
182+
# update_data password $NEW_DB_PASS
183+
# else
184+
echo "Enter the PASSWORD for $DB_USER: "
185+
read -s DB_PASS
186+
if [ -z ${DB_PASS} ]; then
187+
echo -e ${RED}Invalid Input${NIL}
188+
enter_db_pass
189+
else
190+
update_data password $DB_PASS
191+
fi
192+
# fi
193+
}
186194
### DATABASE HOST
187195
function enter_db_host(){
188196
read -e -i 'localhost' -p "HOST for $DB_NAME: " DB_HOST

bootstrap/setup_phppgadmin.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@ sed -i 's/^allow from 127.0.0.0\/255.0.0.0 ::1\/128/# allow from 127.0.0.0\/255.
99
sed -i 's/^#allow from all/allow from all/' /etc/apache2/conf.d/phppgadmin
1010
sed -i 's/^# allow from all/allow from all/' /etc/apache2/conf.d/phppgadmin
1111
sudo service apache2 reload
12-
echo -e ${BYELLOW}Update password for user "postgres"${NIL}
13-
# Create a new password for user "postgres"
14-
sudo -u postgres psql -tAc "\password postgres"
1512
# enable user "postgres" to login
1613
sudo sed -i "s/\s*\$conf\['extra_login_security'\] = true;/ \$conf\['extra_login_security'\] = false;/" /etc/phppgadmin/config.inc.php
17-
sudo sed -i "s/\s*local\s*all\s*all\s*peer/local all all md5/" /etc/postgresql/9.3/main/pg_hba.conf
18-
sudo service postgresql restart
1914
# Update port 80 to port 8080
20-
sudo sed -i "s/Listen 80/Listen 8080/" /etc/apache2/ports.conf
15+
sudo sed -i "s/Listen 80\s+/Listen 8080/" /etc/apache2/ports.conf
2116
sudo sed -i "s/:80>/:8080>/" /etc/apache2/sites-available/000-default.conf
2217
sudo /etc/init.d/apache2 restart
2318

0 commit comments

Comments
 (0)