Skip to content

Commit

Permalink
scripts: if DOTFILES path env exists, make sure we are in it
Browse files Browse the repository at this point in the history
  • Loading branch information
chadsr committed Apr 16, 2024
1 parent 987b6b4 commit 1921ac8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
20 changes: 15 additions & 5 deletions setup_all.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/usr/bin/env bash

base_path=$PWD
data_path="$base_path"/data
system_config_path="$base_path"/system
git_submodule_path="$base_path"/.git_submodules

gpg_primary_key=0x2B7340DB13C85766
gpg_encryption_subkey=0x79C70BBE4865D828

Expand Down Expand Up @@ -50,6 +45,15 @@ prompt_exit() {
esac
}

update_paths() {
base_path=$PWD
data_path="$base_path"/data
system_config_path="$base_path"/system
git_submodule_path="$base_path"/.git_submodules
}

update_paths

if [[ "$current_hostname" != "$laptop_hostname" ]] && [[ "$current_hostname" != "$desktop_hostname" ]]; then
if [[ "$1" != "$laptop_hostname" ]] && [[ "$1" != "$desktop_hostname" ]]; then
echo "Unrecognised hostname! Please provide a valid one."
Expand All @@ -65,6 +69,12 @@ fi

prompt_exit "This script will remove/change existing system settings."

if [[ -n ${DOTFILES+x} ]] && [[ "$base_path" != "$DOTFILES" ]]; then
echo "Changing directory to '${DOTFILES}'"
cd "$DOTFILES"
update_paths
fi

install_packages() {
"$package_manager" -S --noconfirm --needed --noredownload -- "${@}" || {
echo "failed to install:"
Expand Down
15 changes: 13 additions & 2 deletions store_secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
gpg_primary_key=0x2B7340DB13C85766
gpg_encryption_subkey=0x79C70BBE4865D828

base_path=$PWD
data_path="$base_path"/data
pkglist_system_path=/etc/pkglist.txt

laptop_hostname="thinky"
Expand All @@ -22,7 +20,14 @@ exit_script() {
set -euo pipefail
trap 'exit_script' ERR INT

update_paths() {
base_path=$PWD
data_path="$base_path"/data
}

script_name=$(basename "$0")
update_paths

help() {
printf "Stores configuration secrets to \"%s\".\n\nUsage: %s <%s|%s>\n" "$data_path" "$script_name" "$laptop_hostname" "$desktop_hostname"
}
Expand Down Expand Up @@ -105,6 +110,12 @@ else
echo "Using current hostname \"${current_hostname}\" for configuration."
fi

if [[ -n ${DOTFILES+x} ]] && [[ "$base_path" != "$DOTFILES" ]]; then
echo "Changing directory to '${DOTFILES}'"
cd "$DOTFILES"
update_paths
fi

if [[ ! $(gpg --list-keys "$gpg_primary_key") ]]; then
gpg --import "$data_path"/gpg/2B7340DB13C85766.asc
fi
Expand Down

0 comments on commit 1921ac8

Please sign in to comment.