Skip to content

Commit

Permalink
feat: add function to move files to bin folder
Browse files Browse the repository at this point in the history
I've added the move_to_bin_folder function in install.sh.
This function moves a file to the specified destination.
If the destination is not writable, it uses sudo to move the file.
I updated the install_kubectl, install_kind, and install_scaf functions to use the new function.
  • Loading branch information
gfranxman committed Aug 14, 2024
1 parent 2c51e49 commit 0e438dc
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ detect_os_and_arch() {
echo $os_arch
}

move_to_bin_folder() {
DEST=${2:-$PREFERRED_BIN_FOLDER}
echo "Moving $1 to ${DEST}..."
# if the DEST folder is not writable, use sudo to move the file
if [ -w $DEST ]; then
mv $1 $DEST/$1
else
sudo mv $1 $DEST/$1
fi
}

install_kubectl() {
echo "Installing kubectl..."
os_arch=$(detect_os_and_arch)
Expand All @@ -179,7 +190,7 @@ install_kubectl() {
url="https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/${os}/${arch}/kubectl"
curl -LO $url
chmod +x ./kubectl
sudo mv ./kubectl $PREFERRED_BIN_FOLDER/kubectl
move_to_bin_folder ./kubectl
;;
*)
echo "Unsupported OS or architecture: $os_arch"
Expand All @@ -197,7 +208,7 @@ install_kind() {
"linux-amd64"|"darwin-amd64"|"darwin-arm64"|"linux-arm64"|"windows-amd64")
curl -Lo ./kind "https://kind.sigs.k8s.io/dl/v0.23.0/kind-$os_arch"
chmod +x ./kind
sudo mv ./kind $PREFERRED_BIN_FOLDER/kind
move_to_bin_folder ./kind
;;
*)
echo "Unsupported OS or architecture: $os_arch"
Expand All @@ -221,7 +232,7 @@ install_scaf() {
if [ -f "$TEMP_DOWNLOAD" ]; then
chmod +x $TEMP_DOWNLOAD
echo "Moving scaf to $DESTINATION..."
sudo mv $TEMP_DOWNLOAD $DESTINATION
move_to_bin_folder $TEMP_DOWNLOAD $DESTINATION
if [ -f "$DESTINATION" ]; then
echo "scaf installed successfully at $DESTINATION"
else
Expand Down

0 comments on commit 0e438dc

Please sign in to comment.