Sublime Forum

How do you run dev builds on Linux?

#1

I cannot find an easy way to run development builds along side by stable built on Linux. Under Windows, I can do this easy by just downloading a portable stable version of Sublime Text, plus a portable development build of Sublime Text. Once, I open each one of them, they run on a separate process with their own Data/ directory.

How do you do it?

For now, I empowered this shell script:

#!/bin/bash
multi_user_runner="~/sublime_text/run_as_user.sh"

function print_usage() {
    printf "\\n"
    printf "Installation: \\n"
    printf "    chmod +x \\n" "$0"
    printf "\\n"
    printf "Usage: \\n"
    printf "    %s username buildnumber\\n" "$0"
    read -p "Press 'Enter' to continue..." variable1
    exit 1
}
rerunnow="rerunnow"

if [ ! -f "$multi_user_runner" ]
then
    printf "Error: The multiuser runner script was not found in '%s'!\\n" "$multi_user_runner"
    read -p "Press 'Enter' to continue..." variable1
    exit 1
fi

# Open a terminal window to ask for the sudo password
if [ "$1" != "$rerunnow" ]
then
    full_command_line="$0 $rerunnow $(printf '%q ' "${@:1}")"

    declare -a available_terminals=(
            "xfce4-terminal --maximize --command"
            "gnome-terminal --maximize -- /bin/bash -c"
            "terminator --maximise -e"
            "konsole -e /bin/bash -c"
            "xterm -maximize -e"
        )

    for current_command in "${available_terminals[@]}"
    do
        current_terminal=$(printf "%s" "$current_command" | head -n1 | cut -d " " -f1)
        printf "current_terminal: %s, current_command: %s\\n" "$current_terminal" "$current_command"

        if command -v "$current_terminal" >/dev/null 2>&1; then
            $current_command "$full_command_line"
            exit 0
        fi
    done

    printf "Error: No valid terminal found!\\n"
    read -p "Press 'Enter' to continue..." variable1
    exit 1
fi

sublime_text_user=$2
sublime_text_build=$3

if [ -z "$sublime_text_build" ] || [ ! -d "./$sublime_text_build" ]
then
    printf "Error: Invalid destine build '%s'\\n" "$sublime_text_build"
    print_usage
fi

id -u "$sublime_text_user" > /dev/null 2>&1

if [ "$?" != "0" ] || [ -z "$sublime_text_user" ]
then
    printf "Error: Invalid user '%s'\\n" "$sublime_text_user"
    print_usage
fi


function handle_exception() {
    printf "\\n"
    printf "There was some exception while running this script!\\n"
    printf "Check/revise the error messages and decide if it is safe to continue.\\n"
    read -p "If it is safe, press 'Enter' to continue... Otherwise close this terminal window!" variable1
}

source_point="./Data"
mount_point="./$sublime_text_build/Data"
sublime_text_executable="./$sublime_text_build/sublime_text"

mkdir -p "$source_point" "$mount_point" || handle_exception
mountpoint -q "$mount_point" || sudo mount --bind "$source_point" "$mount_point" || handle_exception

if [ "$#" -gt 3 ]
then
    extra_arguments=$(printf '%q ' "${@:4}")
fi

"$multi_user_runner" "$sublime_text_user" "$sublime_text_executable" -n "$extra_arguments" || handle_exception

# read -p "Press 'Enter' to continue..." variable1
printf "Exiting %s...\\n" "$0"
exit 0

To use it, you need to create another a shell script I posted on this other thread and set the variable multi_user_runner pointing to that script path:

Here, I had the following directory structure:

  1. /home/sublime/sublime_text
    • This directory contains all Sublime Text builds I have installed, each build is on a directory named after them, i.e.,
      1. 3194
      2. 3176
      3. etc
  2. /home/sublime/sublime_text/Data
    • This directory contains all Sublime Text files which are going to be mounted inside each Sublime Text build.
      1. 3194/Data
      2. 3176/Data
      3. etc/Data
0 Likes

#2

Just as an aside, both the Linux and OSX versions of Sublime will act like a Windows portable install if you create a Data directory inside of their installation folders alongside the binary. I’m not sure if that’s what your script it doing because it looks fairly complicated.

I have a similar script that takes a build number and just untars first a build and then a second tarball with a stub Data directory (so I don’t need to install a License on first run).

1 Like

Install Sublime Text multiple times on your system?
#3

It does not work here on Linux Mint 19.1 XFCE.

  1. I created the directories sublime1 and sublime2, both with a full copy of Sublime Text build 3176 with a Data directory inside it.
  2. Then, I open sublime1/sublime_text, and it open the first Sublime Text window
  3. But, when I open sublime2/sublime_text (without closing the first Sublime Text window), it does not open/start a new Sublime Text process, it just focus on the first window/process of Sublime Text I had opened.

If I do these same steps on Windows, the result is two (2) Sublime Text processes/windows, not only 1.

0 Likes

#4

Sorry, I meant to add that it doesn’t let you run two copies simultaneously because Sublime uses dbus to communicate with running instances, if that’s what you were trying to do (I’ve never done that because I don’t see the facility in having multiple running copies).

I’m pretty sure that if you stop the dbus daemon, every invocation of Sublime will be distinct because it has no way to talk to a running instance. There have been reported issues where Sublime does this when it’s not wanted, and the reason is that dbus wasn’t running.

0 Likes

#5

Those scripts look rather horrific.

Have you tried creating a Flatpak or container image with Podman… or literally anything that isn’t hacking up usermod commands?

0 Likes

#6

Looks like the main purpose of the script is to run it as a different user. You can also do that with sudo -u <username>, though you don’t get the automatic path setup and stuff as well.

There were some issues with portable and installed builds on parallel on windows that I remember to have reported on the tracker, but for Linux it’s different. I suggest to request better functionality for this as a feature, though I personally haven’t needed this. My package setup is small enough to work for all situations, or I start up less to view big files.

0 Likes

#7

Ow, they are very basic user creation, permission updates, and a way to ask for the sudo password in a new terminal window, so I can use this script directly from thunar or nautilus, i.e., without having to open a new terminal. For example: (use it directly from the context menu)

Thanks for the suggestion! I did not know about that stuff. It seems very promising. I just get scared about how would this affect the application performance, and how it would be configured, i.e., user access, etc. For now, I already setup this. Some other day, when I feel like experimenting with something new, I would definitely try it on.

I am doing that. I am just not using sudo -u but sudo runuser, which should just do the same thing. The other things on the scripts are:

  1. Automatic user creation
  2. Automatic configuration and update of user groups on every start up
  3. And I ask for the sudo password in a terminal window before allowing you do such nasty things, i.e, run a program on another user account.
  4. And share the same Data directory across all builds. This last one, was not required, I could just let them create the standard ~/.config/sublime-text-3/ directory, but I did it just to have some fun with the mount command.

Well, I already got the script working, and I have no complaints about it, except that I need to add everything in my home folder as accessible for my user group, and vice-versa, which is very nasty. Then, may be if I feel like someday, I may open a issue for that. Right now, I got a much bigger issue to attack, there is a week I am writing a memory leaking issue with Sublime Text for Linux (but it does not affect Windows). This one is really pissing me off and it is very hard to create reproducible ways to replicate it. And just now, I figured I have to rewrite everything I have so far, because it is outdated by my new findings.

0 Likes