Commit edb3f09f authored by kytv's avatar kytv
Browse files

Merge branch 'devel' into feature/5663-return-to-icedove

Conflicts:
	config/chroot_apt/preferences
	config/chroot_local-includes/etc/skel/.claws-mail/clawsrc
	config/chroot_local-packageslists/tails-common.list
	config/chroot_local-patches/torsocks_claws-mail.diff
parents 5cf2ad75 a3f66357
......@@ -32,3 +32,23 @@
/vagrant/definitions/squeeze/preseed.cfg
/vagrant/iso
/vagrant/squeeze.box
# Jenkins artifacts directory
/build-artifacts/
# Files managed by intltool
/config/chroot_local-includes/etc/skel/Desktop/tails-documentation.desktop
/config/chroot_local-includes/etc/skel/Desktop/Report_an_error.desktop
/config/chroot_local-includes/etc/skel/Desktop/Tails_documentation.desktop
/config/chroot_local-includes/usr/share/applications/tails-documentation.desktop
/config/chroot_local-includes/usr/share/applications/tails-reboot.desktop
/config/chroot_local-includes/usr/share/applications/unsafe-browser.desktop
/config/chroot_local-includes/usr/share/applications/tails-shutdown.desktop
/config/chroot_local-includes/usr/share/applications/i2p-browser.desktop
/config/chroot_local-includes/usr/share/applications/tor-browser.desktop
/config/chroot_local-includes/usr/share/applications/tails-about.desktop
/config/chroot_local-includes/usr/share/desktop-directories/Tails.directory
/tmp/
# The test suite's local configuration files
/features/config/local.yml
/features/config/*.d/
[submodule "submodules/pythonlib"]
path = submodules/pythonlib
url = https://git-tails.immerda.ch/pythonlib
[submodule "submodules/jenkins-tools"]
path = submodules/jenkins-tools
url = https://git-tails.immerda.ch/jenkins-tools
......@@ -25,6 +25,7 @@ require 'uri'
$:.unshift File.expand_path('../vagrant/lib', __FILE__)
require 'tails_build_settings'
require 'vagrant_version'
# Path to the directory which holds our Vagrantfile
VAGRANT_PATH = File.expand_path('../vagrant', __FILE__)
......@@ -33,7 +34,7 @@ VAGRANT_PATH = File.expand_path('../vagrant', __FILE__)
STABLE_BRANCH_NAMES = ['stable', 'testing']
# Environment variables that will be exported to the build script
EXPORTED_VARIABLES = ['http_proxy', 'MKSQUASHFS_OPTIONS', 'TAILS_RAM_BUILD', 'TAILS_CLEAN_BUILD', 'TAILS_BOOTSTRAP_CACHE']
EXPORTED_VARIABLES = ['http_proxy', 'MKSQUASHFS_OPTIONS', 'TAILS_RAM_BUILD', 'TAILS_CLEAN_BUILD']
# Let's save the http_proxy set before playing with it
EXTERNAL_HTTP_PROXY = ENV['http_proxy']
......@@ -41,26 +42,59 @@ EXTERNAL_HTTP_PROXY = ENV['http_proxy']
# In-VM proxy URL
INTERNEL_HTTP_PROXY = "http://#{VIRTUAL_MACHINE_HOSTNAME}:3142"
def current_vm_memory
def primary_vm
env = Vagrant::Environment.new(:cwd => VAGRANT_PATH, :ui_class => Vagrant::UI::Basic)
uuid = env.primary_vm.uuid
info = env.primary_vm.driver.execute 'showvminfo', uuid, '--machinereadable'
$1.to_i if info =~ /^memory=(\d+)/
if vagrant_old
return env.primary_vm
else
name = env.primary_machine_name
return env.machine(name, env.default_provider)
end
end
def primary_vm_state
if vagrant_old
return primary_vm.state
else
return primary_vm.state.id
end
end
def primary_vm_chan
if vagrant_old
return primary_vm.channel
else
return primary_vm.communicate
end
end
def vm_id
if vagrant_old
primary_vm.uuid
else
primary_vm.id
end
end
def vm_driver
if vagrant_old
primary_vm.driver
else
primary_vm.provider.driver
end
end
def current_vm_cpus
env = Vagrant::Environment.new(:cwd => VAGRANT_PATH, :ui_class => Vagrant::UI::Basic)
uuid = env.primary_vm.uuid
info = env.primary_vm.driver.execute 'showvminfo', uuid, '--machinereadable'
info = vm_driver.execute 'showvminfo', vm_id, '--machinereadable'
$1.to_i if info =~ /^cpus=(\d+)/
end
def vm_running?
env = Vagrant::Environment.new(:cwd => VAGRANT_PATH, :ui_class => Vagrant::UI::Basic)
env.primary_vm.state == :running
primary_vm_state == :running
end
def enough_free_memory?
def enough_free_host_memory_for_ram_build?
return false unless RbConfig::CONFIG['host_os'] =~ /linux/i
begin
......@@ -71,6 +105,24 @@ def enough_free_memory?
end
end
def free_vm_memory
primary_vm_chan.execute("free", :error_check => false) do |fd, data|
return data.split[16].to_i
end
end
def enough_free_vm_memory_for_ram_build?
free_vm_memory > BUILD_SPACE_REQUIREMENT * 1024
end
def enough_free_memory_for_ram_build?
if vm_running?
enough_free_vm_memory_for_ram_build?
else
enough_free_host_memory_for_ram_build?
end
end
def is_release?
branch_name = `git name-rev --name-only HEAD`
tag_name = `git describe --exact-match HEAD 2> /dev/null`
......@@ -91,7 +143,7 @@ task :parse_build_options do
options = ''
# Default to in-memory builds if there is enough RAM available
options += 'ram ' if enough_free_memory?
options += 'ram ' if enough_free_memory_for_ram_build?
# Use in-VM proxy unless an external proxy is set
options += 'vmproxy ' unless EXTERNAL_HTTP_PROXY
......@@ -111,17 +163,10 @@ task :parse_build_options do
case opt
# Memory build settings
when 'ram'
unless vm_running? || enough_free_memory?
abort "Not enough free memory to do an in-memory build. Aborting."
end
ENV['TAILS_RAM_BUILD'] = '1'
when 'noram'
ENV['TAILS_RAM_BUILD'] = nil
# Bootstrap cache settings
when 'cache'
ENV['TAILS_BOOTSTRAP_CACHE'] = '1'
when 'nocache'
ENV['TAILS_BOOTSTRAP_CACHE'] = nil
# HTTP proxy settings
when 'extproxy'
abort "No HTTP proxy set, but one is required by TAILS_BUILD_OPTIONS. Aborting." unless EXTERNAL_HTTP_PROXY
......@@ -195,12 +240,35 @@ end
desc 'Build Tails'
task :build => ['parse_build_options', 'ensure_clean_repository', 'validate_http_proxy', 'vm:up'] do
if ENV['TAILS_RAM_BUILD'] && not(enough_free_memory_for_ram_build?)
$stderr.puts <<-END_OF_MESSAGE.gsub(/^ /, '')
The virtual machine is not currently set with enough memory to
perform an in-memory build. Either remove the `ram` option from
the TAILS_BUILD_OPTIONS environment variable, or shut the
virtual machine down using `rake vm:halt` before trying again.
END_OF_MESSAGE
abort 'Not enough memory for the virtual machine to run an in-memory build. Aborting.'
end
if ENV['TAILS_BUILD_CPUS'] && current_vm_cpus != ENV['TAILS_BUILD_CPUS'].to_i
$stderr.puts <<-END_OF_MESSAGE.gsub(/^ /, '')
The virtual machine is currently running with #{current_vm_cpus}
virtual CPU(s). In order to change that number, you need to
stop the VM first, using `rake vm:halt`. Otherwise, please
adjust the `cpus` options accordingly.
END_OF_MESSAGE
abort 'The virtual machine needs to be reloaded to change the number of CPUs. Aborting.'
end
exported_env = EXPORTED_VARIABLES.select { |k| ENV[k] }.
collect { |k| "#{k}='#{ENV[k]}'" }.join(' ')
env = Vagrant::Environment.new(:cwd => VAGRANT_PATH)
status = env.primary_vm.channel.execute("#{exported_env} build-tails",
:error_check => false) do |fd, data|
status = primary_vm_chan.execute("#{exported_env} build-tails",
:error_check => false) do |fd, data|
(fd == :stdout ? $stdout : $stderr).write data
end
......@@ -214,8 +282,7 @@ end
namespace :vm do
desc 'Start the build virtual machine'
task :up => ['parse_build_options', 'validate_http_proxy'] do
env = Vagrant::Environment.new(:cwd => VAGRANT_PATH, :ui_class => Vagrant::UI::Basic)
case env.primary_vm.state
case primary_vm_state
when :not_created
# Do not use non-existant in-VM proxy to download the basebox
if ENV['http_proxy'] == INTERNEL_HTTP_PROXY
......@@ -223,7 +290,7 @@ namespace :vm do
restore_internal_proxy = true
end
$stderr.puts <<-END_OF_MESSAGE.gsub(/^ /, '')
$stderr.puts <<-END_OF_MESSAGE.gsub(/^ /, '')
This is the first time that the Tails builder virtual machine is
started. The virtual machine template is about 300 MB to download,
......@@ -236,7 +303,7 @@ namespace :vm do
END_OF_MESSAGE
when :poweroff
$stderr.puts <<-END_OF_MESSAGE.gsub(/^ /, '')
$stderr.puts <<-END_OF_MESSAGE.gsub(/^ /, '')
Starting Tails builder virtual machine. This might take a short while.
Please remember to shut it down once your work on Tails is done:
......@@ -244,30 +311,8 @@ namespace :vm do
$ rake vm:halt
END_OF_MESSAGE
when :running
if ENV['TAILS_RAM_BUILD'] && current_vm_memory < VM_MEMORY_FOR_RAM_BUILDS
$stderr.puts <<-END_OF_MESSAGE.gsub(/^ /, '')
The virtual machine is not currently set with enough memory to
perform an in-memory build. Either remove the `ram` option from
the TAILS_BUILD_OPTIONS environment variable, or shut the
virtual machine down using `rake vm:halt` before trying again.
END_OF_MESSAGE
abort 'Not enough memory for the virtual machine to run an in-memory build. Aborting.'
end
if ENV['TAILS_BUILD_CPUS'] && current_vm_cpus != ENV['TAILS_BUILD_CPUS'].to_i
$stderr.puts <<-END_OF_MESSAGE.gsub(/^ /, '')
The virtual machine is currently running with #{current_vm_cpus}
virtual CPU(s). In order to change that number, you need to
stop the VM first, using `rake vm:halt`. Otherwise, please
adjust the `cpus` options accordingly.
END_OF_MESSAGE
abort 'The virtual machine needs to be reloaded to change the number of CPUs. Aborting.'
end
end
env = Vagrant::Environment.new(:cwd => VAGRANT_PATH, :ui_class => Vagrant::UI::Basic)
result = env.cli('up')
abort "'vagrant up' failed" unless result
......@@ -295,45 +340,3 @@ namespace :vm do
abort "'vagrant destroy' failed" unless result
end
end
namespace :basebox do
task :create_preseed_cfg => 'validate_http_proxy' do
require 'erb'
preseed_cfg_path = File.expand_path('../vagrant/definitions/squeeze/preseed.cfg', __FILE__)
template = ERB.new(File.read("#{preseed_cfg_path}.erb"))
File.open(preseed_cfg_path, 'w') do |f|
f.write template.result
end
end
desc 'Create virtual machine template (a.k.a. basebox)'
task :create_basebox => [:create_preseed_cfg] do
# veewee is pretty stupid regarding path handling
Dir.chdir(VAGRANT_PATH) do
require 'veewee'
# Veewee assumes a separate process for each task. So we mimic that.
env = Vagrant::Environment.new(:ui_class => Vagrant::UI::Basic)
Process.fork do
env.cli('basebox', 'build', 'squeeze')
end
Process.wait
abort "Building the basebox failed (exit code: #{$?.exitstatus})." if $?.exitstatus != 0
Process.fork do
env.cli('basebox', 'validate', 'squeeze')
end
Process.wait
abort "Validating the basebox failed (exit code: #{$?.exitstatus})." if $?.exitstatus != 0
Process.fork do
env.cli('basebox', 'export', 'squeeze')
end
Process.wait
abort "Exporting the basebox failed (exit code: #{$?.exitstatus})." if $?.exitstatus != 0
end
end
end
#!/bin/bash
# set -x
set -x
umask 022
### functions
fatal () {
echo "$*" >&2
exit 1
}
syslinux_utils_upstream_version () {
dpkg-query -W -f='${Version}\n' syslinux-utils | \
# drop epoch
sed -e 's,.*:,,' | \
# drop +dfsg and everything that follows
sed -e 's,\+dfsg.*,,'
}
print_iso_size () {
local isofile="$1"
[ -f "$isofile" ] || return 23
size=$(stat --printf='%s' "$isofile")
echo "The ISO is ${size} bytes large."
}
### Main
# we require building from git
if ! git rev-parse --is-inside-work-tree &> /dev/null; then
echo "${PWD} is not a Git tree."
exit 1
fi
git rev-parse --is-inside-work-tree &> /dev/null \
|| fatal "${PWD} is not a Git tree."
. config/amnesia
if [ -e config/amnesia.local ] ; then
......@@ -24,61 +46,107 @@ rm -rf cache/stages_rootfs
# get LB_ARCHITECTURE and LB_DISTRIBUTION
. config/bootstrap
# build the doc wiki
./build-wiki
# refresh translations of our programs
./refresh-translations
# save variables that are needed by chroot_local-hooks
echo "LB_DISTRIBUTION=${LB_DISTRIBUTION}" >> config/chroot_local-includes/usr/share/amnesia/build/variables
echo "AMNESIA_SUPPORTED_LANGUAGES='${AMNESIA_SUPPORTED_LANGUAGES}'" >> config/chroot_local-includes/usr/share/amnesia/build/variables
echo "POTFILES_DOT_IN='$(
/bin/grep -E --no-filename '[^ #]*\.in$' po/POTFILES.in \
| sed -e 's,^config/chroot_local-includes,,' | tr "\n" ' '
)'" \
>> config/chroot_local-includes/usr/share/amnesia/build/variables
# fix permissions on some source files that will be copied as is to the chroot.
# they may be wrong, e.g. if the Git repository was cloned with a strict umask.
chmod -R go+rX config/binary_local-includes/
chmod -R go+rX config/chroot_local-includes/etc
chmod 0440 config/chroot_local-includes/etc/sudoers.d/*
chmod go+rX config/chroot_local-includes/home
chmod go+rX config/chroot_local-includes/lib
chmod go+rX config/chroot_local-includes/lib/live
chmod -R go+rx config/chroot_local-includes/lib/live/config
chmod go+rX config/chroot_local-includes/live
chmod -R go+rX config/chroot_local-includes/usr
chmod -R go+rx config/chroot_local-includes/usr/local/bin
chmod -R go+rx config/chroot_local-includes/usr/local/sbin
chmod -R go+rX config/chroot_local-includes/usr/share/doc/tails
chmod -R go+rX config/chroot_local-includes/var
chmod -R go+rX config/chroot_apt
chmod -R go+rX config/chroot_sources
# build the image
: ${MKSQUASHFS_OPTIONS:='-comp xz'}
: ${MKSQUASHFS_OPTIONS:='-comp xz -Xbcj x86 -b 1024K -Xdict-size 1024K'}
MKSQUASHFS_OPTIONS="${MKSQUASHFS_OPTIONS} -wildcards -ef chroot/usr/share/amnesia/build/mksquashfs-excludes"
export MKSQUASHFS_OPTIONS
# get git branch or tag so we can set the basename appropriately, i.e.:
# * if we build from a tag: tails-$ARCH-$TAG.iso
# * if we build from a branch: tails-$ARCH-$BRANCH-$VERSION-$DATE.iso
# * if Jenkins builds from a branch: tails-$ARCH-$BRANCH-$VERSION-$TIME-$COMMIT.iso
if GIT_REF="$(git symbolic-ref HEAD)"; then
GIT_BRANCH="${GIT_REF#refs/heads/}"
CLEAN_GIT_BRANCH=$(echo "$GIT_BRANCH" | sed 's,/,_,g')
BUILD_BASENAME="tails-${LB_ARCHITECTURE}-${CLEAN_GIT_BRANCH}-${AMNESIA_VERSION}-${AMNESIA_TODAY}"
if [ -n "$JENKINS_URL" ]; then
GIT_SHORT_ID="$(git rev-parse --short HEAD)"
BUILD_BASENAME="tails-${LB_ARCHITECTURE}-${CLEAN_GIT_BRANCH}-${AMNESIA_VERSION}-${AMNESIA_NOW}-${GIT_SHORT_ID}"
else
BUILD_BASENAME="tails-${LB_ARCHITECTURE}-${CLEAN_GIT_BRANCH}-${AMNESIA_VERSION}-${AMNESIA_TODAY}"
fi
else
GIT_CURRENT_COMMIT="$(git rev-parse HEAD)"
if GIT_TAG="$(git describe --tags --exact-match ${GIT_CURRENT_COMMIT})"; then
CLEAN_GIT_TAG=$(echo "$GIT_TAG" | sed 's,/,_,g')
CLEAN_GIT_TAG=$(echo "$GIT_TAG" | tr '/-' '_~')
BUILD_BASENAME="tails-${LB_ARCHITECTURE}-${CLEAN_GIT_TAG}"
else
# this shouldn't reasonably happen (e.g. only if you checkout a
# tag, remove the tag and then build)
echo "Neither a Git branch nor a tag, exiting."
exit 1
fatal "Neither a Git branch nor a tag, exiting."
fi
fi
GIT_BASE_BRANCH=$(head -n1 config/base_branch) \
|| fatal "GIT_BASE_BRANCH could not be guessed."
# Merge base branch into the branch being built, iff. we're building
# in Jenkins, and not building from a tag, and not building the base
# branch itself
if [ -n "$JENKINS_URL" ] && [ -z "$GIT_TAG" ] \
&& [ "$GIT_BRANCH" != "$GIT_BASE_BRANCH" ] ; then
GIT_BASE_BRANCH_COMMIT=$(git rev-parse "origin/${GIT_BASE_BRANCH}") \
|| fatal "Base branch's top commit could not be guessed."
echo "Merging base branch origin/${GIT_BASE_BRANCH}"
echo "(at commit ${GIT_BASE_BRANCH_COMMIT})..."
git merge --no-edit "origin/${GIT_BASE_BRANCH}" \
|| fatal "Failed to merge base branch."
# Adjust BUILD_BASENAME to embed the base branch name and its top commit
CLEAN_GIT_BASE_BRANCH=$(echo "$GIT_BASE_BRANCH" | sed 's,/,_,g')
GIT_BASE_BRANCH_SHORT_ID=$(git rev-parse --short "origin/${GIT_BASE_BRANCH}") \
|| fatal "Base branch's top commit short ID could not be guessed."
BUILD_BASENAME="${BUILD_BASENAME}+${CLEAN_GIT_BASE_BRANCH}"
BUILD_BASENAME="${BUILD_BASENAME}@${GIT_BASE_BRANCH_SHORT_ID}"
fi
# build the doc wiki
./build-wiki
# refresh translations of our programs
./refresh-translations || fatal "refresh-translations failed ($?)."
case "$LB_BINARY_IMAGES" in
iso)
BUILD_FILENAME_EXT=iso
BUILD_FILENAME=binary
which isohybrid >/dev/null || fatal 'Cannot find isohybrid in $PATH'
installed_syslinux_utils_upstream_version="$(syslinux_utils_upstream_version)"
if dpkg --compare-versions \
"$installed_syslinux_utils_upstream_version" \
'lt' \
"$REQUIRED_SYSLINUX_UTILS_UPSTREAM_VERSION" ; then
fatal \
"syslinux-utils '${installed_syslinux_utils_upstream_version}' is installed, " \
"while we need at least '${REQUIRED_SYSLINUX_UTILS_UPSTREAM_VERSION}'."
fi
;;
iso-hybrid)
BUILD_FILENAME_EXT=iso
......@@ -93,23 +161,46 @@ case "$LB_BINARY_IMAGES" in
BUILD_FILENAME=binary
;;
*)
echo "Image type ${LB_BINARY_IMAGES} is not supported." >&2
exit 1
fatal "Image type ${LB_BINARY_IMAGES} is not supported."
;;
esac
BUILD_DEST_FILENAME="${BUILD_BASENAME}.${BUILD_FILENAME_EXT}"
BUILD_MANIFEST="${BUILD_DEST_FILENAME}.list"
BUILD_PACKAGES="${BUILD_DEST_FILENAME}.packages"
BUILD_LOG="${BUILD_DEST_FILENAME}.buildlog"
BUILD_START_FILENAME="${BUILD_DEST_FILENAME}.start.timestamp"
BUILD_END_FILENAME="${BUILD_DEST_FILENAME}.end.timestamp"
# Clone all output, from this point on, to the log file
exec > >(tee -a "$BUILD_LOG")
trap "kill -9 $! 2>/dev/null" EXIT HUP INT QUIT TERM
exec 2> >(tee -a "$BUILD_LOG" >&2)
trap "kill -9 $! 2>/dev/null" EXIT HUP INT QUIT TERM
echo "Building $LB_BINARY_IMAGES image ${BUILD_BASENAME}..."
set -o pipefail
if time eatmydata lb build noauto ${@} 2>&1 | tee "${BUILD_LOG}" ; then
echo "Image was successfully created"
[ -z "$JENKINS_URL" ] || date --utc '+%s' > "$BUILD_START_FILENAME"
time eatmydata lb build noauto ${@}
RET=$?
if [ -e "${BUILD_FILENAME}.${BUILD_FILENAME_EXT}" ]; then
if [ "$RET" -eq 0 ]; then
[ -z "$JENKINS_URL" ] || date --utc '+%s' > "$BUILD_END_FILENAME"
echo "Image was successfully created"
if [ "$LB_BINARY_IMAGES" = iso ]; then
ISO_FILE="${BUILD_FILENAME}.${BUILD_FILENAME_EXT}"
print_iso_size "$ISO_FILE"
echo "Hybriding it..."
isohybrid $AMNESIA_ISOHYBRID_OPTS "$ISO_FILE"
print_iso_size "$ISO_FILE"
truncate -s %2048 "$ISO_FILE"
print_iso_size "$ISO_FILE"
fi
else
echo "Warning: image created, but lb build exited with code $RET"
fi
echo "Renaming generated files..."
mv -i "${BUILD_FILENAME}.${BUILD_FILENAME_EXT}" "${BUILD_DEST_FILENAME}"
mv -i binary.packages "${BUILD_PACKAGES}"
else
echo "lb build failed." >&2
exit 1
fatal "lb build failed ($?)."
fi
#!/bin/sh
set -x
for dir in chroot/{dev/pts,proc,sys,var/lib/dpkg} ; do
if mountpoint -q "$dir" ; then
umount "$dir"
......
#! /bin/sh
# automatically run by "lb config"
set -x
# we require building from git
if ! git rev-parse --is-inside-work-tree; then
echo "${PWD} is not a Git tree. Exiting."
......@@ -12,16 +14,18 @@ if [ -e config/amnesia.local ] ; then
. config/amnesia.local
fi
export LB_BOOTSTRAP_INCLUDE='eatmydata'
# init variables
RUN_LB_CONFIG="lb config noauto"
# init config/ with defaults for the target distribution
$RUN_LB_CONFIG --distribution squeeze ${@}
$RUN_LB_CONFIG --distribution wheezy ${@}
# set Amnesia's general options
$RUN_LB_CONFIG \
--apt-recommends false \
--backports true \
--backports false \
--binary-images iso \
--binary-indices false \
--checksums none \
......@@ -33,9 +37,12 @@ $RUN_LB_CONFIG \
--iso-publisher="https://tails.boum.org/" \
--iso-volume="TAILS ${AMNESIA_FULL_VERSION}" \
--memtest none \
--mirror-binary "http://ftp.us.debian.org/debian/" \
--mirror-bootstrap "http://ftp.us.debian.org/debian/" \
--mirror-chroot "http://ftp.us.debian.org/debian/" \
--packages-lists="standard" \
--tasks="standard" \
--linux-packages="linux-image-3.2.0-4" \
--linux-packages="linux-image-3.16.0-4" \
--syslinux-menu vesamenu \
--syslinux-splash data/splash.png \
--syslinux-timeout 4 \
......@@ -47,7 +54,7 @@ hw_arch="`dpkg --print-architecture`"
if [ "$hw_arch" = i386 -o "$hw_arch" = amd64 ]; then
$RUN_LB_CONFIG \
--architecture i386 \
--linux-flavours "486 686-pae" \
--linux-flavours "586 amd64" \
${@}
# build powerpc images on powerpc64 as well, include only powerpc kernel
elif [ "$hw_arch" = powerpc -o "$hw_arch" = powerpc64 ]; then
......
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use 5.10.1;
use autodie;
use Carp::Assert;
use Carp::Assert::More;
use IO::All;
use List::MoreUtils qw{uniq};
my $usage = "Usage: $0 ACNG_LOG IP EPOCH_START EPOCH_END [OUTPUT_BIN_PKGS OUTPUT_SRC_PKGS]";
my $logline_re = qr{
\A
(\d+) [|]
([^|]+) [|]
(\d+) [|]
([^|]+) [|]
([^\n]+)
\z
}xms;
### Subs
sub logline_timestamp_is_between {
my $logline = shift;
my $epoch_start = shift;
my $epoch_end = shift;
if (my ($timestamp) = ($logline =~ m{\A (\d+) [|]}xms)) {
return $timestamp >= $epoch_start && $timestamp <= $epoch_end;
}
return;
}
sub logline_is_from_ip {
my $logline = shift;
my $client_ip = shift;
if (my ($time, $whatever, $size, $ip, $url) = ($logline =~ m{$logline_re}xms)) {
return $ip eq $client_ip;