new.sh: do not overwrite the existing .gitignore file, just append to it
[drupal-init-tools.git] / libexec / clean.sh
1 #!/bin/bash
2 # Clean up a Drupal project directory
3 #
4 # Copyright (C) 2017  Antonio Ospite <ao2@ao2.it>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 set -e
20
21 usage() {
22   cat <<EOF
23 usage: drin $(basename "$0" .sh) [-h|--help]
24
25 Cleanup the project, removing all the installed files.
26
27 Options:
28   -h, --help          display this usage message and exit
29 EOF
30 }
31
32 while [ $# -gt 0 ];
33 do
34   case "$1" in
35     -h|--help)
36       usage
37       exit 0
38       ;;
39     -*)
40       echo "Error: Unknown option '${1}'" 1>&2
41       ;;
42   esac
43   shift
44 done
45
46 [ -f "bootstrap.conf" ] || { echo "Aborting, run this command from the Drupal project directory." 1>&2; exit 1; }
47
48 CONFIRMATION_STRING="YESIAMSURE"
49
50 echo "WARNING! This removes any files in the config/ web/ and vendor/ directories."
51 echo "Are you sure you want to continue?"
52 echo
53 read -r -p "Type ${CONFIRMATION_STRING} to confirm: " INPUT
54
55 run() {
56   echo "$@"
57   "$@"
58 }
59
60 [ "$INPUT" = "$CONFIRMATION_STRING" ] && run sudo --reset-timestamp rm -rf config/ web/ vendor/ composer.lock