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

updated/fixed hauler directory #354

Merged
merged 10 commits into from
Nov 15, 2024
5 changes: 3 additions & 2 deletions cmd/hauler/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ var ro = &flags.CliRootOpts{}

func New() *cobra.Command {
cmd := &cobra.Command{
Use: "hauler",
Short: "Airgap Swiss Army Knife",
Use: "hauler",
Short: "Airgap Swiss Army Knife",
Example: " View the Docs: https://docs.hauler.dev\n Environment Variables: HAULER_HOME | HAULER_TEMP",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
l := log.FromContext(cmd.Context())
l.SetLevel(ro.LogLevel)
Expand Down
12 changes: 8 additions & 4 deletions cmd/hauler/cli/store/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,21 @@ func LoadCmd(ctx context.Context, o *flags.LoadOpts, archiveRefs ...string) erro

// unarchiveLayoutTo accepts an archived oci layout and extracts the contents to an existing oci layout, preserving the index
func unarchiveLayoutTo(ctx context.Context, archivePath string, dest string, tempOverride string) error {
tmpdir, err := os.MkdirTemp(tempOverride, "hauler")
if tempOverride == "" {
tempOverride = os.Getenv("HAULER_TEMP")
}

tempDir, err := os.MkdirTemp(tempOverride, "hauler")
if err != nil {
return err
}
defer os.RemoveAll(tmpdir)
defer os.RemoveAll(tempDir)

if err := archiver.Unarchive(archivePath, tmpdir); err != nil {
if err := archiver.Unarchive(archivePath, tempDir); err != nil {
return err
}

s, err := store.NewLayout(tmpdir)
s, err := store.NewLayout(tempDir)
if err != nil {
return err
}
Expand Down
36 changes: 22 additions & 14 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
# - curl -sfL https://get.hauler.dev | HAULER_INSTALL_DIR=/usr/local/bin bash
# - HAULER_INSTALL_DIR=/usr/local/bin ./install.sh
#
# Set Hauler Directory
# - curl -sfL https://get.hauler.dev | HAULER_HOME=$HOME/.hauler bash
# - HAULER_HOME=$HOME/.hauler ./install.sh
#
# Debug Usage:
# - curl -sfL https://get.hauler.dev | HAULER_DEBUG=true bash
# - HAULER_DEBUG=true ./install.sh
Expand Down Expand Up @@ -65,7 +69,7 @@ done
# set install directory from argument or environment variable
HAULER_INSTALL_DIR=${HAULER_INSTALL_DIR:-/usr/local/bin}

# ensure install directory exists
# ensure install directory exists and/or create it
if [ ! -d "${HAULER_INSTALL_DIR}" ]; then
mkdir -p "${HAULER_INSTALL_DIR}" || fatal "Failed to Create Install Directory: ${HAULER_INSTALL_DIR}"
fi
Expand All @@ -82,8 +86,8 @@ if [ "${HAULER_UNINSTALL}" = "true" ]; then
# remove the hauler binary
rm -rf "${HAULER_INSTALL_DIR}/hauler" || fatal "Failed to Remove Hauler from ${HAULER_INSTALL_DIR}"

# remove the working directory
rm -rf "$HOME/.hauler" || fatal "Failed to Remove Hauler Directory: $HOME/.hauler"
# remove the hauler directory
rm -rf "${HAULER_HOME}" || fatal "Failed to Remove Hauler Directory: ${HAULER_HOME}"

info "Successfully Uninstalled Hauler" && echo
exit 0
Expand All @@ -110,7 +114,7 @@ case $PLATFORM in
PLATFORM="darwin"
;;
*)
fatal "Unsupported Platform: $PLATFORM"
fatal "Unsupported Platform: ${PLATFORM}"
;;
esac

Expand All @@ -124,29 +128,33 @@ case $ARCH in
ARCH="arm64"
;;
*)
fatal "Unsupported Architecture: $ARCH"
fatal "Unsupported Architecture: ${ARCH}"
;;
esac

# set hauler directory from argument or environment variable
HAULER_HOME=${HAULER_HOME:-$HOME/.hauler}

# start hauler installation
info "Starting Installation..."

# display the version, platform, and architecture
verbose "- Version: v${HAULER_VERSION}"
verbose "- Platform: $PLATFORM"
verbose "- Architecture: $ARCH"
verbose "- Platform: ${PLATFORM}"
verbose "- Architecture: ${ARCH}"
verbose "- Install Directory: ${HAULER_INSTALL_DIR}"
verbose "- Hauler Directory: ${HAULER_HOME}"

# check working directory and/or create it
if [ ! -d "$HOME/.hauler" ]; then
mkdir -p "$HOME/.hauler" || fatal "Failed to Create Directory: $HOME/.hauler"
# ensure hauler directory exists and/or create it
zackbradys marked this conversation as resolved.
Show resolved Hide resolved
if [ ! -d "${HAULER_HOME}" ]; then
mkdir -p "${HAULER_HOME}" || fatal "Failed to Create Hauler Directory: ${HAULER_HOME}"
fi

# update permissions of working directory
chmod -R 777 "$HOME/.hauler" || fatal "Failed to Update Permissions of Directory: $HOME/.hauler"
# ensure hauler directory is writable (by user or root privileges)
chmod -R 777 "${HAULER_HOME}" || fatal "Failed to Update Permissions of Hauler Directory: ${HAULER_HOME}"

# change to working directory
cd "$HOME/.hauler" || fatal "Failed to Change Directory: $HOME/.hauler"
# change to hauler directory
cd "${HAULER_HOME}" || fatal "Failed to Change Directory to Hauler Directory: ${HAULER_HOME}"

# start hauler artifacts download
info "Starting Download..."
Expand Down
6 changes: 3 additions & 3 deletions pkg/content/chart/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
)

func TestNewChart(t *testing.T) {
tmpdir, err := os.MkdirTemp("", "hauler")
tempDir, err := os.MkdirTemp("", "hauler")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
defer os.RemoveAll(tempDir)

type args struct {
name string
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestNewChart(t *testing.T) {
// {
// name: "should create from a chart directory",
// args: args{
// path: filepath.Join(tmpdir, "podinfo"),
// path: filepath.Join(tempDir, "podinfo"),
// },
// want: want,
// wantErr: false,
Expand Down
5 changes: 4 additions & 1 deletion pkg/cosign/cosign.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ func getCosignPath() (string, error) {
homeDir := currentUser.HomeDir

// Construct the path to the .hauler directory
haulerDir := filepath.Join(homeDir, ".hauler")
haulerDir := os.Getenv("HAULER_HOME")
if haulerDir == "" {
haulerDir = filepath.Join(homeDir, ".hauler")
}

// Create the .hauler directory if it doesn't exist
if _, err := os.Stat(haulerDir); os.IsNotExist(err) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ func TestLayout_AddOCI(t *testing.T) {
}

func setup(t *testing.T) func() error {
tmpdir, err := os.MkdirTemp("", "hauler")
tempDir, err := os.MkdirTemp("", "hauler")
if err != nil {
t.Fatal(err)
}
root = tmpdir
root = tempDir

ctx = context.Background()

return func() error {
os.RemoveAll(tmpdir)
os.RemoveAll(tempDir)
return nil
}
}
Expand Down
Loading