Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit db6a2f8

Browse files
committed
update permissions so user "vagrant" can run all commands. Fix usability
1 parent 6bd24f7 commit db6a2f8

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

‎README.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Vagrant-Python-Django VM
22

33
A Vagrantfile utilizing Ubuntu 14.04/Trusty to get you started with self-contained Python/Django projects quickly via VirtualEnv.
4-
Create contained environments within the VM via `. init_python_env`
4+
Create contained environments within the VM via `init_python_env`
55

66
## Installation
77
#### Prerequisites
@@ -13,17 +13,17 @@ Create contained environments within the VM via `. init_python_env`
1313

1414
#### Logging Into Your VM
1515
- `vagrant up` to setup and initialize the VM. ( only the first time you run `vagrant up` will take long 5-10 mins )
16-
- After the VM is initialized, run `vagrant ssh` and then `sudo su` to login as the root user.
16+
- After the VM is initialized, run `vagrant ssh`
1717
- change the current directory to your projects root by typing `cd $WORKON_HOME`
1818

1919
#### Create a Contained Python Environment
20-
`. init_python_env`**(Notice the preceding period!)**Django install is optional.
20+
`init_python_env`. Installing Django is optional.
2121

2222
#### Setup PgAdmin Web interface (phpPgAdmin)
2323
`setup_phppgadmin`
2424

2525
#### Setting Up a New Database For A Django Project
26-
`manage_django_db`. Switch to a Django Project Folder before running. This will create a new user, alter their role, create a new database, and assign them to a DB. If you just want to assign roles and not create new users/DBs, that works too. Running this command will also automatically update the django `settings.py` file for your project. ** CURRENTLY ONLY SUPPORTS POSTGRESQL ** More DBMS will be added in the future.
26+
`manage_django_db`. **Switch to a Django Project Folder before running**. This will create a new user, alter their role, create a new database, and assign them to a DB. If you just want to assign roles and not create new users/DBs, that works too. Running this command will also automatically update the django `settings.py` file for your project. ** CURRENTLY ONLY SUPPORTS POSTGRESQL ** More DBMS will be added in the future.
2727

2828
## Notes to User:
2929
- The default settings will run Django on port 80
@@ -33,13 +33,13 @@ Create contained environments within the VM via `. init_python_env`
3333
- Defaults to latest stable version PostgreSQL
3434
- Default settings run Apache on port 8080, needed for phpPgAdmin web interface.
3535
- To change the port(s) Apache runs on edit the following:
36-
- `vim /etc/apache2/ports.conf`
37-
- `vim /etc/apache2/sites-available/000-default.conf`
36+
- `sudo vim /etc/apache2/ports.conf`
37+
- `sudo vim /etc/apache2/sites-available/000-default.conf`
3838
- Then restart Apache `sudo /etc/init.d/apache2 restart`
3939

4040
## Usage
4141
- VirtualEnv is _not_ a VM container, it is simply to create self-contained python environments. Think of it as a sandbox, not a full fledged VM. Plus, we already have the VM!
42-
- `cd` into the synced_folder and run the command `. init_python_env` to create a new Python Environment so projects/packages are contained. **All python environments will be initialized in the synced_folder (`/vagrant/www/` by default). Notice the preceding period.**
42+
- `cd` into the synced_folder and run the command `init_python_env` to create a new Python Environment so projects/packages are contained. **All python environments will be initialized in the synced_folder (`/vagrant/www/` by default).**
4343
- Be aware that self-contained Python Environments does ***NOT*** mean self-contained Database Environments. Future releases may take this into account through porting.
4444
- Run `python -V` and `django-admin --version` to make sure everything checked out.
4545
- run `deactivate` to exit virtualenv environment or `workon [PROJECT_NAME]` to activate it. Alternatively, whenever you navigate into a project folder, the virtual environment will become activated.

