sxiii

Linux Distros Unified Package Manipulation Alias Script

Mar 16th, 2016
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.30 KB | None | 0 0
  1. #!/bin/bash
  2. ###############################################################################
  3. # Universal Multi-Distro Mostly Used Aliases Script ###########################
  4. ########################################## More than 20 pkg managers supported!
  5. # What is this script for? It creates aliases that can be used as simple as:
  6. # i = install package, up = update repos, ug = upgrade sytem, r = remove, etc.
  7. # This scripts works with any distro (it knows more than 20 package managers).
  8. # It also adds "lsb" command which shows you info about your distro & packages.
  9. # And you don't have to look which actual package manager your system uses.
  10. ###############################################################################
  11. # Based on package management article from distrowatch which is here:
  12. # http://distrowatch.com/package-management
  13. ###############################################################################
  14. # This script was written in the idea of uniting several package management
  15. # system into one single command that can be issued easily.
  16. # This script DOES NOT detect your distros because it is not so important
  17. # while we just want to see if you have any package managers installed.
  18. # That wouldn't be a problem because small amount of people uses more than one
  19. # package managers (guys you will have to fix this script in this case)
  20. # ################## Currently supported package managers #####################
  21. # Main distributions: Ubuntu, Debian (apt-get), OpenSUSE (zypper),
  22. # Fedora, CentOS, RedHat (yum/dnf), Mandriva, Mageia (urpmi).
  23. # Slackware distros: Slackware (slackpkg), Vector (slapt-get), Zenwalk (netpkg),
  24. # Independent distros: Sabayon (equo), Arch/Manjaro (pacman),
  25. # Foresight, rPath (conary), Alpine (apk).
  26. # Multi-distro (distro-agnostic) package managers: Mandria, OpenSUSE (smart),
  27. # Fedora, Ubuntu, openSUSE, Mandriva (pkcon).
  28. # Source package managers: Gentoo (emerge), Lunar (lin), Source Mage (cast),
  29. # New, binary pac.-man. systems: NixOS (nix), Void (xbps), Ubuntu (snappy).
  30. # FreeBSD: 10.0+ (pkg).
  31. # Totally this script supports 6 categories of package managers, 20+ pcs.
  32. ###############################################################################
  33. # Written 19~23 feb 2016 by Security XIII at Gmail Dot Com.
  34. # v 0.04 alpha, has to check it on many distros ! but probably usable somehow #
  35. ###############################################################################
  36. # Re-creates empty bash aliases file for you (fix if needed)
  37. afile="$HOME/.bash_aliases"
  38. rm $afile; touch $afile
  39. # If your distro/user doesen't need sudo just comment the following line:
  40. sn='sudo'
  41. # Choose your editor (to open mirror files)
  42. ed='nano'
  43. # Distro founded
  44. df="You're using"
  45. # Set debug="echo" to turn on debug mode (does not make any syschanges)
  46. debug=""
  47. # Error handling
  48. err1="echo"
  49. err2="not needed"
  50.  
  51. # Aliases (you can edit them to your like)
  52. mkaliases() {
  53. shopt -s expand_aliases
  54. $debug echo "alias i=\"$sn $1 $2\"" >> $afile        # installing packages (from repo)
  55. $debug echo "alias ii=\"$sn $3 $4\"" >> $afile       # installing packages (from file)
  56. $debug echo "alias r=\"$sn $5 $6\"" >> $afile        # removing packages
  57. $debug echo "alias up=\"$sn $7 $8\"" >> $afile       # updating packages (list)
  58. $debug echo "alias ug=\"$sn $9 ${10}\"" >> $afile    # upgrading packages (themselves)
  59. $debug echo "alias s=\"$sn ${11} ${12}\"" >> $afile  # searching packages
  60. $debug echo "alias li=\"$sn ${13} ${14}\"" >> $afile # list installed packages
  61. $debug echo "alias rl=\"$sn ${15} ${16}\"" >> $afile   # list your repositories
  62. $debug echo "alias ra=\"$sn ${17} ${18}\"" >> $afile # add new repository or PPA
  63. $debug echo "alias rr=\"$sn ${19} ${20}\"" >> $afile # removes repository or PPA
  64. $debug echo "alias lsb=\"echo /etc/*_ver* /etc/*-rel*; cat /etc/*_ver* /etc/*-rel*\"" >> $afile # info
  65. source ~/.bash_aliases
  66. }
  67.  
  68. # Command to check existence of package manager (can also be command or type)
  69. checkcmd='hash'
  70.  
  71. # To add your own package manager, write function for it similar to
  72. # the following functions, adding "f" letter in the front of package
  73. # manager name, and add it to the end of checkarray list.
  74. # Example: your package manager is "zeta", write function with the name
  75. # "fzeta" similar to others. Last step, add it to the end of 'checkarray' array.
  76. # When writing functions, include options from mkaliases one after another
  77. # (!) Don't forget to include empty places '' if no variable is needed (!)
  78. # (!) You should pass total of 20 variables, most of which shouldn't be empty.
  79.  
  80.   # Writing own function help sample
  81. fapt-get() { s='apt-get'; echo "$df $s on Debian/Ubuntu"
  82.   mkaliases $s install dpkg -i $s remove $s update $s upgrade apt-cache search dpkg -l cat /etc/apt/sources.list apt-add-repository '' apt-add-repository -r
  83.   # ^funct  ^$1  ^$2   ^$3  ^$4 ^$5  ^$6 ^$7  ^$8   ^$9  ^$10   ^$11    ^$12   ^$13 ^$14 ^$15      ^$16          ^$17               ^$18    ^$19          ^$20
  84.   # Variables just go one by one, one after another, from mkaliases list.
  85. }
  86.  
  87. function fzypper { s='zypper'; echo "$df $s on OpenSUSE"
  88.   mkaliases $s install $s install $s remove $s refresh $s update $s search $s 'search -is' $s repos $s addrepo $s removerepo
  89. }
  90.  
  91. function fyum { s='yum'; echo "$df $s on Fedora/CentOS"
  92.   mkaliases $s install $s localinstall $s erase $s check-update $s update $s list rpm -qa $s repolist 'cd /etc/yum.repos.d/' '&& ls' 'cd /etc/yum.repos.d/' '&& ls'
  93. }
  94.  
  95. function furpmi { s='urpmi'; echo "$df $s on Mandriva/Mageia"
  96.   mkaliases $s '' $s '' urpme '' $s.update -a $s '--auto-select' urpmq '' rpm -qa urpmq --list-media $s.addmedia '' $s.removemedia ''
  97. }
  98.  
  99. function fslackpkg { s='slackpkg'; echo "$df $s on Slackware"
  100.   mkaliases $s install $s install $s remove $s update $s upgrade-all $s search ls /var/log/packages/ cat /etc/slackpkg/mirrors "$sn $ed" '/etc/slackpkg/mirrors' "$sn $ed" '/etc/slackpkg/mirrors'
  101. }
  102.  
  103. function fslapt-get { s='slapt-get'; echo "$df $s on Vector"
  104.   mkaliases $s --install $s --install $s --remove $s --update $s --upgrade $s --search $s --installed cat /etc/slapt-get/slapt-getrc "$sn $ed" '/etc/slapt-get/slapt-getrc' "$sn $ed" '/etc/slapt-get/slapt-getrc'
  105. }
  106.  
  107. function fnetpkg { s='netpkg'; echo "$df $s on Zenwalk"
  108.   mkaliases $s '' $s '' $s remove "$err1" "$err2" $s upgrade $s 'list | grep' $s 'list I' $s mirror "$sn $ed" '/etc/netpkg.conf' "$sn $ed" '/etc/netpkg.conf'
  109. }
  110.  
  111. function fequo { s='equo'; echo "$df $s on Sabayon"
  112.   mkaliases $s install $s install $s remove $s update $s upgrade $s search $s list $s repoinfo 'cd /etc/entropy/repositories.conf.d' '&& ls' 'cd /etc/entropy/repositories.conf.d' '&& ls'
  113. }
  114.  
  115. function fpacman { s='pacman'; echo "$df $s on Arch/Manjaro"
  116.   mkaliases $s -S $s -U $s -R $s -Sy $s -Su $s -Ss $s -Q cat /etc/pacman.conf $ed /etc/pacman.conf $ed /etc/pacman.conf
  117. }
  118.  
  119. function fconary { s='conary'; echo "$df $s on Foresight/rPath"
  120.   mkaliases $s update $s update $s erase "$err1" "$err2" $s updateall $s query $s query "$err1" "$err2" "$err1" "$err2" "$err1" "$err2"
  121. }
  122.  
  123. function fapk { s='apk'; echo "$df $s on Alpine"
  124.   mkaliases $s add $s 'add --force' $s del $s update $s upgrade $s search $s info cat /etc/apk/repositories setup-apkrepos '' $ed /etc/apk/repositories
  125. }
  126.  
  127. function fsmart { s='smart'; echo "$df $s on Mandriva/OpenSUSE"
  128.   mkaliases $s install $s install $s remove $s update $s upgrade $s search $s 'query --installed' $s 'channel --show' $s 'channel --add' $s 'channel --remove'
  129. }
  130.  
  131. function fpkcon { s='pkcon'; echo "$df $s on Fedora/Ubuntu/OpenSUSE/Mandriva"
  132.   mkaliases $s install $s install-file $s remove $s refresh $s upgrade $s search $s search $s repo-list "$err1" "$err2" "$err1" "$err2"
  133. }
  134.  
  135. function femerge { s='emerge'; echo "$df $s on Gentoo"
  136.   mkaliases $s '' "$err1" "$err2" $s '-aC' $s '--sync' $s '-NuDa world' $s '--search' qlist -I layman -L layman -a layman -d
  137. }
  138.  
  139. function flin { s='lin'; echo "$df $s on Lunar"
  140.   mkaliases $s '' "$err1" "$err2" lrm '' $s moonbase lunar update lvu search lvu installed "$err1" "$err2" "$err1" "$err2" "$err1" "$err2"
  141. }
  142.  
  143. function fcast { echo "$df $s on Source Mage"
  144.   mkaliases cast '' "$err1" "$err2" dispel '' scribe update sorcery upgrade gaze search gaze installed scribe index scribe add scribe remove
  145. }
  146.  
  147. function fnix-env { s='nix-env'; echo "$df $s on NixOS"
  148.   mkaliases $s -i "$err1" "$err2" $s -e nix-channel --update nix-env -u nix-env -qa nix-env -q nix-channel --list nix-channel --add nix-channel --remove
  149. }
  150.  
  151. function fxbps-install { s='xbps-install'; echo "$df $s on Void"
  152.   mkaliases $s '' "$err1" "$err2" xbps-remove '' $s -S $s -u xbps-query -Rs xbps-query -l xbps-query -L 'cd /etc/xbps/repo.d/' '&& ls' 'cd /etc/xbps/repo.d/' '&& ls'
  153. }
  154.  
  155. function fsnappy { s='snappy'; echo "$df $s on Ubuntu Snappy"
  156.   mkaliases $s install "$err1" "$err2" $s remove "$err1" "$err2" $s update $s search $s list "$err1" "$err2" "$err1" "$err2" "$err1" "$err2"
  157. }
  158.  
  159. function fpkg { s='pkg'; echo "$df $s on FreeBSD 10.0+"
  160.   mkaliases $s install $s add $s remove $s update $s upgrade $s search $s info "$err1" "$err2" "$err1" "$err2" "$err1" "$err2"
  161. }
  162.  
  163. checkarray=(apt-get zypper yum urpmi slackpkg slapt-get netpkg equo pacman conary apk smart pkcon emerge lin cast nix-env xbps-install snappy pkg)
  164.  
  165. for i in ${checkarray[@]};
  166. do
  167.   ($checkcmd $i &>/dev/null) && f$i
  168. done
  169.  
  170. echo "Aliases added. If you don't know them just open this script to find out."
Advertisement
Add Comment
Please, Sign In to add comment