forked from Islandora/migrate_islandora_csv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset.sh
executable file
·189 lines (162 loc) · 12.6 KB
/
reset.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env bash
PURPLE='\033[1;30;0;45m'
RED='\e[31m'
NC='\033[0m'
cd ../migrate_islandora_csv
migration_config_names_tmp=()
migration_groups_tmp=()
echo -e "\n${PURPLE}+------------ Scanning YMLs for config names ------------+ ${NC}\n"
# For each file in config/install/ directory read line that starts with "id:" and extract the id into an array
# Then, for each id, read the line that starts with "id:" and extract the name into an array
for file in config/install/*.yml; do
while read -r line; do
# If the line starts with "id:" then extract the id
if [[ $line =~ ^id: ]]; then
id=$(echo $line | cut -d ':' -f 3)
name=$(grep "^id:$id" config/install/*.yml | cut -d ':' -f 3)
migration_config_names_tmp+=("$name")
fi
# If the line starts with "migration_group:" then extract the migration_group
if [[ $line =~ ^migration_group: ]]; then
migration_group=$(echo $line | cut -d ':' -f 2)
group_name=$(grep "^migration_group:$migration_group" config/install/*.yml | cut -d ':' -f 3)
migration_groups_tmp+=("$group_name")
fi
done < "$file"
done
migration_config_names=($(echo "${migration_config_names_tmp[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
migration_groups=($(echo "${migration_groups_tmp[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
cd ../isle-dc || exit
# migration_groups=("collections_migrate_islandora_csv" "taxonomies_migrate_islandora_csv" "knoxgardens_migrate_islandora_csv")
# migration_config_names=("countries" "taxonomies_geo_locations" "collections_file" "collections_node" "collections_media" "knoxgardens_subject" "knoxgardens_file" "knoxgardens_media" "knoxgardens_node")
echo -e "\n${PURPLE}+------------ Backup or Upload RDF mappings ------------+ ${NC}\n"
echo -e "Would you like to (\033[1md\033[0m)ownload, (\033[1mu\033[0m)pload, (\033[1ms\033[0m)kip the migration's RDF mapping config files (d|u|s)? "
read -p "" choice
# If choice is not one of the options, default to "no"
case "$choice" in
d|D )
echo -e "\n${PURPLE}+------------ Downloading RDF mappings ------------+ ${NC}"
docker-compose exec drupal bash -lc "drush config-export --destination=/var/www/drupal/config/sync/ sync -y"
docker-compose exec drupal bash -lc "mkdir -p /var/www/drupal/web/sites/default/files/tmp"
docker-compose exec drupal bash -lc "cd /var/www/drupal/web/sites/default/files/tmp ; for filename in /var/www/drupal/config/sync/rdf.mapping.*; do cp \$filename . ; done "
docker cp "$(docker-compose ps -q drupal)":"/var/www/drupal/web/sites/default/files/tmp/." "../migrate_islandora_csv/rdf_mapping"
docker-compose exec drupal bash -lc "rm -rf /var/www/drupal/web/sites/default/files/tmp"
;;
u|U )
echo -e "\n${PURPLE}+------------ Uploading RDF mappings ------------+ ${NC}"
docker-compose exec drupal bash -lc "drush config-export --destination=/var/www/drupal/config/sync/ sync -y"
docker-compose exec drupal bash -lc "mkdir -p /var/www/drupal/web/sites/default/files/tmp"
docker cp "../migrate_islandora_csv/rdf_mapping/." "$(docker-compose ps -q drupal)":"/var/www/drupal/web/sites/default/files/tmp/"
docker-compose exec drupal bash -lc "cd /var/www/drupal/config/sync/ ; for filename in /var/www/drupal/web/sites/default/files/tmp/rdf.mapping.*; do cp \$filename . ; done "
docker-compose exec drupal bash -lc "rm -rf /var/www/drupal/web/sites/default/files/tmp"
;;
n|N )
echo -e "\n${PURPLE}+------------ Skipping RDF mappings ------------+ ${NC}"
;;
* )
echo -e "\n${PURPLE}+------------ Skipping RDF mappings ------------+ ${NC}"
;;
esac
echo -e "\n${PURPLE}+------------ Add public://csv_migration/ && Redirect Sendmail to DevelMailLog ------------+ ${NC}"
# Just in case folder is missing.
docker-compose exec drupal bash -lc "mkdir -p /var/www/drupal/web/sites/default/files/csv_migration && chown -R nginx:nginx /var/www/drupal/web/sites/default/files/csv_migration"
# docker-compose exec drupal bash -lc "cp /var/www/drupal/web/sites/default/settings.php /var/www/drupal/web/sites/default/settings.php.bak"
docker-compose exec drupal bash -lc "[[ \$(grep 'system.mail' /var/www/drupal/web/sites/default/settings.php) =~ 'system.mail' ]] || echo -e \"\044config['system.mail']['interface']['default'] = 'devel_mail_log';\" >> /var/www/drupal/web/sites/default/settings.php"
echo -e "\n${PURPLE}+------------ Drush clear all and running cron ------------+ ${NC}"
echo -e "\tThis checks to see if there's any issues. Any ${RED}red${NC} in this section will likely cause failures in the migration.\n"
docker-compose exec drupal bash -lc "drush cr && drush cron"
# IF migration_groups[0] is found in the configs, then run the migration
is_group_config_on_the_list=$(docker-compose exec drupal bash -lc "echo \"\$(drush config:status --state=Any --format=list --prefix=migrate_plus.migration_group.${migration_groups[0]} | sed '/^$/d' | grep ${migration_groups[0]})\"")
if [[ "$(echo ${is_group_config_on_the_list// /} | sed '/^$/d')" =~ "migrate_plus.migration_group.${migration_groups[0]}" ]]; then
echo -e "\n${PURPLE}+------------ Resetting migration(s) ------------+ ${NC}"
for migration_config_name in "${migration_config_names[@]}"
do
docker-compose exec drupal bash -lc "drush -y migrate-reset ${migration_config_name}"
done
echo -e "\n${PURPLE}+------------ Rolling back migration(s) ------------+ ${NC}"
echo -e "Ignore ${RED}[error] Failed to unlink file 'fedora://csv_migration/xxxx.tiff'. ${NC}\n"
for migration_group in "${migration_groups[@]}"
do
echo "Rolling back the migration group '${migration_group}'"
docker-compose exec drupal bash -lc "drush -y migrate-rollback --group ${migration_group}"
done
else
echo -e "\n${PURPLE}+------------ No migration(s) installed ------------+ ${NC}"
fi
echo -e "\n${PURPLE}+------------ Checking config_delete and Drupal Console is installed and enabled ------------+ ${NC}"
latest_version=$(curl -s https://api.github.com/repos/desandro/masonry/releases/latest | grep '\"tag_name\":' | sed -E 's/.*\"([^\"]+)\".*/\1/')
docker-compose exec drupal bash -lc "cd /var/www/drupal/web/libraries/ ; [ ! -d '/var/www/drupal/web/libraries/masonry' ] && git clone https://github.com/desandro/masonry masonry"
docker-compose exec drupal bash -lc "cd /var/www/drupal/web/libraries/masonry ; git fetch --all --tags && [[ \$(git branch | sed -nr 's/\*\s(.*)/\1/p') =~ \"${latest_version}\" ]] || git checkout tags/${latest_version}"
docker-compose exec drupal bash -lc "echo \"alias drupal='/var/www/drupal/vendor/drupal/console/bin/drupal'\" > ~/.bashrc"
docker-compose exec drupal bash -lc "mkdir -p /var/www/drupal/config/sync"
docker-compose exec drupal bash -lc "[ ! -f '/var/www/drupal/config/sync/.htaccess' ] && cat > /var/www/drupal/config/sync/.htaccess << EOL
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
# Deny all requests from Apache 2.0-2.2.
<IfModule !mod_authz_core.c>
Deny from all
</IfModule>
# Turn off all options we don't need.
Options -Indexes -ExecCGI -Includes -MultiViews
# Set the catch-all handler to prevent scripts from being executed.
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
<Files *>
# Override the handler again if we're run later in the evaluation list.
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003
</Files>
EOL"
docker-compose exec drupal bash -lc "[[ \$(composer show | grep 'drupal/console') =~ 'drupal/console' ]] || composer require drupal/console:~1.0 --with-all-dependencies"
docker-compose exec drupal bash -lc "[[ \$(composer show | grep 'config_delete') =~ 'config_delete' ]] || composer require 'drupal/config_delete:^1.17' --with-all-dependencies"
docker-compose exec drupal bash -lc "[[ \$(drush pm-list --type=Module --status=enabled | grep 'config_delete') =~ 'config_delete' ]] || drush pm:enable config_delete -y"
echo -e "\n${PURPLE}+------------ Checking / Enabling admin theme and admin menu ------------+ ${NC}"
docker-compose exec drupal bash -lc "[[ \$(composer show | grep 'adminimal_theme') =~ 'adminimal_theme' ]] || composer require 'drupal/adminimal_theme:^1.6' --with-all-dependencies"
docker-compose exec drupal bash -lc "[[ \$(composer show | grep 'adminimal_admin_toolbar') =~ 'adminimal_admin_toolbar' ]] || composer require 'drupal/adminimal_admin_toolbar:^1.11' --with-all-dependencies"
docker-compose exec drupal bash -lc "[[ \$(drush pm-list --type=Theme --status=enabled | grep 'adminimal_theme') =~ 'adminimal_theme' ]] || drush theme:enable adminimal_theme -y"
docker-compose exec drupal bash -lc "[[ \$(drush pm-list --type=Module --status=enabled | grep 'adminimal_admin_toolbar') =~ 'adminimal_admin_toolbar' ]] || drush pm:enable adminimal_admin_toolbar -y"
docker-compose exec drupal bash -lc "[[ \$(drush config:get system.theme admin | grep 'adminimal_theme') =~ 'adminimal_theme' ]] || drush config-set system.theme admin adminimal_theme -y"
docker-compose exec drupal bash -lc "[[ \$(composer show | grep 'migrate_file') =~ 'migrate_file' ]] || composer require 'drupal/migrate_file:^2.0' --with-all-dependencies"
docker-compose exec drupal bash -lc "[[ \$(drush pm-list --type=Module --status=enabled | grep 'migrate_file') =~ 'migrate_file' ]] || drush pm:enable migrate_file -y"
echo -e "\n${PURPLE}+------------ Copying migration_islandora_csv module into the container ------------+ ${NC}"
docker cp "../migrate_islandora_csv" isle-dc_drupal_1:"/var/www/drupal/web/modules/contrib/migrate_islandora_csv"
docker-compose exec drupal bash -lc "drush pm:enable -y migrate_islandora_csv"
docker-compose exec drupal bash -lc "drush cr && drush cron 2> /dev/null"
echo -e "\n${PURPLE}+------------ Uninstalling migrate_islandora_csv ------------+ ${NC}"
docker-compose exec drupal bash -lc "[[ \$(drush pm-list --type=Module --status=enabled | grep 'migrate_islandora_csv') =~ 'migrate_islandora_csv' ]] && drush pm:uninstall -y migrate_islandora_csv"
echo -e "\n${PURPLE}+------------ Installing migrate_islandora_csv ------------+ ${NC}"
docker-compose exec drupal bash -lc 'drush pm:enable -y migrate_islandora_csv'
echo -e "\n${PURPLE}+------------ Deleting the migration(s) configs ------------+ ${NC}"
is_config_on_the_list=$(docker-compose exec drupal bash -lc "echo \"\$(drush config:status --state=Any --format=list --prefix=migrate_plus.migration.${migration_config_names[0]} | sed '/^$/d' | grep ${migration_config_names[0]})\"")
if [[ "$(echo ${is_config_on_the_list// /} | sed '/^$/d')" =~ "migrate_plus.migration.${migration_config_names[0]}" ]]; then
for migration_config_name in "${migration_config_names[@]}"
do
echo "Deleting migrate_plus.migration.${migration_config_name}"
docker-compose exec drupal bash -lc "drush config:delete -y \"migrate_plus.migration.${migration_config_name}\""
done
fi
echo -e "\n${PURPLE}+------------ Copying the new configs into the container ------------+ ${NC}"
for f in ../migrate_islandora_csv/config/install/*.yml; do docker cp "../migrate_islandora_csv/config/install/$(basename $f)" isle-dc_drupal_1:"/var/www/drupal/web/modules/contrib/migrate_islandora_csv/config/install/$(basename $f)"; done
for f in ../migrate_islandora_csv/data/*.csv; do docker cp "../migrate_islandora_csv/data/$(basename $f)" isle-dc_drupal_1:"/var/www/drupal/web/modules/contrib/migrate_islandora_csv/data/$(basename $f)"; done
echo -e "\n${PURPLE}+------------ Importing the migration configs (excluding the group) ------------+ ${NC}"
docker-compose exec drupal bash -lc 'drush config-import --partial --source=modules/contrib/migrate_islandora_csv/config/install/ -y && drush migrate:status -v'
echo -e "\n${PURPLE}+------------ Running the migration import ------------+ ${NC}"
for migration_group in "${migration_groups[@]}"
do
docker-compose exec drupal bash -lc "drush -y --userid=1 migrate:import --group ${migration_group} --verbose"
done
echo -e "\n${PURPLE}+------------ Running the migration end report ------------+ ${NC}"
docker-compose exec drupal bash -lc 'drush migrate:status -v'
echo -e "\n If upload RDF mapping configs, go to https://islandora.traefik.me/admin/config/development/configuration\n to review and import them. This shows you what has changed. I don't suggest clicking the 'import all',\n this will revert the configs. Please review before proceeding with the next step."
sleep 4
echo -e "\n${PURPLE}+------------ Export Configs to config/sync ------------+ ${NC}"
while true; do
read -p "Do you wish to export configs? yn " yn
case $yn in
[Yy]* ) docker-compose exec drupal bash -lc "drush config-export sync -y"; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
sleep 2
echo -e "\n${PURPLE}+------------ done ------------+ ${NC}\n\n"
# drush sql-query "SELECT * FROM migrate_map_collections_file LIMIT 100"