Révision 3e9236bd
Ajouté par Julien Enselme il y a plus de 9 ans
bin/scripts-utils.sh | ||
---|---|---|
3 | 3 |
# This script contains useful functions for other scripts. |
4 | 4 |
|
5 | 5 |
# Check if scripts-config.sh is imported. |
6 |
if [ -z $scripts_config ] ; then
|
|
6 |
if [ -z "${scripts_config}" ] ; then
|
|
7 | 7 |
echo "Import of scripts-config.sh required." |
8 | 8 |
. scripts-config.sh |
9 | 9 |
fi |
... | ... | |
13 | 13 |
ask_password() { |
14 | 14 |
# read -s doesn't work with sh. |
15 | 15 |
# usage: pass=$(ask_password "password please:") |
16 |
echo $1 >&2
|
|
16 |
echo "$1" >&2
|
|
17 | 17 |
echo -n ">" >&2 |
18 | 18 |
stty_avant=$(stty -g) |
19 | 19 |
stty -echo |
20 | 20 |
read password |
21 |
stty $stty_avant
|
|
22 |
echo "$password"
|
|
21 |
stty "${stty_avant}"
|
|
22 |
echo "${password}"
|
|
23 | 23 |
unset password |
24 | 24 |
} |
25 | 25 |
|
... | ... | |
29 | 29 |
|
30 | 30 |
local site_password='/' |
31 | 31 |
|
32 |
if [ -z $1 ] ; then
|
|
32 |
if [ -z "$1" ] ; then
|
|
33 | 33 |
local password_length=20 |
34 | 34 |
else |
35 |
local password_length=$1
|
|
35 |
local password_length="$1"
|
|
36 | 36 |
fi |
37 | 37 |
|
38 | 38 |
while echo "$site_password" | grep -Fq '/' ; do |
39 |
site_password=$(dd if=/dev/random count=1 | uuencode -m - | head -n 2 | tail -n 1 | cut -c-$password_length)
|
|
39 |
site_password="$(dd if=/dev/random count=1 | uuencode -m - | head -n 2 | tail -n 1 | cut -c-"${password_length}")"
|
|
40 | 40 |
done |
41 | 41 |
|
42 |
echo $site_password
|
|
42 |
echo "$site_password"
|
|
43 | 43 |
} |
44 | 44 |
|
45 | 45 |
count_d7_sites() { |
46 |
find $d7_dir_sites -type d ! -name all -maxdepth 1 | wc -l
|
|
46 |
find "${d7_dir_sites}" -type d ! -name all -maxdepth 1 | wc -l
|
|
47 | 47 |
} |
48 | 48 |
|
49 | 49 |
check_arguments() { |
50 | 50 |
# ARGS: number of arguments passed to script, number of arguments required, [help text] |
51 |
if [ $1 -lt $2 ] ; then
|
|
51 |
if [ "$1" -lt "$2" ] ; then
|
|
52 | 52 |
echo "Number of arguments insuffisant." |
53 |
echo -e $3
|
|
53 |
echo -e "$3"
|
|
54 | 54 |
exit 1 |
55 | 55 |
fi |
56 | 56 |
} |
57 | 57 |
|
58 | 58 |
generate_settings_local() { |
59 | 59 |
# ARGS: site_name, site_password, d7_settings_local_template, d7_site_settings_local |
60 |
sed "s/\%\%DBUSER\%\%/$1/ ; s/\%\%DBNAME\%\%/$1/ ; s/\%\%DBPASS\%\%/$2/ ; s/\%\%SITE_NAME\%\%/$1/" < $3 > $4
|
|
60 |
sed "s/\%\%DBUSER\%\%/$1/ ; s/\%\%DBNAME\%\%/$1/ ; s/\%\%DBPASS\%\%/$2/ ; s/\%\%SITE_NAME\%\%/$1/" < "$3" > "$4"
|
|
61 | 61 |
} |
62 | 62 |
|
63 | 63 |
give_dir() { |
64 | 64 |
# ARG: file |
65 | 65 |
# Return the abosulte directory path of a file or a dir. |
66 |
settings_location=$(realpath $1)
|
|
67 |
echo $(dirname $settings_location)
|
|
66 |
settings_location="$(realpath "$1")"
|
|
67 |
echo "$(dirname "${settings_location}")"
|
|
68 | 68 |
} |
69 | 69 |
|
70 | 70 |
work_tree_clean() { |
71 |
git_status_output=$(git status --porcelain)
|
|
72 |
if [ -z "$git_status_output" ] ; then
|
|
71 |
git_status_output="$(git status --porcelain)"
|
|
72 |
if [ -z "${git_status_output}" ] ; then
|
|
73 | 73 |
return 0 |
74 | 74 |
else |
75 | 75 |
return 1 |
... | ... | |
77 | 77 |
} |
78 | 78 |
|
79 | 79 |
mail_unclean_work_tree() { |
80 |
cd $dir_multi_assos
|
|
81 |
git_status_output=$(git status)
|
|
82 |
echo "$git_status_output" | mail -s "$1" $email_multi_assos
|
|
80 |
cd "$dir_multi_assos"
|
|
81 |
git_status_output="$(git status)"
|
|
82 |
echo "${git_status_output}" | mail -s "$1" "${email_multi_assos}"
|
|
83 | 83 |
} |
84 | 84 |
|
85 | 85 |
commit_if_unclean() { |
86 | 86 |
if ! work_tree_clean ; then |
87 | 87 |
commit_message="COMMIT OF UNCLEAN STUFF" |
88 |
commit -a -m "$commit_message"
|
|
89 |
mail_unclean_work_tree "[git] $commit_message"
|
|
88 |
commit -a -m "${commit_message}"
|
|
89 |
mail_unclean_work_tree "[git] ${commit_message}"
|
|
90 | 90 |
fi |
91 | 91 |
} |
92 | 92 |
|
... | ... | |
96 | 96 |
echo "Empty commit message. Nothing was commited." |
97 | 97 |
return 2 |
98 | 98 |
fi |
99 |
cd $dir_multi_assos
|
|
99 |
cd "${dir_multi_assos}"
|
|
100 | 100 |
git commit -a -m "$1" |
101 | 101 |
} |
102 | 102 |
|
103 | 103 |
site_exists() { |
104 | 104 |
# Check if site database exists. |
105 |
if mysql --defaults-extra-file=$myassos_cnf -e "USE $1" 2>/dev/null ; then
|
|
105 |
if mysql --defaults-extra-file="${myassos_cnf}" -e "USE $1" 2>/dev/null ; then
|
|
106 | 106 |
echo "Database $1 already exits." |
107 | 107 |
return 0 |
108 | 108 |
fi |
109 | 109 |
|
110 | 110 |
# Check if site folder already exists. |
111 |
dir=$d7_dir_sites/$1
|
|
112 |
if [ -d "$dir" ] ; then
|
|
113 |
echo "Foder $dir already exists."
|
|
111 |
dir="${d7_dir_sites}/$1"
|
|
112 |
if [ -d "${dir}" ] ; then
|
|
113 |
echo "Foder ${dir} already exists."
|
|
114 | 114 |
return 0 |
115 | 115 |
fi |
116 | 116 |
return 1 |
Formats disponibles : Unified diff
Update scritp so they respect the new convention.