Code Monkey home page Code Monkey logo

Comments (5)

13hannes11 avatar 13hannes11 commented on June 17, 2024 1

For separate home folders: containers/toolbox#348

# Check if we're running inside a toolbox
TOOLBOX_NAME=""
if [ -f "/run/.containerenv" ]; then
	TOOLBOX_NAME=$(sed -nr 's/^name="(.*)"$/\1/p' /run/.containerenv)
        HOME="$HOME/.toolbox/homedir/$TOOLBOX_NAME/$USER"
        mkdir -p "$HOME"
        bash
        exit 0
fi

from toolbox-tuner.

13hannes11 avatar 13hannes11 commented on June 17, 2024

To launch applications prepend something like

export "HOME=/var/home/USER/.toolbox/homedir/rust/";

from toolbox-tuner.

13hannes11 avatar 13hannes11 commented on June 17, 2024
  1. Create if not exists ~/.bashrc.d
  2. Create file (toolbx_tuner_set_home.sh) in ~/.bashrc.d that reflects application settings with home folders.
  3. create folder ~/.bashrc.d/toolbx_tuner_settings with the files per_app and global_settings
    i. per_app looks as follows:
    Name,Path 
    rust,Hello/ABC
    other,
    
    ii. global_settings looks as follows
    DEFAULT_HOME=$HOME/.toolbx/homedir
    USE_SEPERATE_HOME=false
    and can be loaded with source ~/.bashrc.d/toolbx_tuner_settings/global_settings

Unfinished Script for toolbx_tuner_set_home.sh:

settings_folder=$HOME/.bashrc.d/toolbx_tuner_settings
per_app_settings_file=per_app
global_settings_file=global_settings

if [ -f "/run/.containerenv" ]; then
    TOOLBOX_NAME=$(sed -nr 's/^name="(.*)"$/\1/p' /run/.containerenv)

    not_found=true
    
    # read individual settings
    while IFS="," read tbx home_dir rest; do
        if [ "$tbx" == $TOOLBOX_NAME ]; then                                # if tbx has individual settings stored          
            # Apply custom home dir if set
            if [ "$home_dir" != "" ]; then
                HOME="$home_dir"
                mkdir -p "$HOME"
            fi
            
            not_found=false                                                 # set not_found to false to prevent use of global settings
            break
        fi
    done < <(tail -n +2 $settings_folder/$per_app_settings_file)            # read file from line 2 because of table headers

    # apply global settings if no individual overrides
    if $not_found; then                                                     # use global settings if not found
        source $settings_folder/$global_settings_file                       # load global settings
        if $USE_SEPERATE_HOME ; then
            HOME="$DEFAULT_HOME/$TOOLBOX_NAME"
            mkdir -p "$HOME"
        fi
    fi
    
    # make sure we are not running recursively before entering new bash shell in toolbox
    if [ -n "$RECURSIVE_PROTECTION" ]; then
        RECURSIVE_PROTECTION=true                                           # set recursive protection to prevent infinite loops
        bash
        exit 0
    fi
fi

from toolbox-tuner.

13hannes11 avatar 13hannes11 commented on June 17, 2024

Possible way to store settings:

https://askubuntu.com/questions/671514/shell-script-to-map-fields-and-return-the-corresponding-value-from-list

source <file> can be used to load global setting variables.

https://serverfault.com/questions/219306/control-a-bash-script-with-variables-from-an-external-file

from toolbox-tuner.

13hannes11 avatar 13hannes11 commented on June 17, 2024

In rust use include_str!() to load the contents of the script files at compile time to then create the script files at runtime.

from toolbox-tuner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.