Skip to content

Commit

Permalink
Merge pull request #176 from daytonaio/set-binary-install-path
Browse files Browse the repository at this point in the history
chore: enable to set binary install path
  • Loading branch information
zzorica authored Mar 12, 2024
2 parents be12a70 + a5b5552 commit daed9ed
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 66 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ To install Daytona all you need to do is execute this script:


```bash
# Install Daytona into ~/bin or ~/.local/bin
curl -sf -L https://download.daytona.io/daytona/get-server.sh | bash
# Install Daytona into /usr/local/bin
curl -sf -L https://download.daytona.io/daytona/get-server.sh | sudo bash

# OR if you want to install Daytona to /usr/loca/bin or /opt/bin
# curl -sf -L https://download.daytona.io/daytona/get-server.sh | sudo bash
# OR if you want to install Daytona to some other path where you don`t need sudo
# curl -sf -L https://download.daytona.io/daytona/get-server.sh | DAYTONA_PATH=/home/user/bin bash

# Start Daytona server
daytona server
Expand Down Expand Up @@ -228,4 +228,3 @@ This project has adapted the Code of Conduct from the [Contributor Covenant](htt

For more information on how to use and develop Daytona, talk to us on
[Slack](https://join.slack.com/t/daytonacommunity/shared_invite/zt-273yohksh-Q5YSB5V7tnQzX2RoTARr7Q).

119 changes: 58 additions & 61 deletions hack/get-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,90 +3,78 @@
# This script downloads the Daytona server binary and installs it to /usr/local/bin
# You can set the environment variable DAYTONA_SERVER_VERSION to specify the version to download
# You can set the environment variable DAYTONA_SERVER_DOWNLOAD_URL to specify the base URL to download from
# You can set the environment variable DAYTONA_PATH to specify the path where to install the binary

VERSION=${DAYTONA_SERVER_VERSION:-"latest"}
BASE_URL=${DAYTONA_SERVER_DOWNLOAD_URL:-"https://download.daytona.io/daytona"}
DESTINATION=""
SUDO_REQUIRED=0
DESTINATION=${DAYTONA_PATH:-"/usr/local/bin"}

# Print error message to stderr and exit
err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
exit 1
}

# Check if there is a directory in $PATH that we can write to. With this
# statement the first match from top to bottom will be used.
# shellcheck disable=SC2088
case :$PATH: in
*:$HOME/bin:*)
DESTINATION="$HOME/bin"
SUDO_REQUIRED=0
;;
*:$HOME/.local/bin:*)
DESTINATION="$HOME/.local/bin"
SUDO_REQUIRED=0
;;
*:/usr/local/bin:*)
DESTINATION="/usr/local/bin"
SUDO_REQUIRED=1
;;
*:/opt/bin:*)
DESTINATION="/opt/bin"
SUDO_REQUIRED=1
;;
*) err "~/bin, ~/.local/bin, /opt/bin and /usr/local/bin not on PATH. No option to install to.";;
esac

# Check machine architecture
ARCH=$(uname -m)
# Check operating system
OS=$(uname -s)

case $OS in
"Darwin")
FILENAME="darwin"
;;
"Linux")
FILENAME="linux"
;;
*)
err "Unsupported operating system: $OS"
;;
"Darwin")
FILENAME="darwin"
;;
"Linux")
FILENAME="linux"
;;
*)
err "Unsupported operating system: $OS"
;;
esac

case $ARCH in
"arm64" | "ARM64")
FILENAME="$FILENAME-arm64"
;;
"x86_64" | "AMD64")
FILENAME="$FILENAME-amd64"
;;
"aarch64")
FILENAME="$FILENAME-arm64"
;;
*)
err "Unsupported architecture: $ARCH"
;;
"arm64" | "ARM64")
FILENAME="$FILENAME-arm64"
;;
"x86_64" | "AMD64")
FILENAME="$FILENAME-amd64"
;;
"aarch64")
FILENAME="$FILENAME-arm64"
;;
*)
err "Unsupported architecture: $ARCH"
;;
esac

DOWNLOAD_URL="$BASE_URL/$VERSION/daytona-$FILENAME"

# We want to fail fast so check everything before we download

# Check if the $DESTINATION exists. We are making a decision to not mkdir
# for the user here. /opt/bin and /usr/local/bin are system directories and
# the user should decide and explicitly create those.
if [ ! -d "$DESTINATION" ]; then
err "Destination directory $DESTINATION does not exist. Run mkdir -p $DESTINATION and re-run."
if [ ! "$DAYTONA_PATH" ]; then
echo "Default installation directory: /usr/local/bin"
echo "You can override this by setting the DAYTONA_PATH environment variable (ie. \`| DAYTONA_PATH=/home/user/bin bash\`)"
fi

# Check if sudo is required
if [ "$SUDO_REQUIRED" -eq 1 ] && [ "$EUID" -ne 0 ]; then
err "Cannot write to /opt/bin or /usr/local/bin as non root. Please re-run with sudo."
# Check if destination exists and is writable
if [[ ! -d $DESTINATION ]]; then
# Inform user about missing directory or write permissions
echo -e "\nWarning: Destination directory $DESTINATION does not exist."
# Provide instructions on how to create dir
echo " Create the directory:"
echo " mkdir -p $DESTINATION"
exit 1
fi
if [[ ! -w $DESTINATION ]]; then
echo -e "\nWarning: Destination directory $DESTINATION is not writeable."
echo " Rerun the script with SUDO privileges:"
if [ "$DAYTONA_PATH" ]; then
echo " curl -sf -L https://download.daytona.io/daytona/get-server.sh | DAYTONA_PATH=$DESTINATION sudo bash"
else
echo " curl -sf -L https://download.daytona.io/daytona/get-server.sh | sudo bash"
fi
exit 1
fi

DOWNLOAD_URL="$BASE_URL/$VERSION/daytona-$FILENAME"

echo "Downloading server from $DOWNLOAD_URL"
echo -e "\nDownloading server from $DOWNLOAD_URL"

# Create a temporary file to download the server binary. Just in case the author... user
# has say a directory named "daytona" in $HOME... the current directory.
Expand All @@ -105,11 +93,20 @@ trap 'rm -f "$temp_file"' EXIT
# -S, --show-error: When used with -s, show error even if silent mode is enabled.
# -L, --location: Follow redirects.
# -o, --output <file>: Write output to <file> instead of stdout.
curl -fsSL "$DOWNLOAD_URL" -o "$temp_file"
if [ $? -ne 0 ]; then
if ! curl -fsSL "$DOWNLOAD_URL" -o "$temp_file"; then
err "Daytona server download failed"
fi
chmod +x "$temp_file"

echo "Installing server to $DESTINATION"
mv "$temp_file" "$DESTINATION/daytona"

# Check if destination is in user's PATH
if [[ ! :"$PATH:" == *":$DESTINATION:"* ]]; then
echo -e "\nWarning: $DESTINATION is not currently in your PATH environment variable."
echo " To be able to run the Daytona server from any directory, you may need to add it to your PATH."
echo " Edit your shell configuration file (e.g., ~/.bashrc or ~/.zshrc)"
echo " Add the following line:"
echo " export PATH=\$PATH:$DESTINATION"
echo " Source the configuration file to apply the changes (e.g., source ~/.bashrc)"
fi

0 comments on commit daed9ed

Please sign in to comment.