/
installer.sh
executable file
·75 lines (67 loc) · 2.32 KB
/
installer.sh
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
#!/bin/bash
cecho () {
declare -A colors;
colors=(\
['black']='\E[0;47m'\
['red']='\E[0;31m'\
['green']='\E[0;32m'\
['yellow']='\E[0;33m'\
['blue']='\E[0;34m'\
['magenta']='\E[0;35m'\
['cyan']='\E[0;36m'\
['white']='\E[0;37m'\
);
local defaultMSG="No message passed.";
local defaultColor="black";
local defaultNewLine=true;
while [[ $# -gt 1 ]];
do
key="$1";
case $key in
-c|--color)
color="$2";
shift;
;;
-n|--noline)
newLine=false;
;;
*)
# unknown option
;;
esac
shift;
done
message=${1:-$defaultMSG}; # Defaults to default message.
color=${color:-$defaultColor}; # Defaults to default color, if not specified.
newLine=${newLine:-$defaultNewLine};
echo -en "${colors[$color]}";
echo -en "$message";
if [ "$newLine" = true ] ; then
echo;
fi
tput sgr0; # Reset text attributes to normal without clearing screen.
}
### Colors ##
ESC=$(printf '\033') RESET="${ESC}[0m" BLACK="${ESC}[30m" RED="${ESC}[31m"
GREEN="${ESC}[32m" YELLOW="${ESC}[33m" BLUE="${ESC}[34m" MAGENTA="${ESC}[35m"
CYAN="$ESC[36m" WHITE="${ESC}[37m" DEFAULT="${ESC}[39m"
cyanprint() { printf "${CYAN}%s${RESET}\n" "$1"; }
_process() {
echo -e "\n"
cyanprint " → $@"
}
_success() {
printf "\n%s✓ Success:%s\n" "$(tput setaf 2)" "$(tput sgr0) $1"
}
cecho -c 'blue' "Welcome to the RPi Dashboard installer!"
read -p "This setup assumes you have a working web server installed that is up and running. Continue? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
hostn="`hostname`"
cecho -c 'blue' "This setup will install the dashboard to /var/www/html."
_process "Please choose your subfolder name, so you will be able to call the dashboard at http://$hostn/{your_subfolder_name}"
read -p "Enter custom subfolder name: " subfoldern
cd /var/www/html
git clone https://github.com/femto-code/Raspberry-Pi-Dashboard $subfoldern
_process "Setting up valid permissions for /var/www/html/$subfoldern..."
sudo chown -R ${whoami}:www-data /var/www/html/$subfoldern
sudo chmod -R 775 /var/www/html/$subfoldern
_success "Installation done! To access the dashboard open up a web browser with URL: http://$hostn/$subfoldern"