refactor(default-flatpaks): version 2 (nushell) (#336)
* feat: initial draft of default-flatpaks v2 this version just sets up the config file but nothing to read it and install the flatpaks after boot * chore: streamline logging * chore: replace json with yaml as generated config format * feat: set up groundwork for post boot scripts * feat: rename installations -> configurations, initial implementation of post-boot part * fix: put executable files into /usr/libexec/ * fix: improve fedora remote detection and removal * feat: implement notifications for system flatpak setup * chore(default-flatpaks): No need to expose `DISPLAY` for notify-send * chore(default-flatpaks): Update service & add timers to match v1 * chore(default-flatpaks): Copy & enable timers instead of services * chore(default-flatpaks): Fix typo for copying `user-flatpak-setup` timer * chore(default-flatpaks): Copy post-boot files directly instead of placing them in `/usr/share/...` * chore(default-flatpaks): Forgot to remove copying step of post-boot files to `/usr/share/...` * chore: update to be in accordance with cli support for nushell * feat: allow usage of fedora flatpak remote, remove fedora flatpaks and runtimes * feat: refactor schema to support multiple versions of the module * docs: separate docs for separate module versions * fix: copy user-flatpak-setup.timer to correct directory * chore: correctly document default values in schema * fix: better flathub package checking - use API url - check everything before erroring out * feat: warn users when giving this module v1 configuration * fix: prevent addition of http get result into unavailablePackages list * fix: mkdir before cp * chore: fix () semantics problems highlighted by debugger * feat: bluebuild-flatpak-manager CLI * feat: alert user when trying to use module with old configuration * docs: write basic documentation page and rewrite example * fix: attempt to use configFile variable without dollar sign * fix: no such things as .configurations (the file is the array) * fix: ensure no empty list is printed * docs: add a quick note about learning to use the flatpak manager tool * fix(schema): distinquish between versions Co-authored-by: Gerald Pinder <gmpinder@gmail.com> * fix: add noninteractive flag to flatpak install commands * fix: ensure repo to be used is enabled * chore: ignore errors in notify wrapper just in case * chore: add link to announcement * docs: run through languagetool --------- Co-authored-by: fiftydinar <65243233+fiftydinar@users.noreply.github.com> Co-authored-by: Gerald Pinder <gmpinder@gmail.com>
This commit is contained in:
parent
c530c6e736
commit
a639f1f64f
12 changed files with 499 additions and 37 deletions
|
|
@ -1,17 +1,25 @@
|
|||
import "@typespec/json-schema";
|
||||
using TypeSpec.JsonSchema;
|
||||
|
||||
@jsonSchema("/modules/default-flatpaks.json")
|
||||
@oneOf
|
||||
union DefaultFlatpaksModule {
|
||||
DefaultFlatpaksV1;
|
||||
DefaultFlatpaksV2;
|
||||
}
|
||||
|
||||
@jsonSchema("/modules/default-flatpaks-latest.json")
|
||||
model DefaultFlatpaksModuleLatest {
|
||||
...DefaultFlatpaksModuleV1;
|
||||
...DefaultFlatpaksModuleV2;
|
||||
}
|
||||
|
||||
@jsonSchema("/modules/default-flatpaks-v1.json")
|
||||
model DefaultFlatpaksModuleV1 {
|
||||
model DefaultFlatpaksV1 {
|
||||
/** The default-flatpaks module can be used to install or uninstall flatpaks from a configurable remote on every boot.
|
||||
* using version: v1
|
||||
* https://blue-build.org/reference/modules/default-flatpaks/
|
||||
*/
|
||||
type: "default-flatpaks" | "default-flatpaks@v1" | "default-flatpaks@latest";
|
||||
type: "default-flatpaks@v1" | "default-flatpaks";
|
||||
|
||||
/** Whether to send a notification after the install/uninstall is finished. */
|
||||
notify?: boolean = false;
|
||||
|
|
@ -52,3 +60,35 @@ model DefaultFlatpaksModuleV1 {
|
|||
remove?: Array<string>;
|
||||
};
|
||||
}
|
||||
|
||||
@jsonSchema("/modules/default-flatpaks-v2.json")
|
||||
model DefaultFlatpaksV2 {
|
||||
/** The default-flatpaks module can be used to install Flatpaks from a configurable remote on every boot.
|
||||
* using version: v2
|
||||
* https://blue-build.org/reference/modules/default-flatpaks/
|
||||
*/
|
||||
type: "default-flatpaks@v2" | "default-flatpaks@latest" | "default-flatpaks";
|
||||
|
||||
configurations: Array<{
|
||||
/** Whether to notify users about Flatpak installation. */
|
||||
notify?: boolean = true;
|
||||
|
||||
/** Whether to perform this configuration for system-wide or separately for each user. */
|
||||
scope?: "system" | "user" = "user";
|
||||
|
||||
/** Details of the Flatpak repository to set up. If omitted, Flathub will be used by default. */
|
||||
repo?: {
|
||||
/** Flatpak repository URL. */
|
||||
url?: string = "https://dl.flathub.org/repo/flathub.flatpakrepo";
|
||||
|
||||
/** Flatpak repository name. */
|
||||
name?: string = "flathub";
|
||||
|
||||
/** Flatpak repository formatted title. */
|
||||
title?: string = "Flathub";
|
||||
};
|
||||
|
||||
/** List of Flatpak IDs to install from the repo. */
|
||||
install?: Array<string>;
|
||||
}>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,37 +1,58 @@
|
|||
name: default-flatpaks
|
||||
shortdesc: The default-flatpaks module can be used to install or uninstall flatpaks from a configurable remote on every boot.
|
||||
example: |
|
||||
modules: # configured multiple times to highlight how options are overridden
|
||||
- type: default-flatpaks
|
||||
notify: true # Send notification after install/uninstall is finished (true/false)
|
||||
system:
|
||||
# If no repo information is specified, Flathub will be used by default
|
||||
repo-url: https://dl.flathub.org/repo/flathub.flatpakrepo
|
||||
repo-name: flathub
|
||||
repo-title: "Flathub (system-wide)" # Optional; this sets the remote's user-facing name in graphical frontends like GNOME Software
|
||||
install:
|
||||
- org.gnome.Loupe
|
||||
- one.ablaze.floorp//lightning # This is an example of flatpak which has multiple branches in selection (flatpak//branch).
|
||||
# Flatpak runtimes are not supported (like org.winehq.Wine//stable-23.08).
|
||||
# Only normal flatpak applications are (like Floorp Lightning web browser in this example).
|
||||
# Multiple install of same flatpaks with different branches is not supported.
|
||||
remove:
|
||||
- org.gnome.eog
|
||||
# A flatpak repo can also be added without having to install flatpaks,
|
||||
# as long as one of the repo- fields is present
|
||||
user:
|
||||
repo-name: flathub
|
||||
versions:
|
||||
- version: v1
|
||||
example: |
|
||||
modules: # configured multiple times to highlight how options are overridden
|
||||
- type: default-flatpaks@v1
|
||||
notify: true # Send notification after install/uninstall is finished (true/false)
|
||||
system:
|
||||
# If no repo information is specified, Flathub will be used by default
|
||||
repo-url: https://dl.flathub.org/repo/flathub.flatpakrepo
|
||||
repo-name: flathub
|
||||
repo-title: "Flathub (system-wide)" # Optional; this sets the remote's user-facing name in graphical frontends like GNOME Software
|
||||
install:
|
||||
- org.gnome.Loupe
|
||||
- one.ablaze.floorp//lightning # This is an example of flatpak which has multiple branches in selection (flatpak//branch).
|
||||
# Flatpak runtimes are not supported (like org.winehq.Wine//stable-23.08).
|
||||
# Only normal flatpak applications are (like Floorp Lightning web browser in this example).
|
||||
# Multiple install of same flatpaks with different branches is not supported.
|
||||
remove:
|
||||
- org.gnome.eog
|
||||
# A flatpak repo can also be added without having to install flatpaks,
|
||||
# as long as one of the repo- fields is present
|
||||
user:
|
||||
repo-name: flathub
|
||||
|
||||
# Assuming that the above example is configured first in a recipe,
|
||||
# a subsequent usage might look like this:
|
||||
- type: default-flatpaks
|
||||
system:
|
||||
# If the repo-* fields are omitted on the subsequent usage,
|
||||
# the module will use the previously configured repo.
|
||||
# Otherwise, it will overwrite the repo configuration.
|
||||
install:
|
||||
- org.kde.kdenlive # this Flatpak is appended to the install list
|
||||
user:
|
||||
# repo-name will overwrite the previously-configured repo-name for the user remote
|
||||
repo-name: flathub-user
|
||||
repo-title: "Flathub (User)
|
||||
# Assuming that the above example is configured first in a recipe,
|
||||
# a subsequent usage might look like this:
|
||||
- type: default-flatpaks
|
||||
system:
|
||||
# If the repo-* fields are omitted on the subsequent usage,
|
||||
# the module will use the previously configured repo.
|
||||
# Otherwise, it will overwrite the repo configuration.
|
||||
install:
|
||||
- org.kde.kdenlive # this Flatpak is appended to the install list
|
||||
user:
|
||||
# repo-name will overwrite the previously-configured repo-name for the user remote
|
||||
repo-name: flathub-user
|
||||
repo-title: "Flathub (User
|
||||
- version: v2
|
||||
example: |
|
||||
- type: default-flatpaks
|
||||
configurations:
|
||||
- scope: user
|
||||
repo:
|
||||
# you can override the title to make inclusion of both system and user repos clearer
|
||||
title: Flathub (user)
|
||||
- notify: true
|
||||
scope: system
|
||||
repo:
|
||||
title: Flathub (system)
|
||||
install: # system flatpaks we want all users to have and not remove
|
||||
- org.mozilla.firefox
|
||||
- com.github.tchx84.Flatseal
|
||||
- io.github.flattool.Warehouse
|
||||
- io.missioncenter.MissionCenter
|
||||
- com.github.rafostar.Clapper
|
||||
- org.gnome.Loupe
|
||||
|
|
|
|||
43
modules/default-flatpaks/v2/README.md
Normal file
43
modules/default-flatpaks/v2/README.md
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# `default-flatpaks`
|
||||
|
||||
:::note
|
||||
For instructions on migration from v1 to v2, see the [announcement blog post](/blog/default-flatpaks-v2).
|
||||
:::
|
||||
|
||||
The `default-flatpaks` module can be used to install Flatpaks from a configurable remote on every boot. By default the module will remove the Fedora Flatpak remote and install the Flathub remote, but you can also configure it to install other Flatpaks from other remotes.
|
||||
|
||||
## Features
|
||||
|
||||
- System and user systemd services that are based on your configuration
|
||||
- Set up a Flatpak remote
|
||||
- Install Flatpaks from the remote
|
||||
- CLI tool `bluebuild-flatpak-manager` to
|
||||
- Display the Flatpak configurations in the image
|
||||
- Manually initiate the setup of Flatpaks
|
||||
- Disable the automatic Flatpak setup
|
||||
- Re-enable the automatic Flatpak setup
|
||||
- _run the `bluebuild-flatpak-manager` command for help and documentation_
|
||||
|
||||
## Configuration
|
||||
|
||||
The `default-flatpaks` module configuration is based on a list of `configurations:` that each set a scope to install in (`system` or `user`), a Flatpak repository to set up, and a list of Flatpaks to install from the repository.
|
||||
|
||||
Multiple configurations are supported, and subsequent module calls will append new configurations to the list. Overriding previous configurations is currently not supported.
|
||||
|
||||
### Scope
|
||||
|
||||
The `scope:` property can be set to `system` or `user`. If omitted, the default is `user`. This property determines whether the Flatpak repository and packages are set up for the system or for each user separately.
|
||||
|
||||
For a single-user system, you can safely use the `user` scope, since that will allow installation of Flatpaks from the configured repo and management of the installed Flatpaks without authentication. If you have multiple users for whom you want to set up the same system Flatpaks, you should use the `system` scope. This ensures that the Flatpaks are not duplicated in each user's home directory, and that managing the Flatpaks requires admin permissions.
|
||||
|
||||
### Flatpak repository
|
||||
|
||||
The `repo:` property is used to configure the Flatpak repository to set up. If omitted, Flathub will be used by default. The URL should be a link to a `.flatpakrepo` file. The name and title are used to identify the repository in the Flatpak CLI; the name should be lowercase and not contain spaces, while the title can be any string.
|
||||
|
||||
### Notification
|
||||
|
||||
The `notify:` property can be set to `true` or `false`. If omitted, the default is `true`. This will send a notification on each boot to the user(s) when starting the Flatpak installation and when it is finished.
|
||||
|
||||
### Flatpak installation
|
||||
|
||||
The `install:` property is a list of the Flatpak IDs to install from the configured repository. If omitted, no Flatpaks will be installed, but the Flatpak repository will still be set up. If the repository to use is configured as Flathub, the list of Flatpaks will be validated at build time to ensure that the packages are available on Flathub.
|
||||
106
modules/default-flatpaks/v2/default-flatpaks.nu
Normal file
106
modules/default-flatpaks/v2/default-flatpaks.nu
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
#!/usr/libexec/bluebuild/nu/nu
|
||||
|
||||
const flathubURL = "https://dl.flathub.org/repo/flathub.flatpakrepo"
|
||||
|
||||
const defaultConfiguration = {
|
||||
notify: true
|
||||
scope: user
|
||||
repo: {
|
||||
url: $flathubURL
|
||||
name: "flathub"
|
||||
title: "Flathub"
|
||||
}
|
||||
install: []
|
||||
}
|
||||
|
||||
const usrSharePath = "/usr/share/bluebuild/default-flatpaks"
|
||||
const libExecPath = "/usr/libexec/bluebuild/default-flatpaks"
|
||||
const configPath = $"($usrSharePath)/configuration.yaml"
|
||||
|
||||
def main [configStr: string] {
|
||||
let config = $configStr | from yaml
|
||||
|
||||
if ('user' in $config or 'system' in $config) {
|
||||
print $"(ansi red_bold)CONFIGURATION ERROR(ansi reset)"
|
||||
print $"(ansi yellow_reverse)HINT(ansi reset): the default-flatpaks module has been updated with breaking changes!"
|
||||
print $"It seems like you are trying to run the new (ansi default_italic)default-flatpaks@v2(ansi reset) module with configuration made for the older version."
|
||||
print $"You can read the docs to migrate to the new and improved module, or just change switch back to the old module like this (ansi default_italic)type: default-flatpaks@v1(ansi reset)"
|
||||
exit 1
|
||||
}
|
||||
|
||||
let configurations = $config.configurations | each {|configuration|
|
||||
mut merged = $defaultConfiguration | merge $configuration
|
||||
$merged.repo = $defaultConfiguration.repo | merge $merged.repo # make sure all repo properties exist
|
||||
|
||||
print $"Validating configuration of (ansi default_italic)($merged.install | length)(ansi reset) Flatpaks from (ansi default_italic)($merged.repo.title)(ansi reset)"
|
||||
|
||||
if (not ($merged.scope == "system" or $merged.scope == "user")) {
|
||||
print $"(ansi red_bold)Scope must be either(ansi reset) (ansi blue_italic)system(ansi reset) (ansi red_bold)or(ansi reset) (ansi blue_italic)user(ansi reset)"
|
||||
print $"(ansi blue)Your input:(ansi reset) ($merged.scope)"
|
||||
exit 1
|
||||
}
|
||||
if (not ($merged.notify == true or $merged.notify == false)) {
|
||||
print $"(ansi red_bold)Notify must be either(ansi reset) (ansi blue_italic)true(ansi reset) (ansi red_bold)or(ansi reset) (ansi blue_italic)false(ansi reset)"
|
||||
print $"(ansi blue)Your input:(ansi reset) ($merged.notify)"
|
||||
exit 1
|
||||
}
|
||||
if ($merged.repo.url == $flathubURL) {
|
||||
checkFlathub $merged.install
|
||||
}
|
||||
|
||||
print $"Validation successful!"
|
||||
|
||||
$merged
|
||||
}
|
||||
|
||||
|
||||
if (not ($configPath | path exists)) {
|
||||
mkdir ($configPath | path dirname)
|
||||
'[]'| save $configPath
|
||||
}
|
||||
|
||||
open $configPath
|
||||
| append $configurations
|
||||
| to yaml | save -f $configPath
|
||||
|
||||
print $"(ansi green_bold)Successfully generated following configurations:(ansi reset)"
|
||||
print ($configurations | to yaml)
|
||||
|
||||
print "Setting up Flatpak setup services..."
|
||||
|
||||
mkdir /usr/lib/systemd/system/
|
||||
cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/system-flatpak-setup.service" /usr/lib/systemd/system/system-flatpak-setup.service
|
||||
cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/system-flatpak-setup.timer" /usr/lib/systemd/system/system-flatpak-setup.timer
|
||||
mkdir /usr/lib/systemd/user/
|
||||
cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/user-flatpak-setup.service" /usr/lib/systemd/user/user-flatpak-setup.service
|
||||
cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/user-flatpak-setup.timer" /usr/lib/systemd/user/user-flatpak-setup.timer
|
||||
systemctl enable --force system-flatpak-setup.timer
|
||||
systemctl enable --force --global user-flatpak-setup.timer
|
||||
|
||||
mkdir ($libExecPath)
|
||||
cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/system-flatpak-setup" $"($libExecPath)/system-flatpak-setup"
|
||||
cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/user-flatpak-setup" $"($libExecPath)/user-flatpak-setup"
|
||||
chmod +x $"($libExecPath)/system-flatpak-setup"
|
||||
chmod +x $"($libExecPath)/user-flatpak-setup"
|
||||
|
||||
cp $"($env.MODULE_DIRECTORY)/default-flatpaks/post-boot/bluebuild-flatpak-manager" "/usr/bin/bluebuild-flatpak-manager"
|
||||
chmod +x "/usr/bin/bluebuild-flatpak-manager"
|
||||
}
|
||||
|
||||
def checkFlathub [packages: list<string>] {
|
||||
print "Checking if configured packages exist on Flathub..."
|
||||
let unavailablePackages = $packages | each { |package|
|
||||
try {
|
||||
let _ = http get $"https://flathub.org/api/v2/stats/($package)"
|
||||
} catch {
|
||||
$package
|
||||
}
|
||||
}
|
||||
if ($unavailablePackages | length) > 0 {
|
||||
print $"(ansi red_bold)The following packages are not available on Flathub, which is the specified repository for them to be installed from:(ansi reset) "
|
||||
for package in $unavailablePackages {
|
||||
print $"(ansi default_italic)($package)(ansi reset)"
|
||||
}
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
#!/usr/libexec/bluebuild/nu/nu
|
||||
|
||||
def main [] {
|
||||
print "A CLI tool to manage the installation and setup of Flatpaks by the default-flatpaks BlueBuild module"
|
||||
print
|
||||
print $"(ansi default_underline)(ansi default_bold)Usage:(ansi reset) bluebuild-flatpak-manager [command] <args>"
|
||||
print
|
||||
print $"(ansi default_underline)(ansi default_bold)Commands:(ansi reset)"
|
||||
print $" (ansi default_bold)show:(ansi reset) Print out all changes configured to be done by the default-flatpaks module"
|
||||
print $" (ansi default_bold)apply <all|user|system>:(ansi reset) Manually initiate the setup of Flatpaks"
|
||||
print $" (ansi default_bold)disable <all|user|system>:(ansi reset) Disable the automatic setup of Flatpaks"
|
||||
print $" (ansi default_bold)enable <all|user|system>:(ansi reset) Enable the automatic setup of Flatpaks"
|
||||
}
|
||||
|
||||
def "main show" [] {
|
||||
let configurations = open "/usr/share/bluebuild/default-flatpaks/configuration.yaml"
|
||||
print $"Found (ansi default_italic)($configurations | length)(ansi reset) configuration\(s)"
|
||||
|
||||
for config in $configurations {
|
||||
print
|
||||
print $" ($config.install | length) (ansi default_italic)($config.scope)(ansi reset) Flatpak\(s\) from (ansi default_italic)($config.repo.title)(ansi reset) \((ansi default_italic)($config.repo.url)(ansi reset)\)"
|
||||
if ($config.notify) {
|
||||
print $" (ansi default_italic)Installer will notify user(ansi reset)"
|
||||
} else {
|
||||
print $" (ansi default_italic)Installer will not notify user(ansi reset)"
|
||||
}
|
||||
print $" Flatpak\(s) to be installed:"
|
||||
$config.install | each {|package|
|
||||
print $" ($package)"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
def "main apply" [] {
|
||||
print $"(ansi default_underline)(ansi default_bold)Usage:(ansi reset)"
|
||||
print $" (ansi default_italic)bluebuild-flatpak-manager apply all(ansi reset): install and setup both system and user Flatpaks"
|
||||
print $" (ansi default_italic)bluebuild-flatpak-manager apply user(ansi reset): install and setup user Flatpaks"
|
||||
print $" (ansi default_italic)bluebuild-flatpak-manager apply system(ansi reset): install and setup system Flatpaks"
|
||||
}
|
||||
|
||||
def "main apply user" [] {
|
||||
/usr/libexec/bluebuild/default-flatpaks/user-flatpak-setup
|
||||
}
|
||||
|
||||
def "main apply system" [] {
|
||||
/usr/libexec/bluebuild/default-flatpaks/system-flatpak-setup
|
||||
}
|
||||
|
||||
def "main apply all" [] {
|
||||
main apply user
|
||||
main apply system
|
||||
}
|
||||
|
||||
def "main disable" [] {
|
||||
print $"(ansi default_underline)(ansi default_bold)Usage:(ansi reset)"
|
||||
print $" (ansi default_italic)bluebuild-flatpak-manager disable all(ansi reset): disable automatic setup for both system Flatpaks and user Flatpaks"
|
||||
print $" (ansi default_italic)bluebuild-flatpak-manager disable user(ansi reset): disable automatic setup for user Flatpaks"
|
||||
print $" (ansi default_italic)bluebuild-flatpak-manager disable system(ansi reset): disable automatic setup for system Flatpaks"
|
||||
}
|
||||
|
||||
def "main disable user" [] {
|
||||
print $"Running: (ansi default_italic)run0 systemctl disable --global user-flatpak-setup.timer(ansi reset)"
|
||||
run0 systemctl disable --global user-flatpak-setup.timer
|
||||
}
|
||||
|
||||
def "main disable system" [] {
|
||||
print $"Running: (ansi default_italic)systemctl disable --now system-flatpak-setup.timer(ansi reset)"
|
||||
systemctl disable --now system-flatpak-setup.timer
|
||||
}
|
||||
|
||||
def "main disable all" [] {
|
||||
main disable system
|
||||
main disable user
|
||||
}
|
||||
|
||||
def "main enable" [] {
|
||||
print $"(ansi default_underline)(ansi default_bold)Usage:(ansi reset)"
|
||||
print $" (ansi default_italic)bluebuild-flatpak-manager enable all(ansi reset): enable automatic setup for both system Flatpaks and user Flatpaks"
|
||||
print $" (ansi default_italic)bluebuild-flatpak-manager enable user(ansi reset): enable automatic setup for user Flatpaks"
|
||||
print $" (ansi default_italic)bluebuild-flatpak-manager enable system(ansi reset): enable automatic setup for system Flatpaks"
|
||||
}
|
||||
|
||||
def "main enable user" [] {
|
||||
print $"Running: (ansi default_italic)run0 systemctl enable --global user-flatpak-setup.timer(ansi reset)"
|
||||
run0 systemctl enable --global user-flatpak-setup.timer
|
||||
}
|
||||
|
||||
def "main enable system" [] {
|
||||
print $"Running: (ansi default_italic)systemctl enable --now system-flatpak-setup.timer(ansi reset)"
|
||||
systemctl enable --now system-flatpak-setup.timer
|
||||
}
|
||||
|
||||
def "main enable all" [] {
|
||||
main enable system
|
||||
main enable user
|
||||
}
|
||||
69
modules/default-flatpaks/v2/post-boot/system-flatpak-setup
Normal file
69
modules/default-flatpaks/v2/post-boot/system-flatpak-setup
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#!/usr/libexec/bluebuild/nu/nu
|
||||
|
||||
const usrSharePath = "/usr/share/bluebuild/default-flatpaks"
|
||||
const configPath = $"($usrSharePath)/configuration.yaml"
|
||||
|
||||
def main [] {
|
||||
let configFile = open $configPath
|
||||
|
||||
let keepFedora = $configFile | where scope == system | any {|config|
|
||||
$config.repo.url == "oci+https://registry.fedoraproject.org"
|
||||
}
|
||||
|
||||
let systemRemotes = (flatpak remotes --system --columns name | split row "\n")
|
||||
if (not $keepFedora and ($systemRemotes | any {|remote| $remote == "fedora" or $remote == "fedora-testing"})) {
|
||||
/usr/bin/gnome-software --quit
|
||||
/usr/lib/fedora-third-party/fedora-third-party-opt-out
|
||||
/usr/bin/fedora-third-party disable
|
||||
|
||||
if ($systemRemotes | any {|remote| $remote == "fedora"}) {
|
||||
flatpak remote-delete --system fedora --force
|
||||
}
|
||||
if ($systemRemotes | any {|remote| $remote == "fedora-testing"}) {
|
||||
flatpak remote-delete --system fedora-testing --force
|
||||
}
|
||||
|
||||
let fedoraApps = flatpak list --system --app --columns=origin,application | detect columns --no-headers | where column0 == fedora | get column1
|
||||
if (($fedoraApps | length) > 0) {
|
||||
flatpak remove --system --noninteractive ...$fedoraApps
|
||||
}
|
||||
|
||||
let fedoraRuntimes = flatpak list --system --runtime --columns=origin,application,arch,branch | detect columns --no-headers | where column0 == fedora | each {|i| $"($i.column1)/($i.column2)/($i.column3)" }
|
||||
if (($fedoraRuntimes | length) > 0) {
|
||||
flatpak remove --system --noninteractive ...$fedoraRuntimes
|
||||
}
|
||||
}
|
||||
|
||||
for config in ($configFile | where scope == system) {
|
||||
flatpak remote-add --system --if-not-exists $config.repo.name $config.repo.url --title $config.repo.title
|
||||
flatpak remote-modify --system --enable $config.repo.name
|
||||
|
||||
if ($config.notify) {
|
||||
(notify-send-as-user
|
||||
"--app-name" "Automatic Flatpak Installation Service"
|
||||
$"Starting automated installation of ($config.install | length) system Flatpak\(s) from ($config.repo.title)..."
|
||||
)
|
||||
}
|
||||
|
||||
flatpak install --system --noninteractive $config.repo.name ...$config.install
|
||||
|
||||
if ($config.notify) {
|
||||
(notify-send-as-user
|
||||
"--app-name" "Automatic Flatpak Installation Service"
|
||||
$"Finished automated installation of ($config.install | length) system Flatpak\(s) from ($config.repo.title)!"
|
||||
($config.install | str join ', ')
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def notify-send-as-user [...args] {
|
||||
# this works most of the time, sometimes not
|
||||
# let's not let notification errors interrupt the rest of the module's function
|
||||
do --ignore-errors {
|
||||
let user_name = (loginctl list-sessions --json=short | from json | get user | get 0)
|
||||
let uid = (loginctl list-sessions --json=short | from json | get uid | get 0)
|
||||
let xdg_runtime_path = $"/run/user/($uid)"
|
||||
sudo -u $user_name DBUS_SESSION_BUS_ADDRESS=unix:path=($xdg_runtime_path)/bus notify-send ...$args
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
[Unit]
|
||||
Description=Manage system flatpaks
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/libexec/bluebuild/default-flatpaks/system-flatpak-setup
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
[Unit]
|
||||
Description=Timer for system-flatpak-setup
|
||||
|
||||
[Timer]
|
||||
OnBootSec=30
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
54
modules/default-flatpaks/v2/post-boot/user-flatpak-setup
Normal file
54
modules/default-flatpaks/v2/post-boot/user-flatpak-setup
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/libexec/bluebuild/nu/nu
|
||||
|
||||
const usrSharePath = "/usr/share/bluebuild/default-flatpaks"
|
||||
const configPath = $"($usrSharePath)/configuration.yaml"
|
||||
|
||||
def main [] {
|
||||
let configFile = open $configPath
|
||||
|
||||
let keepFedora = $configFile | where scope == user | any {|config|
|
||||
$config.repo.url == "oci+https://registry.fedoraproject.org"
|
||||
}
|
||||
|
||||
let userRemotes = (flatpak remotes --user --columns name | split row "\n")
|
||||
if (not $keepFedora) {
|
||||
if ($userRemotes | any {|remote| $remote == "fedora"}) {
|
||||
flatpak remote-delete --user fedora --force
|
||||
}
|
||||
if ($userRemotes | any {|remote| $remote == "fedora-testing"}) {
|
||||
flatpak remote-delete --user fedora-testing --force
|
||||
}
|
||||
|
||||
let fedoraApps = flatpak list --user --app --columns=origin,application | detect columns --no-headers | where column0 == fedora | get column1
|
||||
if (($fedoraApps | length) > 0) {
|
||||
flatpak remove --user --noninteractive ...$fedoraApps
|
||||
}
|
||||
|
||||
let fedoraRuntimes = flatpak list --user --runtime --columns=origin,application,arch,branch | detect columns --no-headers | where column0 == fedora | each {|i| $"($i.column1)/($i.column2)/($i.column3)" }
|
||||
if (($fedoraRuntimes | length) > 0) {
|
||||
flatpak remove --user --noninteractive ...$fedoraRuntimes
|
||||
}
|
||||
}
|
||||
|
||||
for config in ($configFile | where scope == user) {
|
||||
flatpak remote-add --user --if-not-exists $config.repo.name $config.repo.url --title $config.repo.title
|
||||
flatpak remote-modify --user --enable $config.repo.name
|
||||
|
||||
if ($config.notify) {
|
||||
(notify-send
|
||||
--app-name "Automatic Flatpak Installation Service"
|
||||
$"Starting automated installation of ($config.install | length) user Flatpak\(s) from ($config.repo.title)..."
|
||||
)
|
||||
}
|
||||
|
||||
flatpak install --user --noninteractive $config.repo.name ...$config.install
|
||||
|
||||
if ($config.notify) {
|
||||
(notify-send
|
||||
--app-name "Automatic Flatpak Installation Service"
|
||||
$"Finished automated installation of ($config.install | length) user Flatpak\(s) from ($config.repo.title)!"
|
||||
($config.install | str join ', ')
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
[Unit]
|
||||
Description=Configure Flatpaks for current user
|
||||
Wants=network-online.target
|
||||
After=system-flatpak-setup.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/libexec/bluebuild/default-flatpaks/user-flatpak-setup
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
[Unit]
|
||||
Description=Timer for user-flatpak-setup
|
||||
|
||||
[Timer]
|
||||
OnBootSec=30
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
Loading…
Add table
Add a link
Reference in a new issue