Home
Post
Cancel

“The cosmic operating system uses a command line interface. It runs on something like a teletype, with lots of noise and heat; punched-out bits flutter down into its hopper like drifting stars. The demiurge sits at his teletype, pounding out one command line after another, specifying the values of fundamental constants of physics:

universe -G 6.672e-11 -e 1.602e-19 -h 6.626e-34 -protonmass 1.673e-27

and when he’s finished typing out the command line, his right pinky hesitates above the enter key for an aeon or two, wondering what’s going to happen; then down it comes—and the whack you hear is another Big Bang.”

― Neal Stephenson, In the Beginning…Was the Command Line

MirrorCommand

MagicMirror is an open source modular smart mirror platform (see https://magicmirror.builders/). This repository maintains an extensive set of scripts to initialize, configure, monitor, and manage a MagicMirror.

MirrorCommand is one of the Neoman managed projects:

Overview

The Mirror Command Line project provides scripts to enable command line control of the MagicMirror system over a local network. The MirrorCommand Debian and RPM format package installation scripts perform automatic installation and configuration of a MagicMirror including:

  • Automated installation of the MagicMirror software if not already installed
  • Automated configuration of the MagicMirror
  • Automated installation and configuration of several MagicMirror modules
  • PM2 process manager installation and configuration
  • Semi-automated key management to enable a single source for adding, storing, and managing the several keys necessary to activate many MagicMirror modules
  • Hundreds of MagicMirror configuration files preconfigured with layouts for both portrait and landscape mode displays and module activation

The mirror command can be installed on your MagicMirror to issue MagicMirror commands. Currently the command line MagicMirror control scripts include support for:

  • Specifying the MagicMirror configuration file to activate
  • Starting, stopping, and restarting the MagicMirror
  • Display of various system info
    • Temperature
    • Memory
    • Disk
    • Usb
    • Network
    • Wireless
    • Screen
  • List active/installed MagicMirror modules
  • List available MagicMirror configuration files
  • Rotate the MagicMirror screen
  • Get or set the brightness level
  • Control MagicMirror video playback
    • Start/Stop video play
    • Replay video
    • Play next video
    • Hide video playback module
    • Show video playback module
  • Control the MagicMirror audio output volume level
  • Get MagicMirror status
  • Update the MagicMirror installation or update installed modules
  • Auto generation of new MagicMirror configuration files
  • Interactive mode via menu dialogs
    • Invoked with no arguments the mirror command displays a command menu.

Compatibility

MirrorCommand has been successfully deployed and tested on a Raspberry Pi 4 and Raspberry Pi 400 running Raspbian Buster. It has also been deployed and tested on Ubuntu Linux 20.04 and Fedora Linux 35 with generic x86_64 hardware.

It has been tested on systems with a mirror display and systems with a standard computer monitor display. MirrorCommand version 2.7 and later has been tested on systems with multiple monitors. Testing has been performed on systems with a variety of screen resolutions and orientation including 1920x1080 portrait mode display, 2560x1440 landscape mode display, and 1920x1080 landscape mode display. Deployment of the MirrorCommand MagicMirror configuration files on screens with display resolution differing significantly from those tested may require changes to the module positions, layout, and geometry.

MirrorCommand installation packages are available in both the Debian packaging format and the RPM packaging format so the automated installation is available for all systems that support Debian or RPM packaging formats. That’s most Linux environments.

Installation

See the MirrorCommand Installation section for detailed installation instructions.

Configuration

See the MirrorCommand Configuration section for detailed configuration instructions.

Custom Package Creation

You can create your own custom Debian and RPM format packages from the repository source. To do so, clone the MirrorCommand repository:

git clone ssh://gitlab.com/doctorfree/MirrorCommand.git

or

git clone https://gitlab.com/doctorfree/MirrorCommand.git

Use the mkpkg script to create Debian and RPM format packages on a system with the prerequisite packaging development environment. Once packages have been created in the source repository they can be installed by executing the ./Install command. Packages can be removed with ./Uninstall.

Removal

On Debian based Linux systems where the MirrorCommand package was installed using the MirrorCommand Debian format package, remove the MirrorCommand package by executing the command:

 sudo apt remove mirrorcommand

or

 sudo dpkg -r mirrorcommand
  

Note: Removal may issue a warning about removing /usr/local and other folders within /usr/local. This is an artifact of the Debian packaging system. If you wish to silence that warning and prevent the Debian packaging system from trying to remove /usr/local then install the core-custom-local Debian package.

On RPM based Linux systems where the MirrorCommand package was installed using the MirrorCommand RPM format package, remove the MirrorCommand package by executing the command:

 sudo yum remove MirrorCommand

or

 sudo rpm -e MirrorCommand
  

Supporting utilities and config files

There are several supporting scripts that can be used to enhance command line capabilites. These are installed in /usr/local/MirrorCommand/bin with symbolic links created in /usr/local/bin. Ensure that /usr/local/bin is in your execution PATH.

Many sample MagicMirror configuration files are provided in the /usr/local/MirrorCommand/config directory. The installation package script attempts to link these into your MagicMirror config folder. The sample config files use the naming convention config-<name>.js.

Several custom CSS files are provided in the `/usr/local/MirrorCommand/css directory. Copy and modify as needed.

Some of the more useful supporting scripts include:

  • audiotest Test the ALSA audio configuration by playing test sounds to each speaker
  • camsnap Snap a photo with your MagicMirror webcam
  • chkconfig Check your MagicMirror configuration files
  • chkinst Check your Mirror Command Line installation
  • chktemp Check your MagicMirror Raspberry Pi temperature
  • get_temps Get your MagicMirror Raspberry Pi temperature
  • gethue Get your Hue Hub properties
  • getquote Get a stock symbol quote
  • mmapiactions Get the MMM-Remote-Control API actions
  • mmgetb Get the MagicMirror screen brightness level
  • mmsetb Set the MagicMirror screen brightness level
  • myreboot Perform additional actions before reboot, executed as a normal user using sudo
  • myshutdown Perform additional actions before shutdown, executed as a normal user using sudo
  • rand_back Select a random desktop wallpaper
  • set_asound_conf Set the ALSA sound configuration in /etc/asound.conf
  • vncview Remote script to start a VNC server on your MagicMirror and a VNC viewer on your desktop
  • vol Script to control volume level of MagicMirror audio output
  • wireless_conf Configure wireless using WPA Supplicant
  • wireless_dot_sample Sample $HOME/.wireless to assist in wireless configuration

Integration

See the MirrorCommand Integration section for information on integration of MirrorCommand with external components.

Documentation

See the MirrorCommand Documentation section for MirrorCommand documentation, man pages, and usage.

Motivation

Introduction to Using the Command Line

The command line has a long and storied history in computing. Read some of that history, learn how to open a command line terminal window on various systems, how to get started using the command line, and see some examples of why the command line interface is so powerful by reading the MirrorCommand article Introduction to Using the Command Line.

This introduction to the command line includes an example of how to automate display of a specified menu on a MagicMirror at designated times of day.

Why would I need or want command line control of MagicMirror

One might reasonably ask “Why would I need or want command line control of my MagicMirror”? Truth be told, most MagicMirror users do not need or want command line control of MagicMirror or any other software. They are happy with the graphical user interfaces they use and never ever see a command line prompt. So the answer to that question is almost always “You don’t”.

However, some users (mostly old propeller head codgers) are comfortable at the command line and prefer to use it over the tedious mouse clicks required to get anything done in a graphical user interface. Different lanes for different brains.

I would say the most significant use case for command line control of anything is automation. For example, if I want to schedule playback of specified music in specific zones triggered by some event, then command line control can be used to implement this. That can be done via Cron jobs, play something in some zone at scheduled times. Or playback of specified songs in selected zones could be triggered by some event like when a particular face is recognized by my smart mirror or when my smart lights are turned to a particular profile. I use command line control of MagicMirror coupled with Apple Siri voice commands that trigger an SSH shortcut to run the command. There are many use cases for automation using command line utilities.

The other main use case for command line control is simple convenience. If you spend a lot of time in a Shell environment then it is just easier to type a command that plays what you would like to hear where you want to hear it than it is to switch windows, bring up a GUI, click a few times to find what you want, and click to play it, then go back to your terminal window and Shell env. Most people do not live in a Shell environment like I do so this use case is not that significant.

Finally, the command line interface and the associated MagicMirror API can provide capabilities not otherwise available. Searching, listing, and filtering can be augmented by the plethora of tools available in a typical Shell environment. You can pipe the output of a mirror command to grep, sed, awk, and other standard utilities to produce results difficult to achieve otherwise. That is, command line control along with the API and Shell utilities/builtins can extend the capabilities of the MagicMirror system. The MirrorCommand package also enables some features not easily available in MagicMirror. One of these, management of a large number of preconfigured MagicMirror config files, allows the MirrorCommand user to easily and quickly switch between any of these preconfigured config files. In my household I find it frequently desirable to be able to switch MagicMirror configs easily and quickly and I can do so by configuring these presets to my typical use cases and executing a simple mirror command.

History

This project began as an attempt to control my MagicMirror with Siri voice commands. I was able to get Siri voice control of a MagicMirror working with simple SSH shortcuts that execute Bash scripts on my mirror’s Raspberry Pi. Apple’s SSH shortcuts are a powerful tool for command line control. They can be used to execute commands on systems that allow SSH access and they can be configured to activate via voice commands. SSH shortcuts enable voice control of anything that can be done at the command line.

I created shortcuts on my iPhone which use the “Run script over SSH” option for Apple Scripting shortcuts. The shortcuts execute the appropriate Bash command on my MagicMirror Pi. Once I got the MagicMirror shortcuts working I then configured Siri to recognize various phrases to run those shortcuts. In this manner I was able to implement Siri voice control of my MagicMirror.

Over time the project became primarily focused on the command line execution of these scripts as I found I spend more time in a terminal at the command line than I do talking to Siri. While voice control is still supported if configured properly, the project is primarily command line control of MagicMirror.

Recent releases have focused on automated installation and configuration as well as configuration based upon auto-detected system features. Some aspects of the automated installation of MagicMirror drew upon previous work by Sam Detweiler in his MagicMirror scripts project.

Contents

See the Commands section for a partial contents listing of commands and configuration files.

Known Limitations

The following are known limitations in the current release:

  • The installation packages are interactive and cannot be integrated into an unattended install process
  • The MirrorCommand config files are modified by the showkeys command in a manner that prevents subsequent key value changes and a rerun of showkeys
    • A key value can be added to an empty key array entry and showkeys rerun
    • Once a key value has been set in mirrorkeys and showkeys has been run, that value is hard coded in all config files that use it
  • If a secondary monitor is attached but the system does not recognize it as “connected” then it will not be added to the mirrorscreens config file and the mirror command will not recognize it
    • In some cases it is necessary to power on the monitor prior to booting the system in order for the X11 graphical system to recognize the monitor
  • Significant effort has been made to adjust the module layouts in all config files to create a MagicMirror display with non-overlapping regions. However, some screen resolutions may need manual adjustment of some config files to arrive at a pleasant display. Testing has been limited to only a few screen resolutions and display modes.
  • The current release does not fully support seamless upgrades nor have upgrades been thoroughly tested. If a future upgrade of the MirrorCommand package fails or does not entirely complete, the recommended procedure is to backup all MagicMirror and MirrorCommand files, remove the MirrorCommand package, and install the newer MirrorCommand package.

Screenshots

Sample default and weather configs

default weather

Interactive menus when invoked with no arguments

menu submenu

License

Copyright: 2014-2023 Ronald Joe Record

License: MIT