├── settings └── .gitkeep ├── templates ├── app │ ├── start-server.sh │ └── start-browser.sh ├── .xserverrc ├── .xinitrc └── systemd │ └── magic-mirror.service ├── setup ├── cleanup.sh ├── scripts │ ├── install-browser.sh │ ├── setup-boot-options.sh │ ├── install-minimal-gui.sh │ ├── install-magic-mirror.sh │ ├── setup-plymouth.sh │ ├── copy-app-files.sh │ ├── setup-magic-mirror-service.sh │ ├── install-node.sh │ └── setup-xserver-on-startup.sh └── run.sh ├── LICENSE ├── README.md ├── .gitignore └── install.sh /settings/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /templates/app/start-server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd %%MAGIC_MIRROR_DIR%% 4 | node serveronly -------------------------------------------------------------------------------- /setup/cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | info 'Cleaning up setup files' 4 | sudo rm -rf "$MAGIC_MIRROR_RASP_LITE_DIR" -------------------------------------------------------------------------------- /setup/scripts/install-browser.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | info "Installing Chromium Browser" 4 | sudo apt install -y chromium-browser -------------------------------------------------------------------------------- /templates/.xserverrc: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # based on /etc/X11/xinit/xserverrc 4 | exec /usr/bin/X -nolisten tcp "$@" vt${XDG_VTNR} 5 | -------------------------------------------------------------------------------- /setup/scripts/setup-boot-options.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | info 'Enabling auto login to console as user `pi`' 4 | sudo raspi-config nonint do_boot_behaviour B2 5 | -------------------------------------------------------------------------------- /templates/.xinitrc: -------------------------------------------------------------------------------- 1 | # disable DPMS (Energy Star) features 2 | xset -dpms 3 | # disable screen saver 4 | xset s off 5 | # disable video device going blank 6 | xset s noblank 7 | -------------------------------------------------------------------------------- /setup/scripts/install-minimal-gui.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | info "Installing Minimal GUI" 4 | sudo apt install -y \ 5 | xserver-xorg \ 6 | xinit \ 7 | matchbox \ 8 | unclutter \ 9 | plymouth \ 10 | plymouth-themes -------------------------------------------------------------------------------- /templates/systemd/magic-mirror.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Magic Mirror Service 3 | After=network.target 4 | 5 | [Service] 6 | Type=simple 7 | User=%%USER%% 8 | WorkingDirectory=%%HOME_DIR%% 9 | ExecStart=%%ENTRY_POINT%% 10 | Restart=on-failure 11 | 12 | [Install] 13 | WantedBy=multi-user.target -------------------------------------------------------------------------------- /setup/scripts/install-magic-mirror.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd "$MAGIC_MIRROR_DIR" 4 | 5 | ARM=$(uname -m) 6 | 7 | info 'Installing Magic Mirror dependencies' 8 | 9 | # Raspberry Pi Zero? 10 | if [ "$ARM" == 'armv6l' ]; then 11 | # MagicMirror has a dependency for electron 12 | # But electron only supports `armv7l` 13 | npm --arch=armv7l install electron 14 | fi 15 | 16 | npm install 17 | 18 | info 'Setting up default config' 19 | # Copy default sample file 20 | cp config/config.js.sample config/config.js -------------------------------------------------------------------------------- /setup/scripts/setup-plymouth.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | THEME_NAME='MagicMirror' 4 | PLYMOUTH_THEME_DIR=/usr/share/plymouth/themes 5 | THEME_DIR=$PLYMOUTH_THEME_DIR/$THEME_NAME 6 | 7 | info 'Setting up Magic Mirror splash screen' 8 | sudo mkdir -p "$THEME_DIR" 9 | sudo cp $MAGIC_MIRROR_DIR/splashscreen/* $THEME_DIR 10 | 11 | info 'Enable Magic Mirror splash screen' 12 | if sudo plymouth-set-default-theme -R "$THEME_NAME"; then 13 | success "Splashscreen: Changed theme to MagicMirror successfully." 14 | else 15 | error "Splashscreen: Couldn't change theme to MagicMirror!" 16 | fi -------------------------------------------------------------------------------- /setup/scripts/copy-app-files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | TEMPLATE_DIR=$MAGIC_MIRROR_RASP_LITE_DIR/templates 4 | 5 | info "Copying app files '$MAGIC_MIRROR_APP_DIR'" 6 | cp $TEMPLATE_DIR/app/* $MAGIC_MIRROR_APP_DIR 7 | 8 | # replace placeholders 9 | FILES=$MAGIC_MIRROR_APP_DIR/* 10 | for f in $FILES 11 | do 12 | sudo sed -i -e "s|%%MAGIC_MIRROR_DIR%%|$MAGIC_MIRROR_DIR|g" "$f" 13 | sudo sed -i -e "s|%%MAGIC_MIRROR_HOST%%|$MAGIC_MIRROR_HOST|g" "$f" 14 | sudo sed -i -e "s|%%MAGIC_MIRROR_PORT%%|$MAGIC_MIRROR_PORT|g" "$f" 15 | done 16 | 17 | # make files executable 18 | sudo chmod a+x -R "$MAGIC_MIRROR_APP_DIR" -------------------------------------------------------------------------------- /templates/app/start-browser.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | MAGIC_MIRROR_HOST='%%MAGIC_MIRROR_HOST%%' 4 | MAGIC_MIRROR_PORT='%%MAGIC_MIRROR_PORT%%' 5 | 6 | # clean up error notifications in chromium (crash reports) 7 | sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' ~/.config/chromium/'Local State' 8 | sed -i 's/"exited_cleanly":false/"exited_cleanly":true/; s/"exit_type":"[^"]\+"/"exit_type":"Normal"/' ~/.config/chromium/Default/Preferences 9 | 10 | unclutter & \ # hide mouse cursor 11 | matchbox-window-manager & \ # window manager for xinit 12 | chromium-browser --noerrdialogs --kiosk --incognito --disable-translate "http://$MAGIC_MIRROR_HOST:$MAGIC_MIRROR_PORT" 13 | -------------------------------------------------------------------------------- /setup/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SETUP_SCRIPTS_DIR=$MAGIC_MIRROR_RASP_LITE_DIR/setup/scripts 4 | 5 | # install required packages 6 | . $SETUP_SCRIPTS_DIR/install-node.sh 7 | . $SETUP_SCRIPTS_DIR/install-minimal-gui.sh 8 | . $SETUP_SCRIPTS_DIR/install-browser.sh 9 | 10 | # install magic mirror even if the user don't want to run magic mirror server 11 | # since we use this for splash screen 12 | . $SETUP_SCRIPTS_DIR/install-magic-mirror.sh 13 | 14 | # setup options 15 | . $SETUP_SCRIPTS_DIR/copy-app-files.sh 16 | . $SETUP_SCRIPTS_DIR/setup-boot-options.sh 17 | . $SETUP_SCRIPTS_DIR/setup-magic-mirror-service.sh 18 | . $SETUP_SCRIPTS_DIR/setup-plymouth.sh 19 | . $SETUP_SCRIPTS_DIR/setup-xserver-on-startup.sh 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 PureArtisan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /setup/scripts/setup-magic-mirror-service.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SERVICE_NAME='magic-mirror' 4 | SERVICE_FILE="$SERVICE_NAME.service" 5 | 6 | TEMPLATE_DIR=$MAGIC_MIRROR_RASP_LITE_DIR/templates 7 | SYSTEMD_PATH=/etc/systemd/system 8 | SERVICE_PATH="$SYSTEMD_PATH/$SERVICE_FILE" 9 | 10 | MM_SERVER_STARTUP="$MAGIC_MIRROR_APP_DIR/start-server.sh" 11 | 12 | info "Copying service file into '$SYSTEMD_PATH'" 13 | sudo cp "$TEMPLATE_DIR/systemd/$SERVICE_FILE" "$SERVICE_PATH" 14 | 15 | # replace placeholders 16 | sudo sed -i -e "s|%%ENTRY_POINT%%|$MM_SERVER_STARTUP|g" "$SERVICE_PATH" 17 | sudo sed -i -e "s|%%USER%%|$USER|g" "$SERVICE_PATH" 18 | sudo sed -i -e "s|%%HOME_DIR%%|$HOME_DIR|g" "$SERVICE_PATH" 19 | 20 | # reset permissions 21 | sudo chmod 644 "$SERVICE_PATH" 22 | sudo chown root:root "$SERVICE_PATH" 23 | 24 | ACTION='Enabling' 25 | if ! $MAGIC_MIRROR_SETUP; then 26 | ACTION='Disabling' 27 | fi 28 | 29 | info "$ACTION Magic Mirror Service..." 30 | sudo systemctl daemon-reload 31 | 32 | # now we can check if the user wants to setup 33 | if $MAGIC_MIRROR_SETUP; then 34 | success "Enabling service" 35 | sudo systemctl enable "$SERVICE_NAME" 36 | else 37 | success "Skipping Magic Mirror server setup (per user input)" 38 | sudo systemctl disable "$SERVICE_NAME" 39 | fi -------------------------------------------------------------------------------- /setup/scripts/install-node.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if which node > /dev/null 4 | then 5 | 6 | info "node is installed, skipping node setup..." 7 | 8 | else 9 | 10 | # taken from the the official magic mirror installer script: 11 | # https://github.com/MichMich/MagicMirror/blob/v2.10.1/installers/raspberry.sh 12 | 13 | cd ~/ 14 | 15 | NODE_MAJOR_VERSION="12" 16 | ARM=$(uname -m) 17 | 18 | if [[ "$ARM" = "armv7l" ]] 19 | then 20 | echo "Original 'ARM' value is: $ARM, so using 'armv6l'" 21 | ARM="armv6l" 22 | fi 23 | 24 | info "Installing node" 25 | 26 | # node official debian distribution doesn't support ARM, so using unofficial distribution 27 | sudo apt-get install -y --only-upgrade libstdc++6 28 | 29 | node_ver=$(curl -sL https://unofficial-builds.nodejs.org/download/release/index.tab | grep $ARM | grep -m 1 v$NODE_MAJOR_VERSION | awk '{print $1}') 30 | echo "Latest release in the $NODE_MAJOR_VERSION family for $ARM is $node_ver" 31 | 32 | NODE_TAR_FILE="node_release-$node_ver.tar.gz" 33 | 34 | curl -sL https://unofficial-builds.nodejs.org/download/release/$node_ver/node-$node_ver-linux-$ARM.tar.gz >"$NODE_TAR_FILE" 35 | echo "using release tar file = '$NODE_TAR_FILE' and extracting to '/usr/local'" 36 | 37 | cd /usr/local 38 | sudo tar --strip-components 1 -xzf "$HOME_DIR/$NODE_TAR_FILE" 39 | cd - >/dev/null 40 | 41 | rm "$HOME_DIR/$NODE_TAR_FILE" 42 | 43 | fi 44 | 45 | echo "Node version:" 46 | node -v 47 | 48 | echo "NPM version:" 49 | npm -v 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Magic Mirror for Raspbian Lite 2 | 3 | A quick and easy, single command to setup [Magic Mirror](https://github.com/MichMich/MagicMirror) on Raspbian Lite. This script will install all required dependencies and a minimal GUI to run MagicMirror on Raspbian Lite (non-desktop version). 4 | 5 | ## Quick Setup 6 | 7 | Simply run the command on your Raspberry Pi (this has been tested on Pi Zero W). 8 | 9 | *NOTE*: This script can take a while as it updates Rasbian package manager and pulls in all dependencies. 10 | 11 | ``` 12 | bash -c "$(curl -sL https://raw.githubusercontent.com/pureartisan/magic-mirror-raspbian-lite/master/install.sh?$(date +%s))" 13 | ``` 14 | 15 | You will be asked a upto 3 questions, and then everything will happen autoamtically. Sit back and relax, or go have a coffee! :) 16 | 17 | ### Minimum Requirements 18 | 19 | It is expected that you have the following already setup: 20 | * Raspbian Lite installed 21 | * The Raspberry Pi has an active internet connection 22 | * You have something better to do while the script does it's magic!!! :) 23 | 24 | ## What does this do? 25 | 26 | This script sets up the following in your Raspbian Lite setup: 27 | * [X11](https://www.x.org/wiki/) (minimal GUI required to run a browser) 28 | * [Chromium](https://www.chromium.org/getting-involved/download-chromium) (using fullscreen chromium kiosk mode) 29 | * [Node](https://nodejs.org/en/) (required by MagicMirror) 30 | * [MagicMirror](https://magicmirror.builders/) 31 | * [Plymouth](https://gitlab.freedesktop.org/plymouth/plymouth) (pretty splash screens used by MagicMirror) 32 | * Auto login to Raspberry Pi -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | # Settings 107 | /settings/* 108 | -------------------------------------------------------------------------------- /setup/scripts/setup-xserver-on-startup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | TEMPLATE_DIR=$MAGIC_MIRROR_RASP_LITE_DIR/templates 4 | COMMENT_MM_RASP_LITE='#### Auto entry - Magic Mirror Raspbian Lite' 5 | 6 | XINITRC=~/.xinitrc 7 | XINITRC_BACKUP=~/.xinitrc.backup 8 | 9 | XSERVERRC=~/.xserverrc 10 | XSERVERRC_BACKUP=~/.xserverrc.backup 11 | 12 | BASHRC=~/.bashrc 13 | BASHRC_BACKUP=~/.bashrc.backup 14 | 15 | info 'Setting up X Server on startup' 16 | 17 | # ----------------------------------------------- 18 | # changes to .xinitrc 19 | # ----------------------------------------------- 20 | 21 | # create backup if file already exists 22 | if [ -f "$XINITRC" ] 23 | then 24 | echo "File existing, so creating backup of $XINITRC" 25 | cp $XINITRC $XINITRC_BACKUP 26 | fi 27 | 28 | info "Adding '$XINITRC' file..." 29 | 30 | # copy the xinitrc file 31 | cp $TEMPLATE_DIR/.xinitrc $XINITRC 32 | sudo chmod a+x $XINITRC 33 | 34 | # add the entry point 35 | echo "# start app" >> $XINITRC 36 | echo "$MAGIC_MIRROR_APP_DIR/start-browser.sh" >> $XINITRC 37 | 38 | 39 | # ----------------------------------------------- 40 | # changes to .xserverrc 41 | # ----------------------------------------------- 42 | 43 | # create backup if file already exists 44 | if [ -f "$XSERVERRC" ] 45 | then 46 | echo "File existing, so creating backup of $XSERVERRC" 47 | cp $XSERVERRC $XSERVERRC_BACKUP 48 | fi 49 | 50 | info "Adding '$XSERVERRC' file..." 51 | 52 | # copy the xserverrc file 53 | cp $TEMPLATE_DIR/.xserverrc $XSERVERRC 54 | sudo chmod a+x $XSERVERRC 55 | 56 | 57 | # ----------------------------------------------- 58 | # changes to .bashrc 59 | # ----------------------------------------------- 60 | 61 | touch "$BASHRC" 62 | 63 | if grep -q "$COMMENT_MM_RASP_LITE" "$BASHRC" 64 | then 65 | 66 | echo "Entry already found, so skipping changes to $BASHRC" 67 | 68 | else 69 | 70 | info "Creating backup of $BASHRC" 71 | if [ -f "$BASHRC" ] 72 | then 73 | cp $BASHRC $BASHRC_BACKUP 74 | fi 75 | 76 | info "Adding entry to $BASHRC" 77 | 78 | echo "$COMMENT_MM_RASP_LITE | START" >> $BASHRC 79 | # if not connecting via SSH only 80 | echo 'if [ -z "$SSH_CLIENT" ] || [ -z "$SSH_TTY" ]; then' >> $BASHRC 81 | # start xinit (browser will start using the .xinitrc file) 82 | echo ' xinit -- -nocursor' >> $BASHRC 83 | echo 'fi' >> $BASHRC 84 | echo "$COMMENT_MM_RASP_LITE | END" >> $BASHRC 85 | 86 | fi 87 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # stop on error 4 | set -e 5 | 6 | cd ~/ 7 | HOME_DIR=$(pwd) 8 | 9 | MM_RASP_LITE="magic-mirror-raspbian-lite" 10 | MAGIC_MIRROR_RASP_LITE_DIR="$HOME_DIR/$MM_RASP_LITE" 11 | 12 | MAGIC_MIRROR_NAME="magic-mirror" 13 | MAGIC_MIRROR_DIR="$HOME_DIR/$MAGIC_MIRROR_NAME" 14 | 15 | MAGIC_MIRROR_APP_DIR="$HOME_DIR/magic-mirror-app" 16 | 17 | MAGIC_MIRROR_SETUP=true 18 | MAGIC_MIRROR_HOST="localhost" 19 | MAGIC_MIRROR_PORT="8080" 20 | 21 | MAGIC_MIRROR_RASP_LITE_GIT='https://github.com/pureartisan/magic-mirror-raspbian-lite.git' 22 | MAGIC_MIRROR_GIT='https://github.com/MichMich/MagicMirror' 23 | 24 | REGEX_NUMERIC_ONLY='^[0-9]+$' 25 | 26 | # show installer splash 27 | clear 28 | 29 | echo -e "\e[33m" 30 | echo '$$\ $$\ $$\ $$\ $$\ $$\ $$$$$$\ ' 31 | echo '$$$\ $$$ | \__| $$$\ $$$ |\__| $$ __$$\ ' 32 | echo '$$$$\ $$$$ | $$$$$$\ $$$$$$\ $$\ $$$$$$$\ $$$$\ $$$$ |$$\ $$$$$$\ $$$$$$\ $$$$$$\ $$$$$$\ \__/ $$ |' 33 | echo '$$\$$\$$ $$ | \____$$\ $$ __$$\ $$ |$$ _____|$$\$$\$$ $$ |$$ |$$ __$$\ $$ __$$\ $$ __$$\ $$ __$$\ $$$$$$ |' 34 | echo '$$ \$$$ $$ | $$$$$$$ |$$ / $$ |$$ |$$ / $$ \$$$ $$ |$$ |$$ | \__|$$ | \__|$$ / $$ |$$ | \__|$$ ____/ ' 35 | echo '$$ |\$ /$$ |$$ __$$ |$$ | $$ |$$ |$$ | $$ |\$ /$$ |$$ |$$ | $$ | $$ | $$ |$$ | $$ | ' 36 | echo '$$ | \_/ $$ |\$$$$$$$ |\$$$$$$$ |$$ |\$$$$$$$\ $$ | \_/ $$ |$$ |$$ | $$ | \$$$$$$ |$$ | $$$$$$$$\ ' 37 | echo '\__| \__| \_______| \____$$ |\__| \_______|\__| \__|\__|\__| \__| \______/ \__| \________|' 38 | echo ' $$\ $$ | ' 39 | echo ' \$$$$$$ | ' 40 | echo ' \______/ ' 41 | echo -e "\e[1;32m" 42 | echo ' ' 43 | echo '$$$$$$$\ $$\ $$\ $$\ $$\ $$\ ' 44 | echo '$$ __$$\ $$ | \__| $$ | \__| $$ | ' 45 | echo '$$ | $$ | $$$$$$\ $$$$$$$\ $$$$$$\ $$$$$$$\ $$\ $$$$$$\ $$$$$$$\ $$ | $$\ $$$$$$\ $$$$$$\ ' 46 | echo '$$$$$$$ | \____$$\ $$ _____|$$ __$$\ $$ __$$\ $$ | \____$$\ $$ __$$\ $$ | $$ |\_$$ _| $$ __$$\ ' 47 | echo '$$ __$$< $$$$$$$ |\$$$$$$\ $$ / $$ |$$ | $$ |$$ | $$$$$$$ |$$ | $$ | $$ | $$ | $$ | $$$$$$$$ |' 48 | echo '$$ | $$ |$$ __$$ | \____$$\ $$ | $$ |$$ | $$ |$$ |$$ __$$ |$$ | $$ | $$ | $$ | $$ |$$\ $$ ____|' 49 | echo '$$ | $$ |\$$$$$$$ |$$$$$$$ |$$$$$$$ |$$$$$$$ |$$ |\$$$$$$$ |$$ | $$ | $$$$$$$$\ $$ | \$$$$ |\$$$$$$$\ ' 50 | echo '\__| \__| \_______|\_______/ $$ ____/ \_______/ \__| \_______|\__| \__| \________|\__| \____/ \_______|' 51 | echo ' $$ | ' 52 | echo ' $$ | ' 53 | echo ' \__| ' 54 | echo -e "\e[0m" 55 | 56 | function drawLine() { 57 | printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' = 58 | } 59 | 60 | function info() { 61 | echo -e "\e[1;45m$1\e[0m" 62 | drawLine 63 | } 64 | 65 | function success() { 66 | echo -e "\e[1;32m$1\e[0m" 67 | } 68 | 69 | function error() { 70 | echo -e "\e[1;91m$1\e[0m" 71 | } 72 | 73 | # draw line before asking questions 74 | drawLine 75 | 76 | echo "Magic Mirror server will be installed on this Raspberry Pi." 77 | echo "However, you can use setup and/or connect to another Magic Mirror server via the network." 78 | 79 | echo "Would you like to setup the Magic Mirror server on this Raspberry Pi? [Y/n]" 80 | while true; do 81 | read input 82 | case $input in 83 | ""|[Yy]* ) 84 | MAGIC_MIRROR_SETUP=true 85 | break;; 86 | [Nn]* ) 87 | MAGIC_MIRROR_SETUP=false 88 | break;; 89 | * ) echo "Please answer y(es) or n(o).";; 90 | esac 91 | done 92 | 93 | if ! $MAGIC_MIRROR_SETUP; then 94 | 95 | echo "What is the HOST for the Magic Mirror server? Enter IP address (or hostname)." 96 | while true; do 97 | read input 98 | if [ -z "$input" ] 99 | then 100 | echo "Please enter a valid host." 101 | else 102 | MAGIC_MIRROR_HOST=$input 103 | break; 104 | fi 105 | done 106 | 107 | echo "What is the PORT for the Magic Mirror server? Enter server port." 108 | while true; do 109 | read input 110 | if ! [[ $input =~ $REGEX_NUMERIC_ONLY ]] 111 | then 112 | echo "Please enter a valid port." 113 | else 114 | MAGIC_MIRROR_PORT=$input 115 | break; 116 | fi 117 | done 118 | 119 | fi 120 | 121 | drawLine 122 | success "The rest will be automatic, so sit back and relax..." 123 | echo "" 124 | echo "" 125 | drawLine 126 | 127 | # Updating package managers 128 | info 'Updating Pi - this may take a while...' 129 | sudo apt-get -y update 130 | info 'Upgrading Pi - this may take a while too...' 131 | sudo apt-get -y upgrade 132 | sudo apt-get -y upgrade --fix-missing 133 | 134 | info 'Installing git' 135 | sudo apt install -y git 136 | 137 | info 'Cloning "Magic Mirror"' 138 | if [ -d "$MAGIC_MIRROR_DIR" ]; then 139 | success "Magic Mirror already exists, pulling latest" 140 | cd "$MAGIC_MIRROR_DIR" > /dev/null 141 | git reset --hard 142 | git pull origin 143 | cd > /dev/null 144 | else 145 | git clone "$MAGIC_MIRROR_GIT" "$MAGIC_MIRROR_NAME" 146 | fi 147 | 148 | info 'Cloning "Magic Mirror for Raspbian Lite"' 149 | if [ -d "$MAGIC_MIRROR_RASP_LITE_DIR" ]; then 150 | success "Magic Mirror for Raspbian Lite already exists, pulling latest" 151 | cd "$MAGIC_MIRROR_RASP_LITE_DIR" > /dev/null 152 | git reset --hard 153 | git pull origin 154 | cd > /dev/null 155 | else 156 | git clone "$MAGIC_MIRROR_RASP_LITE_GIT" "$MM_RASP_LITE" 157 | fi 158 | 159 | info 'Creating app directory' 160 | # remove if it already exists 161 | sudo rm -rf "$MAGIC_MIRROR_APP_DIR" 162 | # create app dir 163 | mkdir -p "$MAGIC_MIRROR_APP_DIR" 164 | # list the directory 165 | cd "$MAGIC_MIRROR_APP_DIR" > /dev/null 166 | cd .. > /dev/null 167 | ls -la 168 | cd ~/ > /dev/null 169 | 170 | # export so the child scripts can access them 171 | export HOME_DIR 172 | export MAGIC_MIRROR_RASP_LITE_DIR 173 | export MAGIC_MIRROR_DIR 174 | export MAGIC_MIRROR_APP_DIR 175 | export MAGIC_MIRROR_SETUP 176 | export MAGIC_MIRROR_HOST 177 | export MAGIC_MIRROR_PORT 178 | 179 | # start the proper setup 180 | . $MAGIC_MIRROR_RASP_LITE_DIR/setup/run.sh 181 | . $MAGIC_MIRROR_RASP_LITE_DIR/setup/cleanup.sh 182 | 183 | info 'Rebooting now...' 184 | sudo reboot 185 | 186 | # end of the script --------------------------------------------------------------------------------