aboutsummaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2016-09-14 18:57:48 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2016-09-14 18:57:48 +0200
commit527cc270d660cbfd4076f5ff4af3471988322eea (patch)
treea035a10de374837250c9d28be1044dc8828289ac /config
parent55442d4a1452ab89d8bfd659a0a324447e9f86d3 (diff)
downloaddotfiles-527cc270d660cbfd4076f5ff4af3471988322eea.tar.gz
dotfiles-527cc270d660cbfd4076f5ff4af3471988322eea.zip
add universal package upgrade function
It handles: + Arch with AUR (pacaur/yaourt) + Debian
Diffstat (limited to 'config')
-rw-r--r--config/fish/functions/upgrade.fish45
1 files changed, 45 insertions, 0 deletions
diff --git a/config/fish/functions/upgrade.fish b/config/fish/functions/upgrade.fish
new file mode 100644
index 0000000..aace60b
--- /dev/null
+++ b/config/fish/functions/upgrade.fish
@@ -0,0 +1,45 @@
+#TODO update dotfile directory
+
+function upgrade -d "universal upgrade function"
+ function is_command -a cmd -d "check if a command is available"
+ type $cmd >/dev/null 2>/dev/null
+ end
+
+ function maybe_root -a cmd -d "execute a cmd if it fails try to use sudo"
+ set res (eval $cmd 2>&1)
+ # cmd failed
+ if test $status -gt 0
+ # try to guess cause
+ if string match -r ".*root|permission.*" "$res"
+ set s_cmd ""
+ for c in (string split ";" $cmd)
+ set s_cmd $s_cmd (echo $c | sed -r "s/^ ?(and |or )?/\1sudo /" -)
+ end
+ eval (string join ";" $s_cmd)
+ else
+ echo "$res" >&2
+ return $status
+ end
+ end
+ end
+
+ # Arch
+ if is_command pacman
+ if is_command pacaur
+ pacaur -Syu
+ else if is_command yaourt
+ yaourt -Syua
+ else
+ maybe_root "pacman -Syu"
+ end
+ end
+
+ # Debian based
+ if is_command apt-get
+ if is_command apt
+ maybe_root "apt update; and apt dist-upgrade"
+ else
+ maybe_root "apt-get update; and apt-get dist-upgrade"
+ end
+ end
+end