MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. TimOgden
    3. Posts
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    T
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 6
    • Groups 0

    Posts

    Recent Best Controversial
    • Custom autostart pm2 script, fixsandbox script doesn't work

      Re: PM2 autostart not working

      About a month ago, I wrote a custom start up script that I called copy_values.sh which replaces a bunch of placeholder strings with their respective values in the config file before running npm start. You can find the thread where I made that solution here.

      Now, I’m trying to get the pm2 autostart to work. Everything is set up exactly how the docs suggest it, but like the thread I am replying to, I get the error about how I can’t run electron as a root without the --no-sandbox tag. I ran @sdetweil 's fixsandbox script, and it does indeed log ‘fixing sandbox permissions’, but then when I run the script again with ‘pm2 start copy_values’, nothing starts, and if I look at the pm2 logs, I see the same issue about the no-sandbox tag.

      Is it because I have a custom installer? I’ve looked at Sam’s script, and it doesn’t seem relative to the mm.sh script that the docs provide, so this should work, but I have no idea why nothing changes. I must be missing something small. Thanks!

      posted in Troubleshooting
      T
      TimOgden
    • RE: Storing variables to be ignored by git in a js file?

      @timogden Also, I should add that there is nothing fancy about the strings on the left-hand side of my dictionary.txt. That’s just how I decided to distinigush them. This is how I would write my config.model.js file now:

      // config/config.model.js
      ...
      config: {
          lat: {latitude},
          lon: {longitude},
          apiKey: {API_KEY},
      }
      ...
      
      posted in Troubleshooting
      T
      TimOgden
    • RE: Storing variables to be ignored by git in a js file?

      @sdetweil Ok, implementing @sdetweil 's suggestions, I have created a working version. This is my workflow.

      // config/dictionary.txt
      // This is a list of key-value or string-replacement pairs
      "{latitude}"    :    "40"
      "{longitude}"    :    "-70"
      
      // installers/copy-values.sh
      // sed command found here: 
      // https://unix.stackexchange.com/questions/269368/string-replacement-using-a-dictionary
      cd ~/MagicMirror
      cp config/config.model.js config/config.js
      sed '
      s|"\(.*\)"[[:blank:]]*:[[:blank:]]*"\(.*\)"|\1\
      \2|
      h
      s|.*\n||
      s|[\&/]|\\&|g
      x
      s|\n.*||
      s|[[\.*^$/]|\\&|g
      G
      s|\(.*\)\n\(.*\)|s/\1/\2/g|
      ' config/dictionary.txt | sed -i -f - config/config.js
      
      DISPLAY=:0 npm start
      

      Now I can have separate dictionary.txt files on both machines for any local important information, which I will add to .gitignore. I will continue to modify config.model.js, and config.model.js will be copied and cleaned up with all the right values before every start of the mirror.

      posted in Troubleshooting
      T
      TimOgden
    • RE: Storing variables to be ignored by git in a js file?

      @sdetweil okay, thanks a lot for the reference material. I’ll work on that and post my solution when I finish. Thanks!

      posted in Troubleshooting
      T
      TimOgden
    • RE: Storing variables to be ignored by git in a js file?

      @sdetweil Could I import a json file into the config.js file instead? Would that be more straightforward?

      posted in Troubleshooting
      T
      TimOgden
    • Storing variables to be ignored by git in a js file?

      Hey all. I have my own smart mirror and I recently created one for my girlfriend.

      I’ve set it up so both mine and hers are clones of my forked repo of the MitchMitch MagicMirror repo. I want to be able to make changes on mine and then let her pull those changes so she doesn’t have to mess with the files herself.

      The only issue is there are some things specific to our own mirrors, like the latitude and longitude for weather, or the link to our google calendars. The solution I came up with is to create another config file which I’ll add to .gitignore,

      // config/variables_config.js
      const variables = {
          lat: 40.0000,
          lon: -70.0000
      };
      export { variables };
      

      So I should be able to use these variables in my usual config.js file, right?

      // config/config.js
      import { variables } from 'variables_config.js'
      ...
      {
          module: "weather",
          config: {
              lat: variables.lat,
              lon: variables.lon
          }
      }
      

      Adding the import statement breaks the config file though. Running npm run config:check returned Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

      I need config.js to be a module I guess? Sorry, I’m a programmer but have almost zero javascript experience, so I need some guidance as to how to fix this or what the better solution is here. Thank you!

      posted in Troubleshooting
      T
      TimOgden
    • 1 / 1