diff --git a/.gitignore b/.gitignore index bb4d8dc..c234179 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ __pycache__ *.pyc *test* sources.list +pkg +tmp-build +tmp-dest diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..286aced --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +all: package + +package: package-dependencies + @fpm-cook package deb-package.rb + +package-dependencies: + @if ! `gem list -i fpm-cookery`; then gem install fpm-cookery; fi diff --git a/bin/apt-select b/bin/apt-select new file mode 100755 index 0000000..61ffcbb --- /dev/null +++ b/bin/apt-select @@ -0,0 +1,6 @@ +#!/bin/bash + +current_path=$(dirname $([ -L $0 ] && readlink -f $0 || echo $0)) +workdir=${current_path}/.. + +exec ${workdir}/apt-select.py $@ diff --git a/update.sh b/bin/apt-select-update similarity index 100% rename from update.sh rename to bin/apt-select-update diff --git a/deb-package.rb b/deb-package.rb new file mode 100644 index 0000000..dd60a22 --- /dev/null +++ b/deb-package.rb @@ -0,0 +1,69 @@ +class AptSelect < FPM::Cookery::Recipe + name 'apt-select' + version '0.1.0' + revision 0 + homepage 'https://github.com/jblakeman/apt-select' + license 'MIT' + description 'Choose a fast, up to date Ubuntu apt mirror' + maintainer 'Gabriel Mazetto ' + source './', :with => :local_path + arch 'all' + + platforms [:ubuntu] do + depends 'python-bs4' + end + + def build + end + + def install + share('apt-select').mkdir + share('apt-select/bin').mkdir + Dir["#{workdir}/*"].each { |f| share('apt-select').install f if allowed_file?(f) } + Dir["#{workdir}/bin/*"].each { |f| share('apt-select/bin').install f } + + with_trueprefix do + create_post_install_hook <<-EOF + set -e + BIN_PATH="#{share('apt-select/bin')}" + + update-alternatives --install /usr/bin/apt-select apt-select $BIN_PATH/apt-select 100 + update-alternatives --install /usr/bin/apt-select-update apt-select-update $BIN_PATH/apt-select-update 100 + + exit 0 + EOF + create_pre_uninstall_hook <<-EOF + set -e + BIN_PATH="#{share('apt-select/bin')}" + + if [ "$1" != "upgrade" ]; then + update-alternatives --remove apt-select $BIN_PATH/apt-select + update-alternatives --remove apt-select-update $BIN_PATH/apt-select-update + fi + + exit 0 + EOF + end + end + + private + + def allowed_file?(file) + allowed_formats = %w(.py .md .sh) + allowed_formats.include? File.extname(file) + end + + def create_post_install_hook(script, interpreter = '/bin/sh') + File.open(builddir('post-install'), 'w', 0755) do |f| + f.write "#!#{interpreter}\n" + script.gsub(/^\s+/, '') + self.class.post_install(File.expand_path(f.path)) + end + end + + def create_pre_uninstall_hook(script, interpreter = '/bin/sh') + File.open(builddir('pre-uninstall'), 'w', 0755) do |f| + f.write "#!#{interpreter}\n" + script.gsub(/^\s+/, '') + self.class.pre_uninstall(File.expand_path(f.path)) + end + end +end