-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhacksql
executable file
·44 lines (34 loc) · 1.57 KB
/
hacksql
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
#!/bin/bash
# hacksql
# Hacks moodle database sql file, replacing the search value with the replacevalue
search= # Search for
replace= # Replace with
datbase= # SQL file to process
if [ "$#" -ne 6 ]; then
echo "Illegal number of parameters"
printf "Usage hacksql -s <search term> -r <replace term> -d <sql file> \n"
printf "example: hacksql -s 'sit-lms.literacyhub.edu.au' -r 'merlin.lih_moodle.edu.au' -d 'lih_moodle_database_bak_sit_38.221121.sql' \n"
exit 2
fi
while getopts "s:r:d:h" param; do
case "${param}" in
s) search="$OPTARG";;
r) replace="$OPTARG";;
d) database="$OPTARG";;
h) printf "Usage hacksql -s <search term> -r <replace term> -d <sql file> \n"
printf "example: hacksql -s 'sit-lms.literacyhub.edu.au' -r 'merlin.lih_moodle.edu.au' -d 'lih_moodle_database_bak_sit_38.221121.sql' \n"
exit 2;;
?) printf "Usage hacksql -s <search term> -r <replace term> -d <sql file> \n"
printf "example: hacksql -s 'sit-lms.literacyhub.edu.au' -r 'merlin.lih_moodle.edu.au' -d 'lih_moodle_database_bak_sit_38.221121.sql' \n"
exit 2;;
esac
done
shift $((OPTIND-1))
printf "sed -e \"s/${search}/${replace}/g\" ${database} > nu_${database}"
if [ ! -z "${search}" ] && [ ! -z "${replace}" ] && [ ! -z "${database}" ]; then
printf "sed -e \"s/${search}/${replace}/g\" ${database} > nu_${database}"
sed -e "s/${search}/${replace}/g" "${database}" > "nu_${database}"
else
# printf "Usage hacksql -s <search term> -r <replace term> -d <sql file> \n"
exit
fi