Skip to content

Commit

Permalink
passes the system architecture as an environment variable to the inst…
Browse files Browse the repository at this point in the history
…aller functions
  • Loading branch information
nyoungstudios committed Sep 17, 2022
1 parent 34338a3 commit 696a0e8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions bin/alfa.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ void main(List<String> args) async {
// gets environment variables
String user = Platform.environment['SUDO_USER'];
String alfaUser = Platform.environment['ALFA_USER'];
String alfaArch = Platform.environment['ALFA_ARCH'];
if (user == 'root' && alfaUser != '') {
user = alfaUser;
}

// gets operating system
// valid options (linux, macos)
var osName = Platform.operatingSystem;
print("Running alfa on ${osName}");
print("Running alfa on ${osName} ${alfaArch}");

// loads config file which maps the install keys to the tags
var configFile = await TomlDocument.load(argResults['config']);
Expand Down Expand Up @@ -189,7 +190,7 @@ void main(List<String> args) async {
arguments = ['-u', user];
}

arguments.addAll(['--preserve-env=ALFA_USER', '--', '/bin/bash']);
arguments.addAll(['--preserve-env=ALFA_USER,ALFA_ARCH', '--', '/bin/bash']);
}

arguments.addAll(['-euc', command]);
Expand Down
5 changes: 3 additions & 2 deletions functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# rather "install_brew".
# To access the list of "options" in the config.toml file you pass to the installer, use the "$@" variable.
# To access the user that called the installer, do not user the environment variable "$SUDO_USER", but rather use "$ALFA_USER".
# To access the uname -m output (system architecture), you can use the environment variable "$ALFA_ARCH"

create_git_config() {
# sets up git config name and email
Expand Down Expand Up @@ -217,14 +218,14 @@ install_anaconda3_common() {
install_anaconda3_macos() {
# installs anaconda3
echo "Installing Anaconda3..."
curl "${1:-https://repo.anaconda.com/archive/Anaconda3-2022.05-MacOSX-x86_64.sh}" -o ~/anaconda3.sh
curl "${1:-https://repo.anaconda.com/archive/Anaconda3-2022.05-MacOSX-${ALFA_ARCH}.sh}" -o ~/anaconda3.sh
install_anaconda3_common
}

install_anaconda3_linux() {
# installs anaconda3
echo "Installing Anaconda3..."
curl "${1:-https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh}" -o ~/anaconda3.sh
curl "${1:-https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-${ALFA_ARCH}.sh}" -o ~/anaconda3.sh
install_anaconda3_common
}

Expand Down
4 changes: 3 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ else
exit 1
fi

export ALFA_ARCH="$unameMachine"

# runs the alfa command depending upon if sudo exists
if ! command -v "sudo" > /dev/null 2>&1; then
# sudo command doesn't exist
Expand All @@ -39,7 +41,7 @@ else
while :; do sudo -v; sleep 59; done &
loopPid="$!"

export ALFA_USER="${SUDO_USER:-${USER:-}}"; sudo --preserve-env=ALFA_USER ./$alfaCommand "$@"
export ALFA_USER="${SUDO_USER:-${USER:-}}"; sudo --preserve-env=ALFA_USER,ALFA_ARCH ./$alfaCommand "$@"

trap 'trap - SIGTERM && kill $(pgrep -P $loopPid) $loopPid' SIGINT SIGTERM EXIT

Expand Down

0 comments on commit 696a0e8

Please sign in to comment.