# Automate APT pinning for Debian distributons # Copyright (C) 2015 Rafael Laboissière # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation, either version 3 of the License, or (at your # option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . SHELL = /bin/bash APT_DIR = /etc/apt PREFS_FILE = preferences.d/debian-releases SRC_DIR = sources.list.d DEFAULT_MIRROR = ftp.us.debian.org MIRROR = DEFAULT_ORDER = stable testing unstable experimental ORDER = MANIFEST = .installed-files .PHONY: install install: @if [ -z "$(MIRROR)" ] ; then \ echo -n "Debian mirror [$(DEFAULT_MIRROR)]: " ; \ read mirror ; \ if [ -z "$$mirror" ] ; then \ mirror=$(DEFAULT_MIRROR) ; \ fi ; \ else \ mirror=$(MIRROR) ; \ fi ; \ if [ -z "$(ORDER)" ] ; then \ echo -n "Priority order [$(DEFAULT_ORDER)]: " ; \ read order ; \ if [ -z "$$order" ] ; then \ order=($(DEFAULT_ORDER)) ; \ fi ; \ else \ order=($(ORDER)) ; \ fi ; \ echo "Installing preferences file..." ; \ prefs=$(APT_DIR)/$(PREFS_FILE) ; \ rm -f $$prefs ; \ echo $$prefs > $(MANIFEST) ; \ priority=1000 ; \ for i in $$( seq 0 $$(( $${#order[*]} - 1)) ) ; do \ echo "Package: *" >> $$prefs ; \ echo "Pin: release a=$${order[$$i]}" >> $$prefs ; \ echo "Pin-Priority: $$priority" >> $$prefs ; \ echo "" >> $$prefs ; \ priority=$$(( $$priority - 100 )) ; \ done ; \ echo "Installing source files..." ; \ srcdir=$(APT_DIR)/$(SRC_DIR) ; \ for d in $${order[*]} ; do \ f=$$srcdir/debian-$$d.list ; \ rm -f $$f ; \ echo $$f >> $(MANIFEST) ; \ for t in deb deb-src ; do \ echo -n "$$t http://$$mirror/debian/" >> $$f ; \ echo " $$d main contrib non-free" >> $$f ; \ done ; \ done aptitude update .PHONY: uninstall uninstall: [ -f $(MANIFEST) ] && rm -f $$(cat $(MANIFEST)) .PHONY: doc doc: [ -n "$$(which markdown_py)" -a -n "$$(which w3m)" ] \ && markdown_py README.md -x fenced_code | w3m -T text/html \ || cat README.md