From 6b7a9ed3e5ef6b25ccfdcd53ced5f8f71f7b405d Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Sun, 16 Apr 2023 21:28:58 +0100 Subject: [PATCH] tests(packer): add source files for tests VM images. --- tests/packer/src/.bash_aliases | 25 +++++++++++++++++++ tests/packer/src/aa-update | 13 ++++++++++ tests/packer/src/htoprc | 44 ++++++++++++++++++++++++++++++++++ tests/packer/src/init.sh | 29 ++++++++++++++++++++++ tests/packer/src/parser.conf | 4 ++++ tests/packer/src/site.local | 3 +++ 6 files changed, 118 insertions(+) create mode 100644 tests/packer/src/.bash_aliases create mode 100644 tests/packer/src/aa-update create mode 100644 tests/packer/src/htoprc create mode 100644 tests/packer/src/init.sh create mode 100644 tests/packer/src/parser.conf create mode 100644 tests/packer/src/site.local diff --git a/tests/packer/src/.bash_aliases b/tests/packer/src/.bash_aliases new file mode 100644 index 000000000..27e05bf80 --- /dev/null +++ b/tests/packer/src/.bash_aliases @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +source /usr/share/bash-completion/bash_completion + +function up() { +for nb in $(seq "$1"); do + cd ../ +done +} + +alias sudo='sudo -E' +alias aa-log='sudo aa-log' +alias aa-status='sudo aa-status' +alias c='clear' +alias du='du -hs' +alias l='ll -h' +alias ll='ls -alFh' +alias p="ps auxZ | grep -v '\[.*\]'" +alias pf="ps auxfZ | grep -v '\[.*\]'" +alias pu="ps auxZ | grep -v '\[.*\]' | grep unconfined" +alias u='up 1' +alias uu='up 2' +alias uuu='up 3' +alias uuuu='up 4' +alias uuuuu='up 5' \ No newline at end of file diff --git a/tests/packer/src/aa-update b/tests/packer/src/aa-update new file mode 100644 index 000000000..d082827ee --- /dev/null +++ b/tests/packer/src/aa-update @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -eu +export BUILDDIR=/tmp/build/ PKGDEST=/tmp/pkg +# shellcheck source=/dev/null +_lsb_release() { . /etc/os-release || exit 1; echo "$ID"; } +DISTRIBUTION="$(_lsb_release)" +cd "$HOME/Projects/apparmor.d" +case "$DISTRIBUTION" in +arch) make pkg ;; +debian | ubuntu | whonix) make dpkg ;; +opensuse-tumbleweed) make rpm ;; +*) ;; +esac \ No newline at end of file diff --git a/tests/packer/src/htoprc b/tests/packer/src/htoprc new file mode 100644 index 000000000..26dbd1352 --- /dev/null +++ b/tests/packer/src/htoprc @@ -0,0 +1,44 @@ +# Beware! This file is rewritten by htop when settings are changed in the interface. +# The parser is also very primitive, and not human-friendly. +htop_version=3.1.2 +config_reader_min_version=2 +fields=0 48 17 18 38 39 40 2 46 47 49 122 1 +sort_key=0 +sort_direction=1 +tree_sort_key=0 +tree_sort_direction=1 +hide_kernel_threads=1 +hide_userland_threads=1 +shadow_other_users=0 +show_thread_names=0 +show_program_path=1 +highlight_base_name=1 +highlight_deleted_exe=1 +highlight_megabytes=1 +highlight_threads=1 +highlight_changes=0 +highlight_changes_delay_secs=5 +find_comm_in_cmdline=1 +strip_exe_from_cmdline=1 +show_merged_command=0 +tree_view=0 +tree_view_always_by_pid=0 +all_branches_collapsed=0 +header_margin=1 +detailed_cpu_time=1 +cpu_count_from_one=1 +show_cpu_usage=1 +show_cpu_frequency=1 +show_cpu_temperature=1 +degree_fahrenheit=0 +update_process_names=0 +account_guest_in_cpu_meter=0 +color_scheme=6 +enable_mouse=1 +delay=15 +hide_function_bar=1 +header_layout=two_50_50 +column_meters_0=LeftCPUs Memory Swap +column_meter_modes_0=1 1 1 +column_meters_1=RightCPUs Tasks LoadAverage Uptime +column_meter_modes_1=1 2 2 2 diff --git a/tests/packer/src/init.sh b/tests/packer/src/init.sh new file mode 100644 index 000000000..f9de2cd97 --- /dev/null +++ b/tests/packer/src/init.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2023 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +set -eu + +# shellcheck source=/dev/null +_lsb_release() { . /etc/os-release; echo "$ID"; } +DISTRIBUTION="$(_lsb_release)" +readonly SRC=/tmp/src +readonly DISTRIBUTION + +main() { + install -dm0750 -o "$SUDO_USER" -g "$SUDO_USER" "/home/$SUDO_USER/Projects/" "/home/$SUDO_USER/.config/" + install -Dm0644 -o "$SUDO_USER" -g "$SUDO_USER" $SRC/.bash_aliases "/home/$SUDO_USER/.bash_aliases" + install -Dm0644 -o "$SUDO_USER" -g "$SUDO_USER" $SRC/htoprc "/home/$SUDO_USER/.config/htop/htoprc" + install -Dm0644 $SRC/parser.conf /etc/apparmor/parser.conf + install -Dm0644 $SRC/site.local /etc/apparmor.d/tunables/etc.d/site.local + install -Dm0755 $SRC/aa-update /usr/bin/aa-update + chown -R "$SUDO_USER:$SUDO_USER" "/home/$SUDO_USER/.config/" + case "$DISTRIBUTION" in + debian | ubuntu) dpkg -i $SRC/apparmor.d_*_all.deb ;; + opensuse*) zypper install -y bash-completion git go htop lsb-release make rsync vim ;; + arch) pacman --noconfirm -U $SRC/apparmor.d-*-x86_64.pkg.tar.zst ;; + esac +} + +main "$@" diff --git a/tests/packer/src/parser.conf b/tests/packer/src/parser.conf new file mode 100644 index 000000000..be8c42560 --- /dev/null +++ b/tests/packer/src/parser.conf @@ -0,0 +1,4 @@ + +write-cache +cache-loc /etc/apparmor/earlypolicy/ +Optimize=compress-fast diff --git a/tests/packer/src/site.local b/tests/packer/src/site.local new file mode 100644 index 000000000..e15435862 --- /dev/null +++ b/tests/packer/src/site.local @@ -0,0 +1,3 @@ + +@{user_build_dirs}+=@{user_projects_dirs} +@{user_pkg_dirs}+=@{user_projects_dirs}