forked from covrig/homeassistant-hline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·76 lines (67 loc) · 1.8 KB
/
update.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
76
#!/bin/bash
function get_file {
DOWNLOAD_PATH=${2}?raw=true
FILE_NAME=$1
if [ "${FILE_NAME:0:1}" = "/" ]; then
SAVE_PATH=$FILE_NAME
else
SAVE_PATH=$3$FILE_NAME
fi
TMP_NAME=${1}.tmp
echo "Getting $1"
# wget $DOWNLOAD_PATH -q -O $TMP_NAME
curl -s -q -L -o $TMP_NAME $DOWNLOAD_PATH
rv=$?
if [ $rv != 0 ]; then
rm $TMP_NAME
echo "Download failed with error $rv"
exit
fi
diff ${SAVE_PATH} $TMP_NAME &>/dev/null
if [ $? == 0 ]; then
echo "File up to date."
rm $TMP_NAME
return 0
else
mv $TMP_NAME ${SAVE_PATH}
if [ $1 == $0 ]; then
chmod u+x $0
echo "Restarting"
$0
exit $?
else
return 1
fi
fi
}
function check_dir {
if [ ! -d $1 ]; then
read -p "$1 dir not found. Create? (y/n): [n] " r
r=${r:-n}
if [[ $r == 'y' || $r == 'Y' ]]; then
mkdir -p $1
else
exit
fi
fi
}
if [ ! -f configuration.yaml ]; then
echo "There is no configuration.yaml in current dir. 'update.sh' should run from Homeassistant config dir"
read -p "Are you sure you want to continue? (y/n): [n] " r
r=${r:-n}
if [[ $r == 'n' || $r == 'N' ]]; then
exit
fi
fi
get_file $0 https://github.com/covrig/homeassistant-hline/blob/master/update.sh ./
check_dir "www/custom_ui"
get_file state-card-hline.html https://raw.githubusercontent.com/covrig/homeassistant-hline/master/www/custom_ui/state-card-hline.html www/custom_ui/
get_file state-card-hline_es5.html https://raw.githubusercontent.com/covrig/homeassistant-hline/master/www/custom_ui/state-card-hline_es5.html www/custom_ui/
echo ""
echo "Add in configuration.yaml : "
echo ""
echo "frontend:"
echo " extra_html_url:"
echo " - /local/custom_ui/state-card-hline.html"
echo " extra_html_url_es5:"
echo " - /local/custom_ui/state-card-hline_es5.html"