@@ -73,55 +73,63 @@ function assign_user_to_db(){
73
73
fi
74
74
}
75
75
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
+ }
76
83
77
84
function update_app_settings(){
78
85
79
86
change_your_dir
80
87
continue_update_app_settings ${1}
88
+ configure_md5_login
81
89
}
82
90
83
91
# ## USER INPUT METHODS ###
84
- function update_data()
85
- {
92
+ function update_data(){
86
93
87
94
case ${1} in
88
95
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
+
125
133
126
134
}
127
135
@@ -169,20 +177,20 @@ function continue_update_app_settings(){
169
177
}
170
178
# ## DATABASE PASSWORD
171
179
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
+ }
186
194
# ## DATABASE HOST
187
195
function enter_db_host(){
188
196
read -e -i ' localhost' -p " HOST for $DB_NAME : " DB_HOST
0 commit comments