Run script commands in a terminal at boot

Hello all,
This time not a real problem, but a question about how to do something.

I am trying to create an automated installation of Kinoite including:
adding RPM-Fusion repo’s,
Nvidia drivers installation and blocking nouveau and nova,
adding flathub repo and installing several flatpacks from flathub.

I have 6 scripts, each ending in a reboot. After the boot the following script is run. (through the correct desktop file in the autostart folder)

A lot of it is working except for 1 major thing:
In my scripts I want to automatically open the Konsole terminal and let the following commands in the script be executed in that terminal.
I found this:
konsole -e ls (ls as simple example command which does no damage)
This should start Konsole, which it does, but I don’t see the execution of the ls command. So I guess this is not happening in Konsole but in free air.
Do I need to transfer my commands from the script into the terminal somehow?

At the moment I am manually trying the ls command above in a terminal and I do see another terminal window flashing after which the original terminal remains with the prompt.
Ten times the same
konsole -e ls
command in the script flashes 10 terminals, one after the other without any visible output from the ls command.

How do I do this, how do I get Konsole to open en all my further commands be executed inside Konsole?

Thanks.

I think this works, but konsole terminates as it should when ls terminates.

Try for example: konsole -e bash -c 'ls; echo Press Enter to terminate; read'

1 Like

Fantastic, it works just as I need it to work. Thank you very much.

Thanks, but I feel that using autostart desktop files for that purpose is rather weird no ?

1 Like

It’s all I could come up with. Is there any other way of doing something like this?

One more thing, I saw the listing output is different from what I normally have. I use an alias ls=‘ls -lh --color’ to get long listing all the time.
Now this alias is not used, am I using a different bash now, or is my .bashrc file not used?

May be with systemd :slight_smile:

  • make 6 systemd services of Type=oneshot for your 6 scripts and with:
    • [Install]
    • WantedBy=multi-user.target
  • configure them to enable the next one and disable itself just before rebooting
  • start the first one

Try konsole -e bash --login -c ...

I can try that as well, thank you again.
Did you read the last lines in my previous post, I added them later so you might have missed them. I wonder why the output of the ls command is different from what I normally have: long listing instead of getting non long listing output.

No, unfortunate it is still the same.
What is the reason you added bash -c to the line? I read the man page but don’t get it what the -c option does, plus I don’t know why bash itself has to be in there.

bash weirdness again :frowning: ~/.bashrc is read only when bash is interactive
Try thus: konsole -e bash -i -c ...

Only to allow executing compound commands: ie: ls followed by waiting.
konsole does not uses the shell to execute the command after -e
(and this is good IMO: safer, easier for managing arguments with spaces)

1 Like

This is getting much more difficult than I hoped for. But it works and if I need the ls command then I can always type ls -l.
I was just reading this page: bash -c but that made it also more complicated. I’m not very familiar with building scripts and hoping to learn from this exercise.
I will search more and in the mean time change my scripts so that I get what I want.

Thank you very much for your time and help, much appreciated.

You can set cron jobs to run at boot. If you do crontab -e and add the command there to run “@reboot”, does that work?

Hi Peter, yes I know about cron jobs, I have used them several times in the past but I wanted to try something new. That part of it all works, I just needed help with opening Konsole from a script and have commands executed in Konsole.

Aren’t there more suitable tools for provisioning?
I don’t really use atomic, but provisioning a new Fedora VM from scratch up to user session defaults is entirely possible with just one Kickstart config and no extra reboots, so I expect atomic to provide a comparable level of efficiency.

1 Like

The normal way would be to create a systemd oneshot service which will run at boot time. Or you can create /etc/rc.d/rc.local as a shell script and make it executable. This shell script can then call your scripts.

I like to point people towards Ansible for something like this instead of custom shell scripts. It has a learning curve, I won’t sugarcoat that, but it can do an enormous amount of things, without having to reinvent the wheel (examining a system, calling commands, handling errors, etc.).

