add pre_deploy.sh script for dotter
This commit is contained in:
parent
808cdb3201
commit
d93bf44ae0
7 changed files with 192 additions and 16 deletions
|
|
@ -1,14 +1,9 @@
|
|||
[default]
|
||||
depends = ["nvim"]
|
||||
[settings]
|
||||
default_target_type = "automatic"
|
||||
|
||||
[default.files]
|
||||
"README.md" = ""
|
||||
chezmoi = ""
|
||||
config = ""
|
||||
exports = ""
|
||||
scripts = ""
|
||||
|
||||
[default.variables]
|
||||
[helpers]
|
||||
flatten_table = ".dotter/handlebars_helpers/flatten_table.rhai"
|
||||
header = ".dotter/handlebars_helpers/header.rhai"
|
||||
|
||||
# CLI package
|
||||
[cli]
|
||||
|
|
@ -22,6 +17,9 @@ depends = ["nvim", "zsh"]
|
|||
"config/yazi" = "~/.config/yazi"
|
||||
"config/zellij" = "~/.config/zellij"
|
||||
|
||||
[dev]
|
||||
depends = ["rust"]
|
||||
|
||||
[dev.files]
|
||||
"config/git" = "~/.config/git"
|
||||
"config/lazygit" = { target = "~/.config/lazygit", type = "symbolic"}
|
||||
|
|
@ -38,8 +36,8 @@ depends = ["nvim", "zsh"]
|
|||
[nushell.files]
|
||||
"config/nushell" = "~/.config/nushell"
|
||||
|
||||
[settings]
|
||||
default_target_type = "automatic"
|
||||
|
||||
[nvim.files]
|
||||
"config/nvim" = "~/.config/nvim"
|
||||
|
||||
[rust.variables]
|
||||
cargo.packages = []
|
||||
|
|
|
|||
30
.dotter/handlebars_helpers/flatten_table.rhai
Normal file
30
.dotter/handlebars_helpers/flatten_table.rhai
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Flatten a table into a list of values.
|
||||
* The table has to be in the form of
|
||||
* ```toml
|
||||
* [table.subtable]
|
||||
* variable1 = ["value1", "value2"]
|
||||
*
|
||||
* [table.subtable]
|
||||
* variable2 = ["value3", "value4"]
|
||||
*
|
||||
* then we use it in handlerbars like this:
|
||||
*
|
||||
* {{ flatten_table table.subtable }}
|
||||
*
|
||||
* and it will return an array with all the arrays of subtable
|
||||
*/
|
||||
|
||||
if type_of(params[0]) != "map" {
|
||||
return;
|
||||
}
|
||||
|
||||
let table = params[0];
|
||||
|
||||
let result = [];
|
||||
|
||||
for value in table.values() {
|
||||
result.append(value);
|
||||
}
|
||||
|
||||
result
|
||||
48
.dotter/handlebars_helpers/header.rhai
Normal file
48
.dotter/handlebars_helpers/header.rhai
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
let x_padding = hash["padding"] ?? 50;
|
||||
|
||||
let header = #{
|
||||
x_padding: x_padding,
|
||||
out: "",
|
||||
append: |suffix| {
|
||||
this.out += suffix + "\n";
|
||||
},
|
||||
append_center: |suffix| {
|
||||
|
||||
let suffix_len = suffix.len();
|
||||
let padding = this.x_padding - suffix_len / 2;
|
||||
let fill = "";
|
||||
fill.pad(padding, " ");
|
||||
|
||||
this.out += fill + suffix.to_upper() + fill + "\n";
|
||||
},
|
||||
append_divider: || {
|
||||
let divider = "";
|
||||
divider.pad(this.x_padding * 2, "─");
|
||||
|
||||
this.append(divider);
|
||||
},
|
||||
open_echo: || {
|
||||
this.out += "echo -e '\n";
|
||||
},
|
||||
close_echo: || {
|
||||
this.out += "'";
|
||||
},
|
||||
to_string: || {
|
||||
return this.out;
|
||||
}
|
||||
};
|
||||
|
||||
header.open_echo();
|
||||
|
||||
header.append_divider();
|
||||
|
||||
|
||||
params.for_each(|idx| {
|
||||
header.append_center(this);
|
||||
});
|
||||
|
||||
header.append_divider();
|
||||
header.close_echo();
|
||||
|
||||
return header.to_string();
|
||||
|
||||
54
.dotter/machines/fedora.toml
Normal file
54
.dotter/machines/fedora.toml
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# Dotter only support merging tables, and put the key-values into the global scope of the tables
|
||||
# If we try to use the same variable name in a package, it will throw an error
|
||||
# if we try to use the same key in a nested table, it will be overriden with the last value
|
||||
#
|
||||
# the fix to this is to have a table with unique keys, this is supported by handlerbars {{#each}} directive
|
||||
# but will give us an array as value, so we need to flatten it
|
||||
|
||||
[utils.variables]
|
||||
pkg-install = "sudo dnf install -y"
|
||||
|
||||
[cli.variables.copr]
|
||||
cli = [
|
||||
"atim/lazygit",
|
||||
"atim/starship"
|
||||
]
|
||||
|
||||
[cli.variables.packages]
|
||||
cli = [
|
||||
"bat",
|
||||
"dnf-plugin-system-upgrade",
|
||||
"duf",
|
||||
"eza",
|
||||
"fd-find",
|
||||
"firefox-dev",
|
||||
"flatpak",
|
||||
"fzf",
|
||||
"git",
|
||||
"lazygit",
|
||||
"neovim",
|
||||
"remove-retired-packages",
|
||||
"ripgrep",
|
||||
"sd",
|
||||
"starship",
|
||||
"tealdeer",
|
||||
"zoxide",
|
||||
"zsh",
|
||||
]
|
||||
|
||||
[dev.variables.packages]
|
||||
dev = [
|
||||
"gcc",
|
||||
"gcc-c++",
|
||||
"nodejs",
|
||||
"openssl",
|
||||
"openssl-devel",
|
||||
"tmux",
|
||||
"tree-sitter-cli",
|
||||
]
|
||||
|
||||
[rust.variables]
|
||||
cargo.packages = [
|
||||
"yazi-fm",
|
||||
"yazi-cli",
|
||||
]
|
||||
|
|
@ -1 +1,43 @@
|
|||
sudo dnf install -y {{# each packages }} {{ this }} {{/each}}
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=all
|
||||
# This is a handlerbars template, so ignore issues
|
||||
|
||||
{{!~ Detect the distribution ~}}
|
||||
{{~ assign "distro" (trim (command_output "awk -F= '/^ID=/ {print $2}' /etc/os-release | tr -d '\"'")) ~}}
|
||||
|
||||
{{ header "Running pre deploy script for distro" (to_title_case distro) }}
|
||||
|
||||
{{#if (eq distro "fedora") ~}}
|
||||
|
||||
{{! extract the copr repositories variable }}
|
||||
{{~ assign "copr" (flatten_table copr) ~}}
|
||||
|
||||
{{#if (ne (len copr) 0) ~}}
|
||||
{{ header "Enabling copr repositories" }}
|
||||
|
||||
{{# each copr }}
|
||||
sudo -B dnf copr enable -y '{{ this }}'
|
||||
{{ /each }}
|
||||
|
||||
{{~ /if }}
|
||||
|
||||
{{ header "Installing dnf packages" }}
|
||||
sudo -B dnf install -y {{~# each (flatten_table packages) }} '{{ this }}' {{~ /each }}
|
||||
|
||||
{{~ /if }}
|
||||
|
||||
{{#if (and dotter.packages.rust (not (is_executable "cargo"))) }}
|
||||
|
||||
{{ header "Installing rust" }}
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain stable
|
||||
|
||||
{{ /if }}
|
||||
|
||||
{{#if (and dotter.packages.rust (ne (len cargo.packages) 0)) }}
|
||||
|
||||
{{ header "Installing crates" }}
|
||||
cargo install --locked {{# each cargo.packages }} "{{ this }}" {{ /each }}
|
||||
|
||||
{{ /if }}
|
||||
|
||||
{{ header "Done :3" }}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
includes = []
|
||||
packages = ["default", "cli", "dev"]
|
||||
includes = [".dotter/machines/fedora.toml"]
|
||||
packages = ["cli", "dev"]
|
||||
|
||||
[files]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue