-
Notifications
You must be signed in to change notification settings - Fork 1
/
upversion.sh
executable file
·90 lines (69 loc) · 2.14 KB
/
upversion.sh
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
88
89
90
#!/bin/sh -eu
check_django_working() {
./manage.py check && DJANGO_OK=1 || DJANGO_OK=0
if [ $DJANGO_OK -ne 1 ]; then
echo
echo "Run from the ./mhep directory inside the Vagrant machine"
exit 1
fi
}
get_latest_version() {
ls -al mhep/
echo
echo "What's the latest version number? (e.g. v2)"
read CURRENT_V
}
check_destination_directory_doesnt_exist() {
if [ -d "mhep/${NEW_V}" ]; then
echo "directory mhep/${NEW_V} already exists"
exit 1
fi
}
copy_app_directory() {
# copy whole app directory
cp -R mhep/${CURRENT_V} mhep/${NEW_V}
}
rename_subdirectories() {
echo "Renaming static/${CURRENT_V} to static/${NEW_V}"
echo " templates/${CURRENT_V} to templates/${NEW_V}"
mv mhep/${NEW_V}/static/${CURRENT_V} mhep/${NEW_V}/static/${NEW_V}
mv mhep/${NEW_V}/templates/${CURRENT_V} mhep/${NEW_V}/templates/${NEW_V}
}
add_to_django_installed_apps() {
echo "Adding ${NEW_V} to config/settings/base.py"
sed -i "s| # Your stuff: custom apps go here| # Your stuff: custom apps go here\n \"mhep.${NEW_V}.apps.AssessmentsConfig\",|g" config/settings/base.py
}
add_to_django_urls() {
echo "Adding ${NEW_V} to config/urls.py"
sed -i "s| # Add app versions after this line| # Add app versions after this line\n path(\"${NEW_V}/\", include(\"mhep.${NEW_V}.urls\", namespace=\"${NEW_V}\")),|g" config/urls.py
}
create_initial_migration() {
echo "Creating initial migration for ${NEW_V}"
rm -rf mhep/${NEW_V}/migrations/*.py
touch mhep/${NEW_V}/migrations/__init__.py
./manage.py makemigrations ${NEW_V}
}
update_fixtures() {
echo "Updating fixtures for ${NEW_V}"
sed -i "s|\"model\": \"${CURRENT_V}\.|\"model\": \"${NEW_V}.|g" mhep/${NEW_V}/fixtures/*.json
}
NEW_V="dev"
check_django_working
get_latest_version
check_destination_directory_doesnt_exist
echo "Copying mhep/${CURRENT_V} to mhep/${NEW_V}"
echo
read -p "Continue (y/n)?" choice
case "$choice" in
y|Y ) echo "yes"
copy_app_directory
rename_subdirectories
add_to_django_installed_apps
add_to_django_urls
create_initial_migration
update_fixtures
echo "Done."
;;
n|N ) echo "no";;
* ) echo "invalid";;
esac