For example, in my playbooks, I have tasks to add the RPM Fusion repos:

RPM Fusion repositories
- name: Import RPM Fusion free GPG key
  become: true
  ansible.builtin.rpm_key:
    state: present
    key: https://rpmfusion.org/keys?action=AttachFile&do=get&target=RPM-GPG-KEY-rpmfusion-free-fedora-2020
    fingerprint: E9A4 91A3 DE24 7814 E7E0 67EA E06F 8ECD D651 FF2E

- name: Enable the RPM Fusion free repository
  become: true
  ansible.builtin.dnf5:
    name: "https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-{{ansible_distribution_major_version}}.noarch.rpm"
    state: present

- name: Import RPM Fusion nonfree GPG key
  become: true
  ansible.builtin.rpm_key:
    state: present
    key: https://rpmfusion.org/keys?action=AttachFile&do=get&target=RPM-GPG-KEY-rpmfusion-nonfree-fedora-2020
    fingerprint: 79BD B88F 9BBF 7391 0FD4 095B 6A2A F961 9484 3C65

- name: Enable the RPM Fusion nonfree repository
  become: true
  ansible.builtin.dnf5:
    name: "https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-{{ansible_distribution_major_version}}.noarch.rpm"
    state: present

Then I have tasks to install RPM packages, remove those I don’t want, etc.:

RPM packages
- name: Remove distribution packages
  become: true
  ansible.builtin.dnf5:
    state: absent
    name: "{{ distro_packages.absent }}"
  when:
    - "distro_packages.absent | length > 0"

- name: Install distribution packages
  become: true
  ansible.builtin.dnf5:
    state: present
    name: "{{ distro_packages.present }}"
  when:
    - "distro_packages.present | length > 0"

- name: Autoremove no longer needed dependencies
  become: true
  ansible.builtin.dnf5:
    autoremove: true
...

Before running these tasks, I load the appropriate distro_packages variable (which contains two lists of packages, absent and present), depending on the distro the target is running. This accounts for different package names and selections for different distros.

Fedora/packages.yml
distro_packages:
  present:
    - cascadia-code-fonts
    - cascadia-mono-fonts
    - cascadia-code-nf-fonts
    - cascadia-mono-nf-fonts
    - distrobox
    - fish
    - fzf
    - gdu
    - mc
    # [...]
  absent:
    - fedora-flathub-remote # Fedora's filtered Flathub remote
    - toolbox # replaced by distrobox above

And finally, I do the same for Flatpaks:

Flatpaks
- name: Add Flathub remote
  become: true
  community.general.flatpak_remote:
    name: flathub
    method: system
    flatpakrepo_url: https://dl.flathub.org/repo/flathub.flatpakrepo
    state: present

- name: Remove Flatpak packages
  become: true
  community.general.flatpak:
    state: absent
    name: "{{ flatpak_packages.absent }}"
  when:
    - "flatpak_packages.absent | length > 0"

- name: Install Flatpak packages
  become: true
  community.general.flatpak:
    state: present
    name: "{{ flatpak_packages.present }}"
  when:
    - "flatpak_packages.present | length > 0"

Note, all of these are are for traditional package-based Fedora, not Atomic. These would need to be adjusted for Kinoite, etc.

1 Like

Hello Lars, I will certainly dive into that, but for now I think, no I know for sure, I will stick to my original idea creating a desktop file for every script and copy/remove them to/from the autostart folder in ~/.config/autostart, just before the necessary reboot.
One because ansible is completely unknown to me and two you wrote

meaning I have to study some more, which will take extra time.
Thank you for pointing out this possibility.

@pedgerow, @vgaetera and @vekruse thank you for your ideas, I will look into those for what could become a version 2 of this exercise, but for now I stick to my original idea. Yes, I know I am stubborn.
@francismontagnac thank you again for helping me with the konsole problem.
That’s it for now, when I should require more help I will open a new thread especially about that issue.
Thanks all.