‎bootstrap/manage_django_db.sh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ function check_module() {
1919
# for formatting the settings.py file.
2020
check_module autopep8
2121

22-
PS3="Select A Database Engine to Use: "
22+
echo -e "${BYELLOW}Select A Database Engine to Use: ${NIL}"
23+
PS3="Enter a corresponding number: "
2324

2425
select db_engine in postgresql mysql sqlite3 oracle SKIP
2526
do

‎bootstrap/manage_django_db_postgres.sh‎

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
source /bin/colors
3-
3+
source /etc/bash.bashrc
44
### CHECK PYTHON MODULES ARE INSTALLED ###
55
function check_module(){
66
python -c "import ${1}" 2> /dev/null
@@ -33,6 +33,7 @@ function check_package(){
3333
function change_your_dir(){
3434

3535
if [ ! -f $PWD/settings.py ]; then
36+
echo -e "${BYELLOW} Let's update the Django Settings File...${NIL}"
3637
echo -e ${RED}
3738
echo -e " Select a project's ${BRED}main app folder${RED} first!\n ${YELLOW}(where the ${BWHITE}settings.py${YELLOW} file lives.${NIL})\n"
3839
echo -e ${NIL}
@@ -48,7 +49,14 @@ function change_your_dir(){
4849
function make_user(){
4950
echo "Enter a password for $NEW_DB_USER: "
5051
read -s NEW_DB_PASS
51-
sudo -u postgres psql -tAc "CREATE USER $NEW_DB_USER WITH PASSWORD '$NEW_DB_PASS';"
52+
echo "Enter it again: "
53+
read -s NEW_DB_PASS_CONFIRM
54+
if [ $NEW_DB_PASS != $NEW_DB_PASS_CONFIRM ]; then
55+
echo -e "${BRED}passwords do not match!${NIL}"
56+
make_user
57+
else
58+
sudo -u postgres psql -tAc "CREATE USER $NEW_DB_USER WITH PASSWORD '$NEW_DB_PASS';"
59+
fi
5260
}
5361

5462
function assign_privs(){
@@ -80,13 +88,17 @@ function configure_md5_login(){
8088
sudo -u postgres psql -tAc "\password postgres"
8189
sudo sed -i "s/\s*local\s*all\s*all\s*peer/local all all md5/" /etc/postgresql/*/main/pg_hba.conf
8290
sudo service postgresql restart
91+
sudo sh -c ' echo "export POSTGRES_PASS=configured" >> /etc/bash.bashrc'
92+
exec $SHELL
8393
}
8494

8595
function update_app_settings(){
8696

8797
change_your_dir
8898
continue_update_app_settings ${1}
89-
configure_md5_login
99+
if [ -z "$POSTGRES_PASS" ]; then
100+
configure_md5_login
101+
fi
90102
}
91103

92104
### USER INPUT METHODS ###
@@ -102,31 +114,31 @@ function update_data(){
102114
echo -e ${BGREEN}using ALIAS: $DB_ALIAS ${NIL}
103115
;;
104116
engine)
105-
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
117+
sudo 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
106118
autopep8 --in-place --aggressive --aggressive settings.py
107119
;;
108120
name)
109121
DB_NAME=${2}
110-
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
122+
sudo 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
111123
autopep8 --in-place --aggressive --aggressive settings.py
112124
;;
113125
user)
114126
DB_USER=${2}
115-
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
127+
sudo 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
116128
autopep8 --in-place --aggressive --aggressive settings.py
117129
;;
118130
password)
119-
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
131+
sudo 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
120132
autopep8 --in-place --aggressive --aggressive settings.py
121133
;;
122134
host)
123135
DB_HOST=${2}
124-
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
136+
sudo 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
125137
autopep8 --in-place --aggressive --aggressive settings.py
126138
;;
127139
port)
128140
DB_PORT=${2}
129-
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
141+
sudo 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
130142
autopep8 --in-place --aggressive --aggressive settings.py
131143
;;
132144
esac
@@ -143,13 +155,13 @@ function continue_update_app_settings(){
143155
read -e -i 'default' -p 'Enter the database ALIAS youd like to edit: ' THE_ALIAS
144156

145157
# output to a temp file
146-
sed -n '/DATABASES*/,/# Password validation/p' settings.py>> tmp_alias_generator.txt
158+
TEST_ALIAS=$(sudo sed -n '/DATABASES*/,/# Password validation/p' settings.py)
147159
# check if exact match exists.
148-
grep -Fxq " '$THE_ALIAS': {" tmp_alias_generator.txt
160+
echo"$TEST_ALIAS"|grep -q " '$THE_ALIAS': {"
149161
ALIAS_EXISTS=$?
150162
# create if it doesnt exist
151163
if [ $ALIAS_EXISTS == 1 ]; then
152-
sed -i "/DATABASES = {/{s/.*/DATABASES = {\n'$THE_ALIAS': {\n},/}" settings.py
164+
sudo sed -i "/DATABASES = {/{s/.*/DATABASES = {\n'$THE_ALIAS': {\n},/}" settings.py
153165
autopep8 --in-place --aggressive --aggressive settings.py
154166

155167
fi

‎bootstrap/setup_phppgadmin.sh‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ source /bin/colors
33
# INSTALL PHPPGADMIN
44
sudo apt-get install phppgadmin -y
55
# configure Apache server to tell it where to find phppgadmin.
6-
sudo echo 'Include /etc/apache2/conf.d/phppgadmin'>> /etc/apache2/apache2.conf
6+
echo 'Include /etc/apache2/conf.d/phppgadmin'| sudo tee --append /etc/apache2/apache2.conf
77
# allow permission to access phppgadmin.
8-
sed -i 's/^allow from 127.0.0.0\/255.0.0.0 ::1\/128/# allow from 127.0.0.0\/255.0.0.0 ::1\/128/' /etc/apache2/conf.d/phppgadmin
9-
sed -i 's/^#allow from all/allow from all/' /etc/apache2/conf.d/phppgadmin
10-
sed -i 's/^# allow from all/allow from all/' /etc/apache2/conf.d/phppgadmin
8+
sudo sed -i 's/^allow from 127.0.0.0\/255.0.0.0 ::1\/128/# allow from 127.0.0.0\/255.0.0.0 ::1\/128/' /etc/apache2/conf.d/phppgadmin
9+
sudo sed -i 's/^#allow from all/allow from all/' /etc/apache2/conf.d/phppgadmin
10+
sudo sed -i 's/^# allow from all/allow from all/' /etc/apache2/conf.d/phppgadmin
1111
sudo service apache2 reload
1212
# enable user "postgres" to login
1313
sudo sed -i "s/\s*\$conf\['extra_login_security'\] = true;/ \$conf\['extra_login_security'\] = false;/" /etc/phppgadmin/config.inc.php

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /