What's new

Setting up new environment variable that gets set on boot before entware applications start and more?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

domic

Regular Contributor
I want to add a environment variable to my router that runs before rclone starts (I put rclone command in the post-mount script), but also sets itself for both any ssh sessions I start, and system-wide so the rclone program always knows where it's new 'default config location' always will be. Oh, and I need this environment variable (envar?) to work in any shell, (sh, bash (are there others?) are built-in as we know, I use fish for my ssh sessions).

Doing this because typing 'rclone --config /tmp/mnt/usb_drive/dir1/dir2/rclone.conf config' instead of 'rclone config' etc is quite annoying having to remember the same thing every time I connect via ssh.

I'm thinking:

#!/bin/sh
# rclone config new default location
RCLONE_CONFIG=/dir/dir/rclone.conf
EXPORT RCLONE_CONFIG

or maybe just a

set RCLONE_CONFIG=/dir/rclone.conf
 
Doing this because typing 'rclone --config /tmp/mnt/usb_drive/dir1/dir2/rclone.conf config' instead of 'rclone config' etc is quite annoying having to remember the same thing every time I connect via ssh.
For interactive login shell sessions, you can simply define an alias for a command that requires typing a long string of arguments. For the router built-in Almquist shell, you can define your own custom aliases in the "/jffs/configs/profile.add" file.

For example:
Bash:
alias dorclone='rclone --config /tmp/mnt/usb_drive/dir1/dir2/rclone.conf config'
Now, every time you log in via SSH using the built-in shell, you need to type only "dorclone" on the terminal window to execute the associated command string.

Other command line shells that you have installed on the router via Entware should have a similar mechanism where a "profile" or configuration file can be created/modified to add your own custom aliases. For example, for the bash shell there is the "$HOME/.bash_aliases" file.

I don't use or know the "fish" shell at all so I can't help you with specific instructions, but perhaps look for something like "config.fish" in the $HOME directory to add your own custom aliases.
 
Last edited:
That seems kind of like a quick fix solution. I'm looking for a more robust solution that according to the Rclone documentation uses the RCLONE_CONFIG envar. Problem is that my shell script game isn't strong at the moment, as every attempt to have the system run post-mount script set "sh" envars and export (even with "sh -c 'command'") i don't know if it's just set on the user root or not at all, but either way, I can't test it because the ssh sessions use the admin user.

I guess I'll try my luck at the rclone forums. I'll keep the alias in mind though. It's easier to forget about the aliases you set up, rather than the documented commands you can just Google online, but with a envar set up manually by you in my opinion.
 
If you want to add or change the environment variables for an interactive session you should use /jffs/etc/profile which is called from /etc/profile.

N.B. /jffs/etc/profile is only supported on HND routers. For pre-HND routers use /jffs/configs/profile.add.

For non-interactive scripts you need to set them in the script itself. Like you did in your script in post #1, except it's export not EXPORT.
 
Last edited:
Screenshot_20220830-204032.jpg

This comment I found seems interesting.
I was wondering if I could run the envar and the export commands on console-login (so it's system-wide for both interactive and non-interactive sessions) via "/opt/etc/profile(.add" if necessary).
What do you think? Would that be viable?
 
Screenshot_20220830-204618~2.jpg

Currently my "post-mount" script looks like this by the way.

Neither that nor "sh -c command" added my envars or export for ssh sessions on either sh/bash or fish.

I did test with small letters for "export" command after testing them manually in the shell earlier this week.
 
/jffs/etc/profile, /opt/etc/profile and /jffs/configs/profile.add all do the same thing. The only difference is that /opt/etc/profile doesn't exist until the Entware filesystem is mounted and /jffs/configs/profile.add is only used if "custom scripts and configs" is enabled. None of them affect non-interactive sessions, that's not their purpose.

It is the responsibility of the script writer to setup the required variables if it's going to be used in a non-interactive way. You can set the variables in the script itself or source them from one of the profiles above instead.

Your post-mount script won't work because you're trying to use Entware programs before the entware-usb filesystem is mounted (by mount-entware.div). A post-mount script doesn't affect interactive sessions.
 
/jffs/etc/profile, /opt/etc/profile and /jffs/configs/profile.add all do the same thing. The only difference is that /opt/etc/profile doesn't exist until the Entware filesystem is mounted and /jffs/configs/profile.add is only used if "custom scripts and configs" is enabled. None of them affect non-interactive sessions, that's not their purpose.

It is the responsibility of the script writer to setup the required variables if it's going to be used in a non-interactive way. You can set the variables in the script itself or source them from one of the profiles above instead.

Your post-mount script won't work because you're trying to use Entware programs before the entware-usb filesystem is mounted (by mount-entware.div). A post-mount script doesn't affect interactive sessions.
Hm okay, how would you do it for non-interactive sessions, like console? I could run it in parallel with the interactive profile scripts.
 

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top