= Introduction to /etc/alternatives :title: Introduction to /etc/alternatives :author: der.hans - https://www.LuftHans.com/talks/ :homepage: https://www.LuftHans.com/talks/ :copyright: 2018 der.hans --- CC BY-SA 4.0 unported :date: 2018Aug09 :max-width: 60em :website: https://www.LuftHans.com/talks/ :source-highlighter: pygments :imagesdir: resources //// Proposal * Approximate Length: 30 min * Description: ---- /etc/alternatives allows choosing among many programs to provide a certain functionality. For instance, editor can point the locally preferred text editor. alternatives will also make sure man-pages also match. Attendees will learn: * what is /etc/alternatives * why is /etc/alternatives * how to configure /etc/alternatives * how to use helper scripts //// == Upcoming Hans PLUG: 2018Sep13 ActivityPub: the decentralized social networking protocol allowing federated services like Mastodon, Pleroma, Plume, PixelFed, PeerTube and CloutStream to interact == What is? /etc/alternatives is a system for determining default commands update-alternatives - maintain symbolic links determining default commands == Long Form ---- Different packages providing the same file need to do so cooperatively. In other words, the usage of update-alternatives is mandatory for all involved packages in such case. It is not possible to override some file in a package that does not employ the update-alternatives mecha‐ nism. ---- == History originally created for debian now available for most distributions == Features * system wide * local override * automagic default * rank options * works with packages * grouping == Symlink chain ---- $ ls -l /usr/bin/pager lrwxrwxrwx 1 root root 23 Nov 29 2016 /usr/bin/pager -> /etc/alternatives/pager $ ls -l /etc/alternatives/pager lrwxrwxrwx 1 root root 9 Nov 29 2016 /etc/alternatives/pager -> /bin/less $ ---- == Grouping ---- $ ls -l /etc/alternatives/pager* lrwxrwxrwx 1 root root 9 Nov 29 2016 /etc/alternatives/pager -> /bin/less lrwxrwxrwx 1 root root 29 Nov 29 2016 /etc/alternatives/pager.1.gz -> /usr/share/man/man1/less.1.gz ---- == Examples: in use visudo uses editor to determine which text editor to use == Examples: list ---- $ update-alternatives --list x-session-manager /usr/bin/startkde $ $ update-alternatives --list editor /bin/ed /bin/nano /usr/bin/vim.gtk /usr/bin/vim.nox /usr/bin/vim.tiny $ ---- == Examples: display details ---- $ update-alternatives --display x-session-manager x-session-manager - auto mode link best version is /usr/bin/startkde link currently points to /usr/bin/startkde link x-session-manager is /usr/bin/x-session-manager /usr/bin/startkde - priority 40 $ ---- == Examples: display with group ---- $ update-alternatives --display pager pager - auto mode link best version is /bin/less link currently points to /bin/less link pager is /usr/bin/pager slave pager.1.gz is /usr/share/man/man1/pager.1.gz /bin/less - priority 77 slave pager.1.gz: /usr/share/man/man1/less.1.gz /bin/more - priority 50 slave pager.1.gz: /usr/share/man/man1/more.1.gz /usr/bin/pg - priority 10 slave pager.1.gz: /usr/share/man/man1/pg.1.gz $ ---- == Examples: local override ---- $ update-alternatives --config pager There are 3 choices for the alternative pager (providing /usr/bin/pager). Selection Path Priority Status ------------------------------------------------------------ * 0 /bin/less 77 auto mode 1 /bin/less 77 manual mode 2 /bin/more 50 manual mode 3 /usr/bin/pg 10 manual mode Press to keep the current choice[*], or type selection number: $ ---- // highest priority wins // not gonna work, ENOTROOT == Examples: return to default ---- $ update-alternatives --auto pager $ ---- == Examples: non-interactive mode ---- # update-alternatives --set pager /bin/more update-alternatives: using /bin/more to provide /usr/bin/pager (pager) in manual mode # ---- == Examples: list alternatives ---- update-alternatives --get-selections ---- == Examples: roll your own ---- # update-alternatives --install /usr/bin/pager pager /bin/cat 99 --slave /usr/share/man/man1/pager.1.gz pager.1.gz /usr/share/man/man1/cat.1.gz # ---- == Examples: roll your own caution ---- # update-alternatives --install /bin/pager pager /bin/cat 99 update-alternatives: renaming pager link from /usr/bin/pager to /bin/pager # ---- == Examples: unroll your own ---- # update-alternatives --remove pager /bin/cat # ---- == Examples: other CLI options * --query: machine readable form of display * --skip-auto: skip alternatives in auto mode * --verbose: more feedback about what's changing * --quiet: don't generate feedback unless an error occurs == Examples: alternatives * editor * www-browser * x-www-browser * pager * c++ * traceroute * sendmail * unison * adventure == Special Handling: java ---- update-java-alternatives updates all alternatives belonging to one run‐ time or development kit for the Java language. A package does provide these information of it's alternatives in /usr/lib/jvm/..jinfo. ---- == Other Mechanisms * environmental variable * sensible-utils * aliases == Other Mechanisms: environmental variable ---- $ EDITOR=/usr/bin/vim visudo ---- == Other Mechanisms: sensible-utils ---- This package provides a number of small utilities which are used by programs to sensibly select and spawn an appropriate browser, editor, or pager. ---- // crontab -e == Other Mechanisms: aliases ---- $ alias pager=/bin/cat $ type pager pager is aliased to `/bin/cat' $ unalias pager $ type pager pager is /usr/bin/pager $ ---- == Contacting der.hans Thank you! * Mastodon ** https://mastodon.social/@lufthans * G+ ** https://plus.google.com/106398898073454924098 * IRC ** LuftHans on Freenode, usually in #LOPSA and #PLUGaz == Resources * https://wiki.debian.org/DebianAlternatives ** Debian's wiki page on the alternatives system * http://manpages.ubuntu.com/manpages/intrepid/man8/update-alternatives.8.html ** update-alternatives man page * http://manpages.ubuntu.com/manpages/bionic/man1/galternatives.1.html ** galternatives - graphical tool for alternatives * http://www.debianadmin.com/galternatives-graphical-setup-tool-for-alternatives-configuration-in-ubuntu.html ** article on galternatives * update-