Merge branch 'dev' into master
This commit is contained in:
0
src/steps/bun.rs
Normal file
0
src/steps/bun.rs
Normal file
@@ -67,25 +67,24 @@ impl Emacs {
|
||||
print_separator("Doom Emacs");
|
||||
|
||||
let mut command = ctx.run_type().execute(doom);
|
||||
command.args(&["-y", "upgrade"]);
|
||||
|
||||
if ctx.config().yes(Step::Emacs) {
|
||||
command.arg("--force");
|
||||
}
|
||||
|
||||
command.args(&["upgrade"]);
|
||||
|
||||
command.check_run()
|
||||
}
|
||||
|
||||
pub fn upgrade(&self, ctx: &ExecutionContext) -> Result<()> {
|
||||
let emacs = require("emacs")?;
|
||||
if let Some(doom) = &self.doom {
|
||||
Emacs::update_doom(doom, ctx)?;
|
||||
}
|
||||
let init_file = require_option(self.directory.as_ref(), String::from("Emacs directory does not exist"))?
|
||||
.join("init.el")
|
||||
.require()?;
|
||||
|
||||
if let Some(doom) = &self.doom {
|
||||
return Emacs::update_doom(doom, ctx);
|
||||
}
|
||||
|
||||
print_separator("Emacs");
|
||||
|
||||
let mut command = ctx.run_type().execute(&emacs);
|
||||
|
||||
@@ -220,13 +220,19 @@ pub fn run_rtcl(ctx: &ExecutionContext) -> Result<()> {
|
||||
ctx.run_type().execute(&rupdate).check_run()
|
||||
}
|
||||
|
||||
pub fn run_opam_update(run_type: RunType) -> Result<()> {
|
||||
pub fn run_opam_update(ctx: &ExecutionContext) -> Result<()> {
|
||||
let opam = utils::require("opam")?;
|
||||
|
||||
print_separator("OCaml Package Manager");
|
||||
|
||||
run_type.execute(&opam).arg("update").check_run()?;
|
||||
run_type.execute(&opam).arg("upgrade").check_run()
|
||||
ctx.run_type().execute(&opam).arg("update").check_run()?;
|
||||
ctx.run_type().execute(&opam).arg("upgrade").check_run()?;
|
||||
|
||||
if ctx.config().cleanup() {
|
||||
ctx.run_type().execute(&opam).arg("clean").check_run()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run_vcpkg_update(run_type: RunType) -> Result<()> {
|
||||
@@ -496,3 +502,14 @@ pub fn run_ghcli_extensions_upgrade(ctx: &ExecutionContext) -> Result<()> {
|
||||
.args(&["extension", "upgrade", "--all"])
|
||||
.check_run()
|
||||
}
|
||||
|
||||
pub fn update_julia_packages(ctx: &ExecutionContext) -> Result<()> {
|
||||
let julia = utils::require("julia")?;
|
||||
|
||||
print_separator("Julia Packages");
|
||||
|
||||
ctx.run_type()
|
||||
.execute(&julia)
|
||||
.args(&["-e", "using Pkg; Pkg.update()"])
|
||||
.check_run()
|
||||
}
|
||||
|
||||
@@ -20,15 +20,11 @@ use crate::{error::SkipStep, execution_context::ExecutionContext};
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
struct NPM {
|
||||
command: PathBuf,
|
||||
pnpm: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl NPM {
|
||||
fn new(command: PathBuf) -> Self {
|
||||
Self {
|
||||
command,
|
||||
pnpm: require("pnpm").ok(),
|
||||
}
|
||||
Self { command }
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
@@ -56,17 +52,13 @@ impl NPM {
|
||||
fn upgrade(&self, run_type: RunType, use_sudo: bool) -> Result<()> {
|
||||
print_separator("Node Package Manager");
|
||||
let version = self.version()?;
|
||||
let args = if version < Version::new(8, 11, 0) || self.pnpm.is_some() {
|
||||
let args = if version < Version::new(8, 11, 0) {
|
||||
["update", "-g"]
|
||||
} else {
|
||||
["update", "--location=global"]
|
||||
};
|
||||
if use_sudo {
|
||||
run_type
|
||||
.execute("sudo")
|
||||
.arg(self.pnpm.as_ref().unwrap_or(&self.command))
|
||||
.args(args)
|
||||
.check_run()?;
|
||||
run_type.execute("sudo").args(args).check_run()?;
|
||||
} else {
|
||||
run_type.execute(&self.command).args(args).check_run()?;
|
||||
}
|
||||
@@ -88,6 +80,59 @@ impl NPM {
|
||||
}
|
||||
}
|
||||
|
||||
struct Yarn {
|
||||
command: PathBuf,
|
||||
yarn: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl Yarn {
|
||||
fn new(command: PathBuf) -> Self {
|
||||
Self {
|
||||
command,
|
||||
yarn: require("yarn").ok(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn root(&self) -> Result<PathBuf> {
|
||||
let args = ["global", "dir"];
|
||||
Command::new(&self.command)
|
||||
.args(args)
|
||||
.check_output()
|
||||
.map(|s| PathBuf::from(s.trim()))
|
||||
}
|
||||
|
||||
fn upgrade(&self, run_type: RunType, use_sudo: bool) -> Result<()> {
|
||||
print_separator("Yarn Package Manager");
|
||||
let args = ["global", "upgrade"];
|
||||
|
||||
if use_sudo {
|
||||
run_type
|
||||
.execute("sudo")
|
||||
.arg(self.yarn.as_ref().unwrap_or(&self.command))
|
||||
.args(args)
|
||||
.check_run()?;
|
||||
} else {
|
||||
run_type.execute(&self.command).args(args).check_run()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn should_use_sudo(&self) -> Result<bool> {
|
||||
let yarn_root = self.root()?;
|
||||
if !yarn_root.exists() {
|
||||
return Err(SkipStep(format!("NPM root at {} doesn't exist", yarn_root.display(),)).into());
|
||||
}
|
||||
|
||||
let metadata = std::fs::metadata(&yarn_root)?;
|
||||
let uid = Uid::effective();
|
||||
|
||||
Ok(metadata.uid() != uid.as_raw() && metadata.uid() == 0)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn should_use_sudo(npm: &NPM, ctx: &ExecutionContext) -> Result<bool> {
|
||||
if npm.should_use_sudo()? {
|
||||
@@ -102,8 +147,22 @@ fn should_use_sudo(npm: &NPM, ctx: &ExecutionContext) -> Result<bool> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn should_use_sudo_yarn(yarn: &Yarn, ctx: &ExecutionContext) -> Result<bool> {
|
||||
if yarn.should_use_sudo()? {
|
||||
if ctx.config().yarn_use_sudo() {
|
||||
Ok(true)
|
||||
} else {
|
||||
Err(SkipStep("NPM root is owned by another user which is not the current user. Set use_sudo = true under the NPM section in your configuration to run NPM as sudo".to_string())
|
||||
.into())
|
||||
}
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_npm_upgrade(ctx: &ExecutionContext) -> Result<()> {
|
||||
let npm = require("npm").map(NPM::new)?;
|
||||
let npm = require("pnpm").or_else(|_| require("npm")).map(NPM::new)?;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
@@ -116,6 +175,20 @@ pub fn run_npm_upgrade(ctx: &ExecutionContext) -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_yarn_upgrade(ctx: &ExecutionContext) -> Result<()> {
|
||||
let yarn = require("yarn").map(Yarn::new)?;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
yarn.upgrade(ctx.run_type(), should_use_sudo_yarn(&yarn, ctx)?)
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
{
|
||||
yarn.upgrade(ctx.run_type(), false)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deno_upgrade(ctx: &ExecutionContext) -> Result<()> {
|
||||
let deno = require("deno")?;
|
||||
let deno_dir = ctx.base_dirs().home_dir().join(".deno");
|
||||
|
||||
@@ -349,6 +349,17 @@ fn upgrade_solus(ctx: &ExecutionContext) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run_pacdef(ctx: &ExecutionContext) -> Result<()> {
|
||||
let pacdef = require("pacdef")?;
|
||||
|
||||
print_separator("pacdef");
|
||||
|
||||
ctx.run_type().execute(&pacdef).arg("sync").check_run()?;
|
||||
|
||||
println!();
|
||||
ctx.run_type().execute(&pacdef).arg("review").check_run()
|
||||
}
|
||||
|
||||
pub fn run_pacstall(ctx: &ExecutionContext) -> Result<()> {
|
||||
let pacstall = require("pacstall")?;
|
||||
|
||||
@@ -492,44 +503,50 @@ pub fn flatpak_update(ctx: &ExecutionContext) -> Result<()> {
|
||||
let flatpak = require("flatpak")?;
|
||||
let sudo = require_option(ctx.sudo().as_ref(), String::from("sudo is not installed"))?;
|
||||
let cleanup = ctx.config().cleanup();
|
||||
let yes = ctx.config().yes(Step::Flatpak);
|
||||
let run_type = ctx.run_type();
|
||||
print_separator("Flatpak User Packages");
|
||||
|
||||
run_type
|
||||
.execute(&flatpak)
|
||||
.args(&["update", "--user", "-y"])
|
||||
.check_run()?;
|
||||
let mut update_args = vec!["update", "--user"];
|
||||
if yes {
|
||||
update_args.push("-y");
|
||||
}
|
||||
run_type.execute(&flatpak).args(&update_args).check_run()?;
|
||||
|
||||
if cleanup {
|
||||
run_type
|
||||
.execute(&flatpak)
|
||||
.args(&["uninstall", "--user", "--unused"])
|
||||
.check_run()?;
|
||||
let mut cleanup_args = vec!["uninstall", "--user", "--unused"];
|
||||
if yes {
|
||||
cleanup_args.push("-y");
|
||||
}
|
||||
run_type.execute(&flatpak).args(&cleanup_args).check_run()?;
|
||||
}
|
||||
|
||||
print_separator("Flatpak System Packages");
|
||||
if ctx.config().flatpak_use_sudo() || std::env::var("SSH_CLIENT").is_ok() {
|
||||
run_type
|
||||
.execute(&sudo)
|
||||
.arg(&flatpak)
|
||||
.args(&["update", "--system", "-y"])
|
||||
.check_run()?;
|
||||
let mut update_args = vec!["update", "--system"];
|
||||
if yes {
|
||||
update_args.push("-y");
|
||||
}
|
||||
run_type.execute(&sudo).arg(&flatpak).args(&update_args).check_run()?;
|
||||
if cleanup {
|
||||
run_type
|
||||
.execute(sudo)
|
||||
.arg(flatpak)
|
||||
.args(&["uninstall", "--system", "--unused"])
|
||||
.check_run()?;
|
||||
let mut cleanup_args = vec!["uninstall", "--system", "--unused"];
|
||||
if yes {
|
||||
cleanup_args.push("-y");
|
||||
}
|
||||
run_type.execute(sudo).arg(flatpak).args(&cleanup_args).check_run()?;
|
||||
}
|
||||
} else {
|
||||
run_type
|
||||
.execute(&flatpak)
|
||||
.args(&["update", "--system", "-y"])
|
||||
.check_run()?;
|
||||
let mut update_args = vec!["update", "--system"];
|
||||
if yes {
|
||||
update_args.push("-y");
|
||||
}
|
||||
run_type.execute(&flatpak).args(&update_args).check_run()?;
|
||||
if cleanup {
|
||||
run_type
|
||||
.execute(flatpak)
|
||||
.args(&["uninstall", "--system", "--unused"])
|
||||
.check_run()?;
|
||||
let mut cleanup_args = vec!["uninstall", "--system", "--unused"];
|
||||
if yes {
|
||||
cleanup_args.push("-y");
|
||||
}
|
||||
run_type.execute(flatpak).args(&cleanup_args).check_run()?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -558,6 +575,15 @@ pub fn run_pihole_update(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()
|
||||
run_type.execute(sudo).arg(pihole).arg("-up").check_run()
|
||||
}
|
||||
|
||||
pub fn run_protonup_update(ctx: &ExecutionContext) -> Result<()> {
|
||||
let protonup = require("protonup")?;
|
||||
|
||||
print_separator("protonup");
|
||||
|
||||
ctx.run_type().execute(protonup).check_run()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run_config_update(ctx: &ExecutionContext) -> Result<()> {
|
||||
let sudo = require_option(ctx.sudo().as_ref(), String::from("sudo is not installed"))?;
|
||||
if ctx.config().yes(Step::ConfigUpdate) {
|
||||
|
||||
@@ -210,6 +210,10 @@ pub fn run_brew_formula(ctx: &ExecutionContext, variant: BrewVariant) -> Result<
|
||||
variant.execute(run_type).arg("cleanup").check_run()?;
|
||||
}
|
||||
|
||||
if ctx.config().brew_autoremove() {
|
||||
variant.execute(run_type).arg("autoremove").check_run()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -251,6 +255,24 @@ pub fn run_brew_cask(ctx: &ExecutionContext, variant: BrewVariant) -> Result<()>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run_guix(ctx: &ExecutionContext) -> Result<()> {
|
||||
let guix = require("guix")?;
|
||||
|
||||
let run_type = ctx.run_type();
|
||||
|
||||
let output = Command::new(&guix).arg("pull").check_output();
|
||||
debug!("guix pull output: {:?}", output);
|
||||
let should_upgrade = output.is_ok();
|
||||
debug!("Can Upgrade Guix: {:?}", should_upgrade);
|
||||
|
||||
print_separator("Guix");
|
||||
|
||||
if should_upgrade {
|
||||
return run_type.execute(&guix).args(&["package", "-u"]).check_run();
|
||||
}
|
||||
Err(SkipStep(String::from("Guix Pull Failed, Skipping")).into())
|
||||
}
|
||||
|
||||
pub fn run_nix(ctx: &ExecutionContext) -> Result<()> {
|
||||
let nix = require("nix")?;
|
||||
let nix_channel = require("nix-channel")?;
|
||||
@@ -274,6 +296,16 @@ pub fn run_nix(ctx: &ExecutionContext) -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
if let Ok(..) = require("darwin-rebuild") {
|
||||
return Err(SkipStep(String::from(
|
||||
"Nix-darwin on macOS must be upgraded via darwin-rebuild switch",
|
||||
))
|
||||
.into());
|
||||
}
|
||||
}
|
||||
|
||||
let run_type = ctx.run_type();
|
||||
|
||||
if should_self_upgrade {
|
||||
@@ -391,6 +423,14 @@ pub fn run_sdkman(base_dirs: &BaseDirs, cleanup: bool, run_type: RunType) -> Res
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run_bun(ctx: &ExecutionContext) -> Result<()> {
|
||||
let bun = require("bun")?;
|
||||
|
||||
print_separator("Bun");
|
||||
|
||||
ctx.run_type().execute(&bun).arg("upgrade").check_run()
|
||||
}
|
||||
|
||||
pub fn reboot() {
|
||||
print!("Rebooting...");
|
||||
Command::new("sudo").arg("reboot").spawn().unwrap().wait().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user