How can I write a Bash script to update system and Flatpak packages?

0
8
Asked By MellowPine42 On

I'm using PikaOS, a Debian-based distribution, and I'm new to both Linux and shell scripting. I'd like to create a small updater script that I can launch from a widget button.

The script should open a terminal, ask whether I've backed up my files with Timeshift, and stop with a reminder if I answer no. If I confirm the backup, it should run `pikman upgrade` and then update my Flatpak packages with `flatpak update`. Running both update commands concurrently would be nice, but running them sequentially is fine too.

My current script is:

```bash
#!/bin/bash
x-terminal-emulator --hold -e pikman upgrade
```

When I launch it this way, I don't see a normal shell prompt such as `user@host:~$`, so I'm unsure when the command has finished. How can I keep the terminal open and return to an interactive prompt afterward?

2 Answers

Answered By CopperLynx7 On

You can launch a shell inside the terminal and put the checks and update commands in that shell. Ask for backup confirmation first, exit if the answer isn’t `y`, run `pikman upgrade`, and only continue to `flatpak update` if the first command succeeds. At the end, run `exec bash` so the terminal remains open with a normal interactive prompt. You can also use a final `read` prompt instead if you want to close the window manually.

MellowPine42 -

Thanks! I tested this approach and it works. I’ll go through the script carefully so I understand what each part does.

Answered By BrightOtter19 On

A backup before every update isn’t mandatory for everyone, especially if updates are frequent and you already have a reasonable backup routine. However, taking a Timeshift snapshot before less frequent or major system updates is a sensible precaution. The important thing is that the backup is actually usable and stored somewhere separate from the system if possible.

MellowPine42 -

I don’t update very often, so I prefer making a snapshot beforehand. I’ll keep doing that while I’m getting comfortable with the process.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.