1 |
d52a5b2f
|
jenselme
|
#!/bin/sh
|
2 |
|
|
|
3 |
|
|
# This script contains useful functions for other scripts.
|
4 |
|
|
|
5 |
|
|
# Check if scripts-config.sh is imported.
|
6 |
|
|
if [ -z $scripts_config ] ; then
|
7 |
|
|
echo "Import of scripts-config.sh required."
|
8 |
|
|
. scripts-config.sh
|
9 |
|
|
fi
|
10 |
|
|
|
11 |
|
|
scripts_utils='imported'
|
12 |
|
|
|
13 |
|
|
ask_password() {
|
14 |
|
|
# read -s doesn't work with sh.
|
15 |
|
|
# usage: pass=`ask_password "password please:"`
|
16 |
|
|
echo $1 >&2
|
17 |
|
|
echo -n ">" >&2
|
18 |
|
|
stty_avant=`stty -g`
|
19 |
|
|
stty -echo
|
20 |
|
|
read password
|
21 |
|
|
stty $stty_avant
|
22 |
|
|
echo "$password"
|
23 |
|
|
unset password
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
ask_password_db() {
|
27 |
|
|
# ARGS: server_name, user_name
|
28 |
|
|
local db_password="pour_boucler"
|
29 |
|
|
# empty db request to validate password
|
30 |
|
|
while ! mysql -h $1 -u $2 -p$db_password -e "" 2>/dev/null ; do
|
31 |
|
|
db_password=`ask_password "database password:"`
|
32 |
|
|
done
|
33 |
|
|
echo $db_password
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
generate_password(){
|
37 |
|
|
# ARGS: [password_length]
|
38 |
|
|
# The password contains special characters. '/' must be excluded to avoid sed malfunction.
|
39 |
|
|
|
40 |
|
|
local site_password='/'
|
41 |
|
|
|
42 |
|
|
if [ -z $1 ] ; then
|
43 |
|
|
local password_length=20
|
44 |
|
|
else
|
45 |
|
|
local password_length=$1
|
46 |
|
|
fi
|
47 |
|
|
|
48 |
|
|
while echo "$site_password" | grep -Fq '/' ; do
|
49 |
|
|
site_password=`dd if=/dev/urandom count=1 | uuencode -m - | head -n 2 | tail -n 1 | cut -c-$password_length`
|
50 |
|
|
done
|
51 |
|
|
|
52 |
|
|
echo $site_password
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
count_d7_sites(){
|
56 |
|
|
find $d7_dir_sites -type d ! -name all -maxdepth 1 | wc -l
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
check_arguments() {
|
60 |
|
|
# ARGS: number of arguments passed to script, number of arguments required, [help text]
|
61 |
|
|
if [ $1 -lt $2 ] ; then
|
62 |
|
|
echo "Number of arguments insuffisant."
|
63 |
|
|
echo -e $3
|
64 |
|
|
exit 1
|
65 |
|
|
fi
|
66 |
|
|
} |