-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxcsites
More file actions
executable file
·147 lines (127 loc) · 4.06 KB
/
xcsites
File metadata and controls
executable file
·147 lines (127 loc) · 4.06 KB
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
#!/bin/bash
a_flag='false'
b_flag='false'
y_flag='false'
filesites=''
verbose='false'
print_usage() {
printf "Usage:\n"
printf "xcsites [options] [arguments]\n\n"
printf "options:\n"
printf "-h|? Affiche cette aide | show brief help\n"
printf "-a A utiliser avec l'option 'f' pour entrer un chemin absolu\n"
printf "-[a]f FICHIER Nom/Chemin du FICHIER des sites à gérer\n"
printf "-y Confirmation automatique\n"
printf "-b (inactif actuellement)\n"
printf "-v Verbeux (inactif actuellement)\n"
}
while getopts 'abyf:vh?' flag; do
case "${flag}" in
a) a_flag='true' ;;
b) b_flag='true' ;;
y) y_flag='true' ;;
f) filesites="${OPTARG}" ;;
v) verbose='true' ;;
h|?) print_usage
exit 1 ;;
esac
done
shift $(($OPTIND - 1))
#printf "Remaining arguments are: %s\n" "$*"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
#printf "DIR: $DIR \n"
# Absolute path to this script. /home/user/bin/foo.sh
SCRIPT=$(readlink -f $0)
# Absolute path this script is in. /home/user/bin
SCRIPTPATH=`dirname $SCRIPT`
#printf "SCRIPT: $SCRIPT / SCRIPTPATH: $SCRIPTPATH \n"
if [ ! -z "$filesites" ]; then
#printf 'Option -f "%s" specified\n' "$filesites"
if [ $a_flag = 'false' ]; then
filename=$SCRIPTPATH/$filesites
else
filename=$filesites
fi
else
filename=$SCRIPTPATH/sites.txt
fi
DORIGINE=`pwd`
IDSITE=1
printf "\e[94m\n"
printf " #####################################################\n"
printf " # Script de gestion de plusieurs instances Drupal #\n"
printf " # [ version 0.5 ] #\n"
printf " #####################################################\n\n"
printf "\e[39mListe les instances à traiter (voir : $filename) : \n"
while IFS= read -r dpath;
do
#Si la ligne est commentée on passe a la suivante
if [[ ${dpath:0:1} == '#' ]]; then
continue
fi
printf " => \e[94m(\e[1m $IDSITE \e[21m)\e[39m $dpath \n";
((IDSITE=IDSITE+1))
done < $filename
((IDSITE=IDSITE-1))
# 2ème parametre
if [ $# -ne 2 ]
then
SITETOUSE="ALL"
else
SITETOUSE=$2
fi
# Infos & Confirmation:
if test "$1" == ""
then
printf "\nIl manque la commande à exécuter ;-)\n"
printf "Exemples : xcsites \"drush status\"\n"
printf " xcsites \"composer require drupal/coffee:1.x-dev@dev\"\n"
printf " xcsites \"composer update\" 2 <-- (pour exécuter seulement sur le site n°2)\n"
exit 1
else
printf "\nExécuter la commande :\e[94m\e[1m $1 \e[21m\e[39m\n"
if [ $SITETOUSE = "ALL" ]
then
printf " sur tous les sites listés [$IDSITE site(s)]\n"
else
printf " sur le site numéro\e[94m\e[1m $SITETOUSE \e[21m\e[39m\n"
fi
fi
getConfirmContinue() {
local REPONSE=""
echo -e " \e[47m\e[31m\e[1m Confirmez ? [oui|yes|o|y] \e[21m\e[39m\e[49m : \c"
read REPONSE
if test "$REPONSE" != "o" -a "$REPONSE" != "y" -a "$REPONSE" != "yes" -a "$REPONSE" != "oui"
# if [[ $REPONSE != "o" || $REPONSE != "y" ]]
then
printf "\e[90m --> Commande annulé, car non confirmée.\e[39m\n"
exit 1
else
return 0
fi
}
if [[ $y_flag != 'true' ]]; then
getConfirmContinue
fi
IDSITE=1
printf "\e[90m\e[4mDébut:\e[24m\e[39m\n"
while IFS= read -r dpath;
do
#Si la ligne est commentée on passe a la suivante
if [[ ${dpath:0:1} == '#' ]]; then
continue
fi
#ALL sites ou un seul.
if [[ $SITETOUSE = "ALL" || $IDSITE = $SITETOUSE ]]; then
printf "\n\e[90msite \e[94m(\e[1m $IDSITE \e[21m)\e[90m >> $dpath <<\e[39m\n\n";
if cd $dpath
then
$1
else
printf "Rien à faire ici ...\n"
fi
fi
((IDSITE=IDSITE+1))
done < $filename
cd $DORIGINE
printf "\n\e[90m\e[4mFin..\e[24m\e[39m\n"