magicmirror-v5-install.sh 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. #!/usr/bin/env bash
  2. # Copyright (c) 2021-2023 tteck
  3. # Author: tteck (tteckster)
  4. # License: MIT
  5. # https://github.com/tteck/Proxmox/raw/main/LICENSE
  6. if [ "$VERBOSE" = "yes" ]; then set -x; STD=""; else STD="silent"; fi
  7. silent() { "$@" > /dev/null 2>&1; }
  8. if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; $STD sysctl -p; fi
  9. YW=$(echo "\033[33m")
  10. RD=$(echo "\033[01;31m")
  11. BL=$(echo "\033[36m")
  12. GN=$(echo "\033[1;92m")
  13. CL=$(echo "\033[m")
  14. RETRY_NUM=10
  15. RETRY_EVERY=3
  16. CM="${GN}✓${CL}"
  17. CROSS="${RD}✗${CL}"
  18. BFR="\\r\\033[K"
  19. HOLD="-"
  20. set -Eeuo pipefail
  21. trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
  22. function error_handler() {
  23. local exit_code="$?"
  24. local line_number="$1"
  25. local command="$2"
  26. local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}"
  27. echo -e "\n$error_message\n"
  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. function msg_error() {
  38. local msg="$1"
  39. echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
  40. }
  41. msg_info "Setting up Container OS "
  42. sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
  43. locale-gen >/dev/null
  44. echo $tz > /etc/timezone
  45. ln -sf /usr/share/zoneinfo/$tz /etc/localtime
  46. for ((i=RETRY_NUM; i>0; i--)); do
  47. if [ "$(hostname -I)" != "" ]; then
  48. break
  49. fi
  50. echo 1>&2 -en "${CROSS}${RD} No Network! "
  51. sleep $RETRY_EVERY
  52. done
  53. if [ "$(hostname -I)" = "" ]; then
  54. echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
  55. echo -e " 🖧 Check Network Settings"
  56. exit 1
  57. fi
  58. msg_ok "Set up Container OS"
  59. msg_ok "Network Connected: ${BL}$(hostname -I)"
  60. set +e
  61. trap - ERR
  62. if ping -c 1 -W 1 1.1.1.1 &> /dev/null; then msg_ok "Internet Connected"; else
  63. msg_error "Internet NOT Connected"
  64. read -r -p "Would you like to continue anyway? <y/N> " prompt
  65. if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then
  66. echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}"
  67. else
  68. echo -e " 🖧 Check Network Settings"
  69. exit 1
  70. fi
  71. fi
  72. RESOLVEDIP=$(getent hosts github.com | awk '{ print $1 }')
  73. if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi
  74. set -e
  75. trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
  76. msg_info "Updating Container OS"
  77. $STD apt-get update
  78. $STD apt-get -y upgrade
  79. msg_ok "Updated Container OS"
  80. msg_info "Installing Dependencies"
  81. $STD apt-get install -y curl
  82. $STD apt-get install -y sudo
  83. $STD apt-get install -y mc
  84. $STD apt-get install -y git
  85. msg_ok "Installed Dependencies"
  86. msg_info "Setting up Node.js Repository"
  87. $STD bash <(curl -fsSL https://deb.nodesource.com/setup_16.x)
  88. msg_ok "Set up Node.js Repository"
  89. msg_info "Installing Node.js"
  90. $STD apt-get install -y nodejs
  91. msg_ok "Installed Node.js"
  92. msg_info "Setting up MagicMirror Repository"
  93. $STD git clone https://github.com/MichMich/MagicMirror /opt/magicmirror
  94. msg_ok "Set up MagicMirror Repository"
  95. msg_info "Installing MagicMirror"
  96. cd /opt/magicmirror
  97. $STD npm install --only=prod --omit=dev
  98. cat <<EOF >/opt/magicmirror/config/config.js
  99. let config = {
  100. address: "0.0.0.0",
  101. port: 8080,
  102. basePath: "/",
  103. ipWhitelist: [],
  104. useHttps: false,
  105. httpsPrivateKey: "",
  106. httpsCertificate: "",
  107. language: "en",
  108. locale: "en-US",
  109. logLevel: ["INFO", "LOG", "WARN", "ERROR"],
  110. timeFormat: 24,
  111. units: "metric",
  112. serverOnly: true,
  113. modules: [
  114. {
  115. module: "alert",
  116. },
  117. {
  118. module: "updatenotification",
  119. position: "top_bar"
  120. },
  121. {
  122. module: "clock",
  123. position: "top_left"
  124. },
  125. {
  126. module: "calendar",
  127. header: "US Holidays",
  128. position: "top_left",
  129. config: {
  130. calendars: [
  131. {
  132. symbol: "calendar-check",
  133. url: "webcal://www.calendarlabs.com/ical-calendar/ics/76/US_Holidays.ics"
  134. }
  135. ]
  136. }
  137. },
  138. {
  139. module: "compliments",
  140. position: "lower_third"
  141. },
  142. {
  143. module: "weather",
  144. position: "top_right",
  145. config: {
  146. weatherProvider: "openweathermap",
  147. type: "current",
  148. location: "New York",
  149. locationID: "5128581", //ID from http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city
  150. apiKey: "YOUR_OPENWEATHER_API_KEY"
  151. }
  152. },
  153. {
  154. module: "weather",
  155. position: "top_right",
  156. header: "Weather Forecast",
  157. config: {
  158. weatherProvider: "openweathermap",
  159. type: "forecast",
  160. location: "New York",
  161. locationID: "5128581", //ID from http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city
  162. apiKey: "YOUR_OPENWEATHER_API_KEY"
  163. }
  164. },
  165. {
  166. module: "newsfeed",
  167. position: "bottom_bar",
  168. config: {
  169. feeds: [
  170. {
  171. title: "New York Times",
  172. url: "https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml"
  173. }
  174. ],
  175. showSourceTitle: true,
  176. showPublishDate: true,
  177. broadcastNewsFeeds: true,
  178. broadcastNewsUpdates: true
  179. }
  180. },
  181. ]
  182. };
  183. /*************** DO NOT EDIT THE LINE BELOW ***************/
  184. if (typeof module !== "undefined") {module.exports = config;}
  185. EOF
  186. msg_ok "Installed MagicMirror"
  187. msg_info "Creating Service"
  188. service_path="/etc/systemd/system/magicmirror.service"
  189. echo "[Unit]
  190. Description=Magic Mirror
  191. After=network.target
  192. StartLimitIntervalSec=0
  193. [Service]
  194. Type=simple
  195. Restart=always
  196. RestartSec=1
  197. User=root
  198. WorkingDirectory=/opt/magicmirror/
  199. ExecStart=/usr/bin/node serveronly
  200. [Install]
  201. WantedBy=multi-user.target" >$service_path
  202. $STD systemctl enable --now magicmirror
  203. msg_ok "Created Service"
  204. echo "export TERM='xterm-256color'" >>/root/.bashrc
  205. echo -e "$APPLICATION LXC provided by https://tteck.github.io/Proxmox/\n" > /etc/motd
  206. chmod -x /etc/update-motd.d/*
  207. if ! getent shadow root | grep -q "^root:[^\!*]"; then
  208. msg_info "Customizing Container"
  209. GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
  210. mkdir -p $(dirname $GETTY_OVERRIDE)
  211. cat <<EOF >$GETTY_OVERRIDE
  212. [Service]
  213. ExecStart=
  214. ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
  215. EOF
  216. systemctl daemon-reload
  217. systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
  218. msg_ok "Customized Container"
  219. fi
  220. if [[ "${SSH_ROOT}" == "yes" ]]; then sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config; systemctl restart sshd; fi
  221. msg_info "Cleaning up"
  222. $STD apt-get autoremove
  223. $STD apt-get autoclean
  224. msg_ok "Cleaned"