• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Storing variables to be ignored by git in a js file?

Scheduled Pinned Locked Moved Solved Troubleshooting
14 Posts 4 Posters 3.4k Views 5 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    sdetweil @TimOgden
    last edited by Jan 26, 2022, 9:59 PM

    @timogden no…

    Sam

    How to add modules

    learning how to use browser developers window for css changes

    1 Reply Last reply Reply Quote 0
    • S Offline
      sdetweil @TimOgden
      last edited by sdetweil Jan 26, 2022, 10:15 PM Jan 26, 2022, 10:13 PM

      @timogden

      but u can write a quick bash script that can read the variables and replacements from a file and use sed (stream editor) to apply them

      https://unix.stackexchange.com/questions/268640/make-multiple-edits-with-a-single-call-to-sed

      use a config.model.js which is the one with the funky names to change,
      cp that to config.js
      loop thru the var list to make the command line, then run it

      and exit
      then launch mm

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      T 1 Reply Last reply Jan 26, 2022, 10:15 PM Reply Quote 1
      • T Offline
        TimOgden @sdetweil
        last edited by Jan 26, 2022, 10:15 PM

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

        S 1 Reply Last reply Jan 26, 2022, 10:18 PM Reply Quote 0
        • S Offline
          sdetweil @TimOgden
          last edited by Jan 26, 2022, 10:18 PM

          @timogden u can look at some of my scripts which get a list from a command then loop

          see… restore which reads a file of module urls

          https://github.com/sdetweil/MagicMirror-backup-restore

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          1 Reply Last reply Reply Quote 1
          • K Offline
            karsten13 @TimOgden
            last edited by Jan 26, 2022, 10:19 PM

            @timogden

            you could use envsubst < config/config.js.template > config/config.js.

            The config.js.template is the config for both which contains variables for the different values. So you could write a script which sets the variables for user1 and then run envsubst for config1 and the same for user2/config2 afterwards.

            S 1 Reply Last reply Jan 26, 2022, 10:26 PM Reply Quote 1
            • S Offline
              sdetweil @karsten13
              last edited by Jan 26, 2022, 10:26 PM

              @karsten13 same as I suggested different tool

              but envsubst needs it’s values in the environment variables… so another hidden thing (to me)

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              K 1 Reply Last reply Jan 26, 2022, 10:35 PM Reply Quote 0
              • K Offline
                karsten13 @sdetweil
                last edited by Jan 26, 2022, 10:35 PM

                @sdetweil

                only wanted to post this variant …

                As background: This is a feature of my docker container where you can use a config.js.template and the variables are defined in the docker-compose.yml which starts the container and before starting mm I run envsubst to make the real config.js.

                1 Reply Last reply Reply Quote 1
                • C Offline
                  CFenner @TimOgden
                  last edited by Jan 27, 2022, 6:04 AM

                  @timogden I’ve created a module to extract the config so you don’t need to maintain your own whole MM fork: https://forum.magicmirror.builders/topic/16224/mmm-personalconfig-persist-personal-config-to-github/1

                  A way to achieve what you want could be to create your own copy of personal config with your mirror config. Then make a clone of if for your friend where you do the specific changes. Changes to your repo then can be pulled to the other one via Pull requests.
                  In combination with MMM-UpdateNotification with can pull updates automatically, your friend won’t need to do anything.

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    TimOgden @sdetweil
                    last edited by Jan 27, 2022, 6:12 AM

                    @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.

                    T 1 Reply Last reply Jan 27, 2022, 2:42 PM Reply Quote 1
                    • T Offline
                      TimOgden @TimOgden
                      last edited by Jan 27, 2022, 2:42 PM

                      @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},
                      }
                      ...
                      
                      S 1 Reply Last reply Jan 27, 2022, 2:56 PM Reply Quote 0
                      • 1
                      • 2
                      • 1 / 2
                      1 / 2
                      • First post
                        8/14
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy