Skip to content
This repository has been archived by the owner on Dec 25, 2024. It is now read-only.

Commit

Permalink
feat: AMD Lact + SuperGFXCTL + GreenWithEnvy and modular DRY scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
tulilirockz committed Mar 10, 2024
1 parent 613d308 commit ff35aa9
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 175 deletions.
101 changes: 43 additions & 58 deletions config/files/shared/libexec/atomic-studio-cli/add.nu
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env -S nu

use lib/distrobox.nu [gen_export_string, DISTROBOX_DOWNLOAD_URL, distroboxes]
use lib/std.nu [fancy_prompt_message, user_prompt]
use lib/distrobox.nu [gen_export_string, create_container_optional, DISTROBOXES_META]
use lib/user_interaction.nu [fancy_prompt_message, user_prompt]
use lib/generic_install.nu [generic_script_installation, nix_installer, brew_installer, distrobox_installer]

const valid_package_managers = ["apt", "brew", "nix", "dnf", "yum", "paru", "pacman", "pipx"]

Expand All @@ -11,30 +12,27 @@ export def "main add export" [
box_or_subsystem: string,
...packages: string
] {
mut exportPath = ""
if ($export == null) or ($export == "") {
mut exportPath = $export
if $export == null {
$exportPath = $"($env.HOME)/.local/bin"
} else {
$exportPath = $export
}
let export_Path = $exportPath
mkdir $export_Path

let selected_box = ($distroboxes | select aliases name | where { |e| ($e.name == $box_or_subsystem) or ($e.aliases == $box_or_subsystem) } | get name | str join)

let packages_export = ($packages | each {|package| gen_export_string $package $export_Path } | str join " ; ")
distrobox-enter $selected_box -- sh -c $"($packages_export) 2> /dev/null" err> /dev/null
let selected_box = ($DISTROBOXES_META | select aliases name | where { |e| ($e.name == $box_or_subsystem) or ($e.aliases == $box_or_subsystem) } | get name | str join)
let packages_export_cmd: string = (gen_export_string $packages $export_Path)
distrobox-enter $selected_box -- sh -c $"($packages_export_cmd) 2> /dev/null" err> /dev/null
}

# List all available commands and subsystems
export def "main add list" [
--as-record (-r)
] {
if $as_record != null {
return {pkg_managers: $valid_package_managers, distroboxes: $distroboxes}
return {pkg_managers: $valid_package_managers, distroboxes: $DISTROBOXES_META}
}

echo $"Valid package managers:\n($valid_package_managers | table)\nSubsystems \(Distroboxes\):\n($distroboxes| table)"
echo $"Valid package managers:\n($valid_package_managers | table)\nSubsystems \(Distroboxes\):\n($DISTROBOXES_META| table)"
}

# Add a package to your Atomic Studio system by using package subsystems or host-based package managers.
Expand All @@ -61,47 +59,37 @@ export def "main add" [
}

match $package_manager {
nix => { nix_install $yes $packages },
brew => { brew_install $yes $packages },
pipx => { pipx_install $yes $packages }
apt | paru | pacman | dnf | yum => {
distrobox_installer_wrapper $package_data (match $package_manager {
apt => { box_distro: "ubuntu", installer_command: "sudo apt install -y" },
paru => { box_distro: "arch", installer_command: "paru -Syu --noconfirm" } ,
pacman => { box_distro:"arch", installer_command: "sudo pacman -Syu --noconfirm" },
dnf | yum => { box_distro: "fedora", installer_command: "sudo dnf install -y" },
})
},
_ => { echo $"Invalid package manager ($manager).\nValid package managers are ($valid_package_managers)" }
nix => { nix_install $yes $packages ; exit 0 },
brew => { brew_install $yes $packages ; exit 0},
pipx => { pipx_install $yes $packages ; exit 0 },
}

distrobox_installer_wrapper $package_data (match $package_manager {
apt => { box_distro: "ubuntu", installer_command: "sudo apt install -y" },
paru => { box_distro: "arch", installer_command: "paru -Syu --noconfirm" } ,
pacman => { box_distro: "arch", installer_command: "sudo pacman -Syu --noconfirm" },
dnf | yum => { box_distro: "fedora", installer_command: "sudo dnf install -y" },
_ => { echo $"Invalid package manager ($manager).\nValid package managers are ($valid_package_managers)" }
})
}

def distrobox_installer_wrapper [
package_data: record<packages: list<string>, export_path: string, no_confirm: bool>
manager: record<box_distro: string, installer_command: string>
] {
if (which distrobox | length) == 0 {
fancy_prompt_message "Distrobox"
if not (user_prompt $package_data.no_confirm) {
exit 0
}
echo "Installing, please wait."
curl -s $DISTROBOX_DOWNLOAD_URL | pkexec sh
generic_script_installation $package_data.no_confirm "distrobox" (distrobox_installer)
}

let box_name = ($distroboxes | where aliases == $manager.box_distro | get name).0

try { distrobox ls | grep $box_name out> /dev/null } catch {
fancy_prompt_message $"The ($distroboxes | where aliases == $manager.box_distro | get aliases | str join | str capitalize) subsystem"
if not (user_prompt $package_data.no_confirm) {
exit 0
}
distrobox create -i ($distroboxes | where aliases == $manager.box_distro | get image | str join) --name $manager.box_name -Y --pull
}
let box_name: string = ($DISTROBOXES_META | where aliases == $manager.box_distro | get name).0
let box_alias: string = ($DISTROBOXES_META | where aliases == $manager.box_distro | get aliases | str join | str capitalize)
let box_image: string = ($DISTROBOXES_META | where aliases == $manager.box_distro | get image | str join)

create_container_optional $package_data.no_confirm {name: $box_name, description: $box_alias, image: $box_image }

mkdir $package_data.export_path

let packages_export = ($package_data.packages | each {|package| gen_export_string $package $package_data.export_path } | str join " ; ")
let packages_export = gen_export_string $package_data.packages $package_data.export_path
distrobox enter $box_name -- sh -c $"($manager.installer_command) ($package_data.packages | str join ' ') && ($packages_export) 2> /dev/null" err> /dev/null
}

Expand All @@ -113,30 +101,27 @@ def pipx_install [yes: bool, packages: list<string>] {

def brew_install [yes: bool, packages: list<string>] {
let brew_path = "/home/linuxbrew/.linuxbrew/bin/brew"
if (which brew | length) == 0) or (not ($brew_path | path exists)) {
fancy_prompt_message Brew
if not (user_prompt $yes) {
exit 0
}
echo "Installing, please wait. You can check logs in /tmp/brew_install.log"
do { yes | /usr/libexec/brew-install ; echo "PLEASE IGNORE THE INSTRUCTIONS ABOVE. THEY WILL NOT HELP YOU! THE SYSTEM IS ALREADY CONFIGURED TO USE BREW PROPERLY BY DEFAULT :>"} out> /tmp/brew_install.log
echo "Brew installed successfully! Please reload your shell and run this program again."
if ((which brew | length) != 0) or ($brew_path | path exists) {
run-external $brew_path install ($packages | str join)
exit 0
}

fancy_prompt_message Brew
if not (user_prompt $yes) {
exit 0
}
run-external $brew_path install ($packages | str join)
generic_script_installation $yes "brew" (brew_installer)
}

def nix_install [yes: bool, packages: list<string>] {
if (which nix | length) == 0 {
fancy_prompt_message Nix
if not (user_prompt $yes) {
exit 0
}
echo "Installing, please wait. You can check logs in /tmp/nix_install.log"
do { yes | curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install } out> /tmp/nix_install.log
echo "Nix installed successfully! Please reload your shell and run this program again."
if (which nix | length) != 0 {
run-external nix profile install ($packages | each {|value| $"nixpkgs#($value) "} | str join)
exit 0
}

run-external nix profile install ($packages | each {|value| $"nixpkgs#($value) "} | str join)
fancy_prompt_message Nix
if not (user_prompt $yes) {
exit 0
}
generic_script_installation $yes "nix" (nix_installer)
}
33 changes: 16 additions & 17 deletions config/files/shared/libexec/atomic-studio-cli/davinci.nu
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env -S nu

use lib/distrobox.nu [DISTROBOX_DOWNLOAD_URL]
use lib/std.nu [fancy_prompt_message, user_prompt]
use lib/user_interaction.nu [fancy_prompt_message, user_prompt]
use lib/generic_install.nu [generic_script_installation]
use lib/distrobox.nu [create_container_optional]

const INSTALLATION_BOX = "davincibox"
const DAVINCI_IMAGE = "ghcr.io/zelikos/davincibox:latest"
Expand All @@ -10,15 +11,16 @@ const DAVINCI_IMAGE = "ghcr.io/zelikos/davincibox:latest"
export def "main davinci remove" [
--yes (-y) # Skip all confirmation prompts,
--box_name: string # Name of the distrobox where davinci-installer will be run from
--delete-box # Also delete container
] {
if (which distrobox | length) == 0 {
fancy_prompt_message "Distrobox"
if (not (user_prompt $yes)) {
fancy_prompt_message "Distrobox"
if not (user_prompt $yes) {
exit 0
}
curl -s $DISTROBOX_DOWNLOAD_URL | pkexec sh
generic_script_installation $yes "Distrobox" (distrobox_installer)
}

mut install_box = ""
if $box_name == null {
$install_box = $INSTALLATION_BOX
Expand All @@ -30,6 +32,9 @@ export def "main davinci remove" [
}

distrobox enter $install_box '--' sh -c "add-davinci-launcher remove"
if $delete_box != null {
distrobox rm $install_box
}
}

# Install Davinci Resolve in a compatible distrobox
Expand All @@ -39,11 +44,11 @@ export def "main davinci" [
script_path: string # The script that will be run to install Davinci Resolve
] {
if (which distrobox | length) == 0 {
fancy_prompt_message "Distrobox"
if (not (user_prompt $yes)) {
return
fancy_prompt_message "Distrobox"
if not (user_prompt $yes) {
exit 0
}
curl -s $DISTROBOX_DOWNLOAD_URL | pkexec sh
generic_script_installation $yes "Distrobox" (distrobox_installer)
}

mut install_box = ""
Expand All @@ -52,13 +57,7 @@ export def "main davinci" [
}
let box_name = $install_box

try { distrobox ls | grep $box_name } catch {
fancy_prompt_message "The Davinci container"
if not (user_prompt $yes) {
return
}
distrobox create -i $DAVINCI_IMAGE --name $box_name -Y --pull
}
create_container_optional $yes {name: $box_name, description: "Davinci container", image: $DAVINCI_IMAGE}

distrobox enter $box_name -- sh -c $"setup-davinci ($script_path) distrobox && add-davinci-launcher"
}
19 changes: 15 additions & 4 deletions config/files/shared/libexec/atomic-studio-cli/lib/distrobox.nu
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
export const DISTROBOX_DOWNLOAD_URL = "https://raw.githubusercontent.com/89luca89/distrobox/main/install"
use user_interaction.nu [fancy_prompt_message]

export def gen_export_string [package: string, export_Path: string] {
return $"distrobox-export --app ($package) ; distrobox-export --export-path ($export_Path) --bin /usr/bin/($package)"
export def gen_export_string [packages: list<string>, export_Path: string] {
return ($packages | each {|package| $"distrobox-export --app ($package) ; distrobox-export --export-path ($export_Path) --bin /usr/bin/($package)" } | str join " ; ")
}

export const distroboxes = [
export const DISTROBOXES_META = [
["aliases","name", "image", "description"];
["ubuntu", "ubuntubox", "ghcr.io/ublue-os/ubuntu-toolbox:latest", "Ubuntu based distrobox"]
["arch", "archbox", "ghcr.io/ublue-os/arch-distrobox:latest", "Arch Linux based distrobox with paru pre-installed"]
["fedora", "fedorabox", "ghcr.io/ublue-os/fedora-toolbox", "Fedora based distrobox"]
]

export def create_container_optional [yes: bool, container: record<name: string, description: string, image: string>] {
try { distrobox ls | grep $container.name } catch {
fancy_prompt_message $container.description
if not (user_prompt $yes) {
return 0
}
distrobox create -Y --pull -i $container.image --name $container.name
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export extern "distrobox" [
create? # Creates distroboxes

]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const DISTROBOX_DOWNLOAD_URL = "https://raw.githubusercontent.com/89luca89/distrobox/main/install"

export def generic_script_installation [yes: bool, program_name: string, installation_script: closure] {
let log_file = $"/tmp/($program_name | str trim | str downcase)_install.log"
touch $log_file
echo $"Installing, please wait. You can check logs in ($log_file)"
do $installation_script out> $log_file
echo $"($program_name | str capitalize) installed successfuly! Please reload your shell and run this script again."
}

export def nix_installer [] {
return { yes | curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install }
}

export def brew_installer [] {
return { yes | /usr/libexec/brew-install ; echo "PLEASE IGNORE THE INSTRUCTIONS ABOVE. THEY WILL NOT HELP YOU! THE SYSTEM IS ALREADY CONFIGURED TO USE BREW PROPERLY BY DEFAULT :>"}
}

export def distrobox_installer [] {
return { http get $DISTROBOX_DOWNLOAD_URL | pkexec sh }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export def fancy_prompt_message [package_manager: string] {
echo $"($package_manager) is not installed. Do you wish to install it?"
}

export const GENERIC_RESET_SESSION_MESSAGE = "Log out and in for changes to take effect."

32 changes: 19 additions & 13 deletions config/files/shared/libexec/atomic-studio-cli/motd.nu
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ def replace_format [
return final_value
}

# Toggle MOTD on and off
export def "main motd toggle" [] {
let MOTD_ENABLED_FILE = $"($env.HOME)/.config/atomic-studio/motd_enabled"
if ($MOTD_ENABLED_FILE | path exists) {
rm $MOTD_ENABLED_FILE
echo "Disabled MOTD for the current user"
} else {
touch $MOTD_ENABLED_FILE
echo "Enabled MOTD for the current user"
}
# Turn MOTD off
export def "main motd off" [] {
let MOTD_DISABLED_FILE = $"($env.HOME)/.config/atomic-studio/motd_enabled"
rm $MOTD_DISABLED_FILE
echo "Disabled MOTD for the current user"
}

# Turn MOTD on
export def "main motd on" [] {
let MOTD_DISABLED_FILE = $"($env.HOME)/.config/atomic-studio/motd_enabled"
touch $MOTD_DISABLED_FILE
echo "Enabled MOTD for the current user"
}

# Display current MOTD text
Expand All @@ -47,6 +49,11 @@ export def "main motd" [
--template_path (-t): string # Which template will be used for displaying the MOTD
--no-tip (-n) # Do not display tip
] {
let MOTD_DISABLED_FILE = $"($env.HOME)/.config/atomic-studio/motd_disabled"
if ($MOTD_DISABLED_FILE | path exists) {
exit 0
}

mut TEMPLATE_PATH = $template_path
if $template_path == null {
$TEMPLATE_PATH = $STUDIO_TEMPLATE_PATH
Expand All @@ -63,7 +70,6 @@ export def "main motd" [
let CURRENT_TIP_FILE = (ls $MOTD_PATH | where { |e| ($e.type == "file") and ($e.name | str ends-with md) } | shuffle | get 0.name)
let IMAGE_INFO = (open $IMAGE_INFO_PATH | from json)
let IMAGE_NAME = ($IMAGE_INFO).image-ref | sed -e 's|ostree-image-signed:docker://ghcr.io/.*/||' -e 's|ostree-unverified-registry:ghcr.io/.*/||' )
let IMAGE_TAG = ($IMAGE_INFO).image-tag
mut TIP = "󰋼 (open ($CURRENT_TIP_FILE) | lines | shuffle | get 0)"

let IMAGE_DATE = (rpm-ostree status --booted | sed -n 's/.*Timestamp: \(.*\)/\1/p')
Expand All @@ -83,8 +89,8 @@ export def "main motd" [
(replace_format [
["source", "output"];
["%IMAGE_NAME%" (replace_format $escape_patterns $IMAGE_NAME)]
["%IMAGE_TAG%" (replace_format $escape_patterns $IMAGE_TAG)]
["%IMAGE_TAG%" (replace_format $escape_patterns ($IMAGE_INFO).image-tag)]
["%TIP%" (replace_format $escape_patterns ($TIP | lines))]
] (open $TEMPLATE_PATH | lines -s)) | str join "\n" | glow -s auto -
] (open $TEMPLATE_PATH | lines -s)) | str join "\n" | run-external glow '-s' auto '-'
}

Loading

0 comments on commit ff35aa9

Please sign in to comment.