Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build packages on Travis #15

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ __pycache__
*.pyc
*test*
sources.list
pkg
tmp-build
tmp-dest
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: ruby
rvm:
- 2.1
addons:
apt:
packages:
- python-bs4
script: make
deploy:
- provider: releases
api-key: $GITHUB_API_KEY
file: 'pkg/apt-select_${TRAVIS_TAG}-0_all.deb'
skip_cleanup: true
on:
tags: true
- provider: bintray
user: $BINTRAY_USER
key: $BINTRAY_KEY
dry-run: true
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions bin/apt-select
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

current_path=$(dirname $([ -L $0 ] && readlink -f $0 || echo $0))
workdir=${current_path}/..

exec ${workdir}/apt-select.py $@
File renamed without changes.
69 changes: 69 additions & 0 deletions deb-package.rb
Original file line number Diff line number Diff line change
@@ -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 <brodock@gmail.com>'
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