magicmirror-install.sh 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #!/usr/bin/env bash
  2. YW=`echo "\033[33m"`
  3. RD=`echo "\033[01;31m"`
  4. BL=`echo "\033[36m"`
  5. GN=`echo "\033[1;92m"`
  6. CL=`echo "\033[m"`
  7. RETRY_NUM=10
  8. RETRY_EVERY=3
  9. NUM=$RETRY_NUM
  10. CM="${GN}✓${CL}"
  11. CROSS="${RD}✗${CL}"
  12. BFR="\\r\\033[K"
  13. HOLD="-"
  14. set -o errexit
  15. set -o errtrace
  16. set -o nounset
  17. set -o pipefail
  18. shopt -s expand_aliases
  19. alias die='EXIT=$? LINE=$LINENO error_exit'
  20. trap die ERR
  21. function error_exit() {
  22. trap - ERR
  23. local reason="Unknown failure occured."
  24. local msg="${1:-$reason}"
  25. local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
  26. echo -e "$flag $msg" 1>&2
  27. exit $EXIT
  28. }
  29. function msg_info() {
  30. local msg="$1"
  31. echo -ne " ${HOLD} ${YW}${msg}..."
  32. }
  33. function msg_ok() {
  34. local msg="$1"
  35. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  36. }
  37. msg_info "Setting up Container OS "
  38. sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
  39. locale-gen >/dev/null
  40. while [ "$(hostname -I)" = "" ]; do
  41. 1>&2 echo -en "${CROSS}${RD} No Network! "
  42. sleep $RETRY_EVERY
  43. ((NUM--))
  44. if [ $NUM -eq 0 ]
  45. then
  46. 1>&2 echo -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
  47. exit 1
  48. fi
  49. done
  50. msg_ok "Set up Container OS"
  51. msg_ok "Network Connected: ${BL}$(hostname -I)"
  52. msg_info "Updating Container OS"
  53. apt update &>/dev/null
  54. apt-get -qqy upgrade &>/dev/null
  55. msg_ok "Updated Container OS"
  56. msg_info "Installing Dependencies"
  57. apt-get install -y curl &>/dev/null
  58. apt-get install -y sudo &>/dev/null
  59. apt-get install -y git &>/dev/null
  60. msg_ok "Installed Dependencies"
  61. msg_info "Setting up Node.js Repository"
  62. curl -fsSL https://deb.nodesource.com/setup_18.x | bash - &>/dev/null
  63. msg_ok "Set up Node.js Repository"
  64. msg_info "Installing Node.js"
  65. apt-get install -y nodejs &>/dev/null
  66. msg_ok "Installed Node.js"
  67. msg_info "Setting up MagicMirror Repository"
  68. git clone https://github.com/MichMich/MagicMirror /opt/magicmirror &>/dev/null
  69. msg_ok "Set up MagicMirror Repository"
  70. msg_info "Installing MagicMirror"
  71. cd /opt/magicmirror &>/dev/null
  72. npm install --only=prod --omit=dev &>/dev/null
  73. cat <<EOF > /opt/magicmirror/config/config.js
  74. let config = {
  75. address: "0.0.0.0",
  76. port: 8080,
  77. basePath: "/",
  78. ipWhitelist: [],
  79. useHttps: false,
  80. httpsPrivateKey: "",
  81. httpsCertificate: "",
  82. language: "en",
  83. locale: "en-US",
  84. logLevel: ["INFO", "LOG", "WARN", "ERROR"],
  85. timeFormat: 24,
  86. units: "metric",
  87. serverOnly: true,
  88. modules: [
  89. {
  90. module: "alert",
  91. },
  92. {
  93. module: "updatenotification",
  94. position: "top_bar"
  95. },
  96. {
  97. module: "clock",
  98. position: "top_left"
  99. },
  100. {
  101. module: "calendar",
  102. header: "US Holidays",
  103. position: "top_left",
  104. config: {
  105. calendars: [
  106. {
  107. symbol: "calendar-check",
  108. url: "webcal://www.calendarlabs.com/ical-calendar/ics/76/US_Holidays.ics"
  109. }
  110. ]
  111. }
  112. },
  113. {
  114. module: "compliments",
  115. position: "lower_third"
  116. },
  117. {
  118. module: "weather",
  119. position: "top_right",
  120. config: {
  121. weatherProvider: "openweathermap",
  122. type: "current",
  123. location: "New York",
  124. locationID: "5128581", //ID from http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city
  125. apiKey: "YOUR_OPENWEATHER_API_KEY"
  126. }
  127. },
  128. {
  129. module: "weather",
  130. position: "top_right",
  131. header: "Weather Forecast",
  132. config: {
  133. weatherProvider: "openweathermap",
  134. type: "forecast",
  135. location: "New York",
  136. locationID: "5128581", //ID from http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city
  137. apiKey: "YOUR_OPENWEATHER_API_KEY"
  138. }
  139. },
  140. {
  141. module: "newsfeed",
  142. position: "bottom_bar",
  143. config: {
  144. feeds: [
  145. {
  146. title: "New York Times",
  147. url: "https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml"
  148. }
  149. ],
  150. showSourceTitle: true,
  151. showPublishDate: true,
  152. broadcastNewsFeeds: true,
  153. broadcastNewsUpdates: true
  154. }
  155. },
  156. ]
  157. };
  158. /*************** DO NOT EDIT THE LINE BELOW ***************/
  159. if (typeof module !== "undefined") {module.exports = config;}
  160. EOF
  161. msg_ok "Installed MagicMirror"
  162. msg_info "Creating Service"
  163. service_path="/etc/systemd/system/magicmirror.service"
  164. echo "[Unit]
  165. Description=Magic Mirror
  166. After=network.target
  167. StartLimitIntervalSec=0
  168. [Service]
  169. Type=simple
  170. Restart=always
  171. RestartSec=1
  172. User=root
  173. WorkingDirectory=/opt/magicmirror/
  174. ExecStart=/usr/bin/node serveronly
  175. [Install]
  176. WantedBy=multi-user.target" > $service_path
  177. systemctl enable --now magicmirror &>/dev/null
  178. msg_ok "Created Service"
  179. PASS=$(grep -w "root" /etc/shadow | cut -b6);
  180. if [[ $PASS != $ ]]; then
  181. msg_info "Customizing Container"
  182. chmod -x /etc/update-motd.d/*
  183. touch ~/.hushlogin
  184. GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
  185. mkdir -p $(dirname $GETTY_OVERRIDE)
  186. cat << EOF > $GETTY_OVERRIDE
  187. [Service]
  188. ExecStart=
  189. ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
  190. EOF
  191. systemctl daemon-reload
  192. systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
  193. msg_ok "Customized Container"
  194. fi
  195. msg_info "Cleaning up"
  196. apt-get autoremove >/dev/null
  197. apt-get autoclean >/dev/null
  198. rm -rf /var/{cache,log}/* /var/lib/apt/lists/*
  199. msg_ok "Cleaned"