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

[WIP] cortex #42

Open
wants to merge 1 commit 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
4 changes: 3 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ let

inherit (unstable.pkgs) callPackage;

cortex = callPackage ./pkgs/cortex { inherit (unstable); };

dart = callPackage ./pkgs/dart { inherit unstable; };

flutter = callPackage ./pkgs/flutter { inherit (final.nubank) dart; };
Expand All @@ -30,7 +32,7 @@ in
{
nubank = {
# Custom packages
inherit dart flutter flutter-patch hover nodejs yarn leiningen;
inherit cortex dart flutter flutter-patch hover nodejs yarn leiningen;

# Meta packages
all-tools = with final.nubank; cli-tools ++ clojure-tools ++ jupyter-tools;
Expand Down
8 changes: 8 additions & 0 deletions pkgs/cortex/builder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

source $stdenv/setup
PATH=$dpkg/bin:$PATH

dpkg -x $src unpacked

cp -r unpacked/* $out/
53 changes: 53 additions & 0 deletions pkgs/cortex/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
buildFHSUserEnv,
stdenv,
fetchurl,
makeWrapper,
lib,
pkgs
}:

let

cortex = stdenv.mkDerivation rec {
pname = "cortex";
rev = "123";
version = "2021.2.1";

src = ../../../ansible-pull/common/files/nubank-global-install-linux-762.deb;

nativeBuildInputs = [ makeWrapper ];
buildInputs = with pkgs; [ dpkg getopt openssl ];

unpackPhase = "dpkg-deb -x ${src} ./";

patches = [
./fix-setup.patch
];

installPhase = ''
mkdir -p $out/bin
mkdir -p $out/log
mkdir -p $out/share

patchShebangs ./opt/traps/deb-installer/setup.sh
for file in ./opt/traps/deb-installer/setup.d/*; do
chmod +w $file
patchShebangs $file
# patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
# --set-rpath ${lib.makeLibraryPath [ pkgs.stdenv.cc.cc ]} \
# $file
done

cd ./opt/traps/deb-installer
./setup.sh
'';

dontPatchELF = true;
};
in buildFHSUserEnv {
name = cortex.name;
targetPkgs = pkgs: [ cortex ];

runScript = "cortex";
}
81 changes: 81 additions & 0 deletions pkgs/cortex/fix-setup.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
diff --git a/opt/traps/deb-installer/setup.d/log_redirect.sh b/opt/traps/deb-installer/setup.d/log_redirect.sh
index e671769..c3c1e43 100644
--- a/opt/traps/deb-installer/setup.d/log_redirect.sh
+++ b/opt/traps/deb-installer/setup.d/log_redirect.sh
@@ -4,7 +4,7 @@

set -u

-declare -r install_log_default="/var/log/traps-install.log"
+declare -r install_log_default="$out/log/traps-install.log"
declare install_log="${TRAPS_INSTALL_LOG-$install_log_default}"

setup_installer_log() {
diff --git a/opt/traps/deb-installer/setup.d/pre-install.sh b/opt/traps/deb-installer/setup.d/pre-install.sh
index c87160f..00c6526 100644
--- a/opt/traps/deb-installer/setup.d/pre-install.sh
+++ b/opt/traps/deb-installer/setup.d/pre-install.sh
@@ -261,11 +261,6 @@ _verify_required_libraries() {
pre_install() {
declare -r should_verify_requirements="$1"

- if [[ "$EUID" -ne 0 ]]; then
- echo "Please run Cortex XDR installer as root"
- return 1
- fi
-
if ! _check_64bit; then
echo "Unsupported architecture: $(uname -m), expected x86_64"
return 1
@@ -279,7 +274,7 @@ pre_install() {
if $should_verify_requirements; then
step_start "Checking prerequisites"

- _verify_required_libraries
+ # _verify_required_libraries
if [[ "$?" -ne 0 ]]; then
echo "Prerequisites not met. Please install missing packages"
return 1
diff --git a/opt/traps/deb-installer/setup.sh b/opt/traps/deb-installer/setup.sh
index 30663f9..b3db5a7 100755
--- a/opt/traps/deb-installer/setup.sh
+++ b/opt/traps/deb-installer/setup.sh
@@ -72,8 +72,6 @@ vet_path() {
export PATH="$(IFS=":"; echo "${path_final[*]}")"
}

-vet_path
-
unalias -a

source "./setup.d/log_redirect.sh"
@@ -249,6 +247,8 @@ _do_upgrade() {
_unpack_installation() {
umask 0177

+ chmod 755 "$deploy_dir"
+
tar --warning=no-timestamp -xzf "$agent_full_version.tar.gz" -C "$deploy_dir/"
if [[ $? -ne 0 ]]; then
rm -rf "$deploy_dir/"
@@ -305,11 +305,6 @@ _cleanup() {
}

main() {
- if [[ "$EUID" -ne 0 ]]; then
- echo "Please run Cortex XDR installer as root"
- return 1
- fi
-
setup_installer_log "Install"

declare -r agent_full_version="$(cat ".version" | sed -e 's/-dbg$//')"
@@ -321,7 +316,7 @@ main() {
return 1
fi

- declare -r deploy_dir="/opt/traps"
+ declare -r deploy_dir="$out/bin"
declare -r config_dir="$deploy_dir/config"

declare -r uninstall_script="$deploy_dir/scripts/uninstall.sh"
11 changes: 6 additions & 5 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ with pkgs;
pkgs.mkShell {
buildInputs = [
# You can comment some derivations here to test only one package
nubank.dart
nubank.flutter
nubank.flutter-patch
nubank.hover
] ++ nubank.all-tools;
# nubank.dart
# nubank.flutter
# nubank.flutter-patch
# nubank.hover
nubank.cortex
]; #++ nubank.all-tools;
}