-
Notifications
You must be signed in to change notification settings - Fork 1
feat: update mac install script to download from latest release #141
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,39 @@ set -e | |
|
||
service_name="com.observeinc.agent" | ||
observeagent_install_dir="/usr/local/observe-agent" | ||
# TODO download the file instead of using the local built zip | ||
script_dir=$(dirname -- "$(readlink -f -- "$0")") | ||
zip_dir="$(dirname $script_dir)/dist/darwin_arm64_v8.0/observe-agent_Darwin_arm64.zip" | ||
tmp_dir="/tmp/observe-agent" | ||
|
||
# Parse args | ||
while [ $# -gt 0 ]; do | ||
opt=$1 | ||
shift | ||
arg="" | ||
if [[ "$opt" == *"="* ]]; then | ||
arg=$(echo $opt | cut -d'=' -f2) | ||
opt=$(echo $opt | cut -d'=' -f1) | ||
elif [ $# -gt 0 ]; then | ||
arg="$1" | ||
shift | ||
fi | ||
case "$opt" in | ||
--token) | ||
TOKEN="$arg" | ||
;; | ||
--observe_url) | ||
OBSERVE_URL="$arg" | ||
;; | ||
--logs_enabled) | ||
LOGS_ENABLED="$arg" | ||
;; | ||
--metrics_enabled) | ||
METRICS_ENABLED="$arg" | ||
;; | ||
*) | ||
echo "Unknown option: $opt" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
# If the observe-agent.yaml file already exists, leave it alone. | ||
# Otherwise we need to know what the collection endpoint and token are. | ||
|
@@ -22,11 +52,19 @@ if [ ! -f "$observeagent_install_dir/observe-agent.yaml" ]; then | |
fi | ||
fi | ||
|
||
# TODO download the zip file from the latest release | ||
# If the zip file is not provided, download the latest release from GitHub. | ||
if [ -z "$ZIP_DIR" ]; then | ||
echo "Downloading latest release from GitHub..." | ||
curl -s -L -o /tmp/observe-agent.zip https://github.com/observeinc/observe-agent/releases/latest/download/observe-agent_Darwin_$(arch).zip | ||
ZIP_DIR="/tmp/observe-agent.zip" | ||
else | ||
echo "Installing from provided zip file: $ZIP_DIR" | ||
fi | ||
|
||
unzip_dir="/tmp/observe-agent" | ||
rm -rf $unzip_dir | ||
unzip $zip_dir -d $unzip_dir >/dev/null | ||
# Set up the temp dir and extract files. | ||
rm -rf $tmp_dir | ||
mkdir -p $tmp_dir | ||
unzip $ZIP_DIR -d $tmp_dir >/dev/null | ||
|
||
if [ -f "/Library/LaunchDaemons/$service_name.plist" ]; then | ||
echo "Stopping $service_name. This may ask for your password..." | ||
|
@@ -40,17 +78,32 @@ sudo mkdir -p $observeagent_install_dir /usr/local/libexec /usr/local/bin /var/l | |
sudo chmod +rw /var/lib/observe-agent/filestorage | ||
|
||
# Copy all files to the install dir. | ||
sudo cp -f $unzip_dir/observe-agent $observeagent_install_dir/observe-agent | ||
sudo cp -fR $unzip_dir/config $observeagent_install_dir/config | ||
sudo cp -fR $unzip_dir/connections $observeagent_install_dir/connections | ||
sudo cp -f $tmp_dir/observe-agent $observeagent_install_dir/observe-agent | ||
sudo cp -fR $tmp_dir/config $observeagent_install_dir/config | ||
sudo cp -fR $tmp_dir/connections $observeagent_install_dir/connections | ||
sudo chown -R root:wheel $observeagent_install_dir | ||
|
||
# Initialize the agent config file if it doesn't exist | ||
if [ -f "$observeagent_install_dir/observe-agent.yaml" ]; then | ||
echo "Leaving existing observe-agent.yaml in place." | ||
else | ||
echo "Initializing observe-agent.yaml" | ||
sudo $observeagent_install_dir/observe-agent init-config --token $TOKEN --observe_url $OBSERVE_URL --config_path $observeagent_install_dir/observe-agent.yaml | ||
INIT_FLAGS="--config_path $observeagent_install_dir/observe-agent.yaml --token $TOKEN --observe_url $OBSERVE_URL --host_monitoring::enabled=true" | ||
if [ -n "$LOGS_ENABLED" ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where are the keys for these args defined? is this just an env var? are we adding another layer/set of config key names? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, these are just env vars. I needed some way of getting the args from the connection into the config. Now that you've called attention to this though, I wonder if it's better to switch this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @obs-gh-alexlew for context, we invoke the Windows install script like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated so it now works like: |
||
if [[ "${LOGS_ENABLED,,}" == "true" ]]; then | ||
INIT_FLAGS="$INIT_FLAGS --host_monitoring::logs::enabled=true" | ||
else | ||
INIT_FLAGS="$INIT_FLAGS --host_monitoring::logs::enabled=false" | ||
fi | ||
fi | ||
if [ -n "$METRICS_ENABLED" ]; then | ||
if [[ "${METRICS_ENABLED,,}" == "true" ]]; then | ||
INIT_FLAGS="$INIT_FLAGS --host_monitoring::metrics::host::enabled=true" | ||
else | ||
INIT_FLAGS="$INIT_FLAGS --host_monitoring::metrics::host::enabled=false" | ||
fi | ||
fi | ||
sudo $observeagent_install_dir/observe-agent init-config $INIT_FLAGS | ||
sudo chown root:wheel $observeagent_install_dir/observe-agent.yaml | ||
fi | ||
|
||
|
@@ -62,7 +115,7 @@ echo "Observe agent successfully installed to $observeagent_install_dir" | |
|
||
# Install the launchd agent | ||
echo "Installing $service_name as a LaunchDaemon. This may ask for your password..." | ||
sudo cp -f $unzip_dir/observe-agent.plist /Library/LaunchDaemons/$service_name.plist | ||
sudo cp -f $tmp_dir/observe-agent.plist /Library/LaunchDaemons/$service_name.plist | ||
sudo chown root:wheel /Library/LaunchDaemons/$service_name.plist | ||
sudo launchctl load -w /Library/LaunchDaemons/$service_name.plist | ||
sudo launchctl kickstart "system/$service_name" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getopts
doesn't work on mac for long options unfortunately, so I had to write out this approximation. It doesn't have all the bells and whistles, but is robust enough for our use case of having users copy/paste commands from the connection portal.