apache-require/migrate.sh
2021-02-01 16:58:20 +01:00

46 lines
936 B
Bash
Executable file

#!/bin/sh
set -e
inventory=$1
tmp_dir=/tmp/apache-require
inventory=$tmp_dir/inventory
to_convert=$tmp_dir/to_convert
# Create a backup of the FILE specific for this project
backup() {
file=$1
cp "$file" "$file".apreq.bak
}
verify_migration() {
if apache2ctl -t; then
echo "the migration produced valid config"
else
echo "the migration went wrong, try doing it manually"
exit 1
fi
}
try_disabling_access_compat() {
if a2dismod access_compat && apache2ctl -t; then
echo "access_compat disabled succesfully!"
else
echo "access_compat can't be disabled, \
some config is still using it"
a2enmod access_compat
fi
}
awk '{ print $1 }' "$inventory" > "$to_convert"
while IFS= read -r file; do
echo $file
backup "$file"
perl -i ~bwaegeneire/convert.pl "$file"
done < "$to_convert"
verify_migration && try_disabling_access_compat