forked from Jopyth/MMM-Remote-Control
-
Notifications
You must be signed in to change notification settings - Fork 1
/
installer.sh
executable file
·179 lines (163 loc) · 6.06 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env bash
# This is an experimental installer script for MagicMirror2 Remote-Control
echo ""
echo "Installation for the MagicMirror2 Remote-Control module started!"
echo ""
echo "Notice: This script and the installed software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software."
echo ""
check_yes() {
read -p ">>> $1 [y/N]? " -n 1 REPLY
echo ""
if [[ ! "$REPLY" =~ ^[Yy]$ ]]; then
return 1
fi
return 0
}
check_no() {
read -p ">>> $1 [Y/n]? " -n 1 REPLY
echo ""
if [[ $REPLY =~ ^[Nn]$ ]]; then
return 1
fi
return 0
}
if check_yes "Continue?"; then
echo ""
else
exit 0
fi
# assume default install location
MM_HOME=$HOME/MagicMirror
# check if we are correct by searching for https://github.com/MichMich/MagicMirror in package.json
TEST_STRING="\"url\": \"git+https://github.com/MichMich/MagicMirror.git\""
if grep -sq "$TEST_STRING" "$MM_HOME/package.json"; then
# we found it
echo -n ""
else
# assume we are in the correct directory
MM_HOME=`pwd`
if grep -sq "$TEST_STRING" "$MM_HOME/package.json"; then
# found it again
echo -n ""
else
echo "Could not find MagicMirror2 installation directory."
echo "Please start this script again from the MagicMirror directory."
exit 1
fi
fi
if [ -d "$MM_HOME/modules/MMM-Remote-Control" ] ; then
# already installed
echo "Directory $MM_HOME/modules/MMM-Remote-Control already exists."
echo ""
cd "$MM_HOME/modules/MMM-Remote-Control"
BRANCH="$(git symbolic-ref HEAD 2>/dev/null)" || BRANCH="(unnamed branch)" # detached HEAD
BRANCH=${BRANCH##refs/heads/}
echo "You are currently on the $BRANCH branch."
echo ""
if [ "$BRANCH" == "master" ]; then
if check_yes "Do you want to switch to the develop branch?"; then
git checkout develop
fi
else
if check_yes "Do you want to switch to the master branch?"; then
git checkout master
fi
fi
echo ""
if check_no "Do you want to update your branch?"; then
echo ""
echo "Pulling changes..."
git pull
if [ $? -ne 0 ]; then
echo "Could not pull successfully."
exit 1;
fi
echo ""
echo "Checking for new dependencies to install..."
echo ""
npm install
if [ $? -ne 0 ]; then
echo "Failed to install new dependencies."
exit 1;
fi
echo "Done."
echo ""
echo "Update finished!"
else
echo "Already installed, not upgrading."
fi
else
echo "MagicMirror2 detected in: $MM_HOME"
echo ""
if check_yes "Is this correct and do you want to start installation?"; then
echo ""
echo "You can use either the master or the develop branch."
echo "The develop branch contains more features, but is also more likely to cause errors or crashes."
echo "This can be changed later by executing this script again, or using the git branch command."
echo ""
echo "By default the master branch will be installed."
echo ""
if check_yes "Do you want to install the develop branch instead?"; then
BRANCH=develop
else
BRANCH=master
fi
cd "$MM_HOME/modules"
echo ""
echo "Cloning the repository on $BRANCH branch..."
echo ""
git clone https://github.com/Jopyth/MMM-Remote-Control.git -b $BRANCH
if [ $? -ne 0 ]; then
echo "Failed. Do you have an internet connection?"
exit 1;
fi
cd MMM-Remote-Control
echo ""
echo "Installing dependencies..."
echo ""
npm install
if [ $? -ne 0 ]; then
echo "Failed to install dependencies."
exit 1;
fi
echo "Done."
echo ""
echo "Installation finished."
else
echo "Installation skipped."
fi
fi
echo ""
if check_no "Do you want to view instructions on how to configure the module?"; then
echo "(1) Please add the following snippet into your modules array in your config.js:"
echo " -------------- copy below this line --------------"
echo " {"
echo " module: 'MMM-Remote-Control'"
echo " // uncomment the following line to show the URL of the remote control on the mirror"
echo " // , position: 'bottom_left'"
echo " // you can hide this module afterwards from the remote control itself"
echo " },"
echo " -------------- copy above this line --------------"
echo ""
echo "(2) Make sure to add the IPs of your devices from which you want to access the Remote Control to the ipWhitelist array."
echo " If for example have a phone with the IP address 192.168.0.50 search for the following line:"
echo " ipWhitelist: [\"127.0.0.1\", \"::ffff:127.0.0.1\", \"::1\"],"
echo " and add your IP to the list:"
echo " ipWhitelist: [\"127.0.0.1\", \"::ffff:127.0.0.1\", \"::1\", \"::ffff:192.168.0.50\"],"
echo ""
if check_no "Got it?"; then
echo ""
else
echo ""
echo "Please have a look at the links below for help."
echo ""
fi
fi
echo "Have fun with the module, if you have any problems, please search for help on github or in the forum:"
echo ""
echo " Github : https://github.com/Jopyth/MMM-Remote-Control"
echo " Forum : http://forum.magicmirror.builders"
echo ""
echo "Do not forget to restart your MagicMirror2 to activate the module! Installed finished."
echo ""
exit 0