From 88a53cecd8d4a9a54aa6f4cc1e718542432d69b1 Mon Sep 17 00:00:00 2001 From: Yash Gorana Date: Thu, 10 Oct 2024 01:02:29 +0530 Subject: [PATCH 1/5] one line to rule them all --- MANIFEST.in | 2 +- syftbox/server/server.py | 23 ++--- syftbox/server/templates/install.sh | 153 ++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+), 13 deletions(-) create mode 100644 syftbox/server/templates/install.sh diff --git a/MANIFEST.in b/MANIFEST.in index e77d35e7..9d4d1a71 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ -recursive-include syftbox *.html *.js *.css *.zip +recursive-include syftbox *.html *.js *.css *.zip *.sh recursive-include default_apps *.py *.sh *.html *.js *.css *.zip *.png *.txt *.csv diff --git a/syftbox/server/server.py b/syftbox/server/server.py index bd8f4764..7636667f 100644 --- a/syftbox/server/server.py +++ b/syftbox/server/server.py @@ -171,18 +171,11 @@ async def lifespan(app: FastAPI): |___/ {__version__:>17} -# MacOS and Linux -Install uv -curl -LsSf https://astral.sh/uv/install.sh | sh +# Install Syftbox (MacOS and Linux) +curl -LsSf https://syftboxstage.openmined.org/install.sh | sh -# create a virtualenv `.venv` in current working dir -uv venv - -# Install SyftBox -uv pip install -U syftbox - -# run the client -uv run syftbox client +# Run the client +syftbox client """ @@ -444,8 +437,14 @@ async def datasites( return JSONResponse({"status": "error"}, status_code=400) +@app.get("/install.sh") +async def install(): + install_script = current_dir / "templates" / "install.sh" + return FileResponse(install_script, media_type="text/plain") + + @app.get("/info") -def info(): +async def info(): return { "version": __version__, } diff --git a/syftbox/server/templates/install.sh b/syftbox/server/templates/install.sh new file mode 100644 index 00000000..f0b6f13c --- /dev/null +++ b/syftbox/server/templates/install.sh @@ -0,0 +1,153 @@ +#!/bin/sh + +set -e + +red='\033[1;31m' +yellow='\033[0;33m' +cyan='\033[0;36m' +green='\033[1;32m' +reset='\033[0m' + +err() { + echo "${red}ERROR${reset}: $1" >&2 + exit 1 +} + +info() { + echo "${cyan}$1${reset}" +} + +warn() { + echo "${yellow}$1${reset}" +} + +success() { + echo "${green}$1${reset}" +} + +check_cmd() { + command -v "$1" > /dev/null 2>&1 + return $? +} + +need_cmd() { + if ! check_cmd "$1" + then err "need '$1' (command not found)" + fi +} + +downloader() { + if check_cmd curl + then curl -sSfL "$1" + elif check_cmd wget + then wget -qO- "$1" + else need_cmd "curl or wget" + fi +} + +need_python() { + # check if either python3 or python is available + if ! check_cmd python && ! check_cmd python3 + then err "need 'python' or 'python3' (command not found)" + fi +} + +check_home_path() { + # check if a path exists as ~/path or $HOME/path + if echo $PATH | grep -q "$HOME/$1" || echo $PATH | grep -q "~/$1" + then return 0 + else return 1 + fi +} + +write_path() { + local _path_contents="$1" + local _profile_path="$2" + # if profile exists, add the export + if [ -f "$_profile_path" ] + then + echo "export PATH=\"$_path_contents\$PATH\"" >> $_profile_path; + fi +} + +patch_path() { + local _path_expr="" + + if ! check_home_path ".cargo/bin" + then _path_expr="$HOME/.cargo/bin:" + fi + + if ! check_home_path ".local/bin" + then _path_expr="${_path_expr}$HOME/.local/bin:" + fi + + # reload env vars + export PATH="$_path_expr$PATH" + + # write to profile files + write_path $_path_expr "$HOME/.profile" + write_path $_path_expr "$HOME/.zshrc" + write_path $_path_expr "$HOME/.bashrc" + write_path $_path_expr "$HOME/.bash_profile" +} + +download_uv() { + if ! check_cmd "uv" + then downloader https://astral.sh/uv/install.sh | env INSTALLER_PRINT_QUIET=1 sh + fi +} + +install_uv() { + download_uv + patch_path +} + +install_syftbox() { + need_cmd "uv" + exit=$(uv tool install -Uq syftbox) + if ! $(exit) + then err "failed to install syftbox" + fi +} + +pre_install() { + echo " + ____ __ _ ____ +/ ___| _ _ / _| |_| __ ) _____ __ +\___ \| | | | |_| __| _ \ / _ \ \/ / + ___) | |_| | _| |_| |_) | (_) > < +|____/ \__, |_| \__|____/ \___/_/\_\\ + |___/ +" + + # ----- pre-install checks ---- + # uv doesn't really need python, + # ... but incase we want we can toggle this on + # need_python +} + +post_install() { + echo + warn "RESTART your shell or RELOAD shell profile" + echo " \`source ~/.zshrc\` (for zsh)" + echo " \`source ~/.bash_profile\` (for bash)" + echo " \`source ~/.profile\` (for sh)" + + success "\nAfter reloading, start the client" + echo " \`syftbox client\`" +} + +do_install() { + pre_install + + info "Installing uv" + install_uv + + info "Installing SyftBox" + install_syftbox + + success "Installation completed!" + post_install +} + +do_install From c92baab55eda202a9150c00d30eab2e089c7b543 Mon Sep 17 00:00:00 2001 From: Yash Gorana Date: Thu, 10 Oct 2024 14:19:21 +0530 Subject: [PATCH 2/5] R E D U C E --- syftbox/server/templates/install.sh | 63 +++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/syftbox/server/templates/install.sh b/syftbox/server/templates/install.sh index f0b6f13c..4cb36c02 100644 --- a/syftbox/server/templates/install.sh +++ b/syftbox/server/templates/install.sh @@ -2,6 +2,12 @@ set -e +# --no-prompt => disables the run client prompt +ASK_RUN_CLIENT=1 + +# --run => disables the prompt & runs the client +RUN_CLIENT=0 + red='\033[1;31m' yellow='\033[0;33m' cyan='\033[0;36m' @@ -111,6 +117,12 @@ install_syftbox() { } pre_install() { + # ----- pre-install checks ---- + # uv doesn't really need python, + # ... but incase we want we can toggle this on + # need_python + + # if you see this message, you're good to go echo " ____ __ _ ____ / ___| _ _ / _| |_| __ ) _____ __ @@ -119,15 +131,28 @@ pre_install() { |____/ \__, |_| \__|____/ \___/_/\_\\ |___/ " +} - # ----- pre-install checks ---- - # uv doesn't really need python, - # ... but incase we want we can toggle this on - # need_python +run_client() { + success "Starting SyftBox client..." + exec ~/.local/bin/syftbox client } -post_install() { - echo +prompt_run_client() { + # prompt if they want to start the client + prompt=$(echo "${yellow}Start the client now? [y/n] ${reset}") + while [ "$start_client" != "y" ] && [ "$start_client" != "Y" ] && [ "$start_client" != "n" ] && [ "$start_client" != "N" ] + do + read -p "$prompt" start_client < /dev/tty + done + + if [ "$start_client" = "y" ] || [ "$start_client" = "Y" ] + then run_client + fi +} + +prompt_restart_shell() { + # default warn "RESTART your shell or RELOAD shell profile" echo " \`source ~/.zshrc\` (for zsh)" echo " \`source ~/.bash_profile\` (for bash)" @@ -137,7 +162,31 @@ post_install() { echo " \`syftbox client\`" } +post_install() { + echo + + if [ $RUN_CLIENT -eq 1 ] + then run_client + elif [ $ASK_RUN_CLIENT -eq 1 ] + then prompt_run_client + else prompt_restart_shell + fi +} + do_install() { + for arg in "$@"; do + case "$arg" in + -r|--run|run) + RUN_CLIENT=1 + ;; + -n|--no-prompt|no-prompt) + ASK_RUN_CLIENT=0 + ;; + *) + ;; + esac + done + pre_install info "Installing uv" @@ -150,4 +199,4 @@ do_install() { post_install } -do_install +do_install "$@" || exit 1 From 9406c365a6d7e083ba633a8e978b8540c008b024 Mon Sep 17 00:00:00 2001 From: Yash Gorana Date: Thu, 10 Oct 2024 14:28:41 +0530 Subject: [PATCH 3/5] fix --- syftbox/server/templates/install.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/syftbox/server/templates/install.sh b/syftbox/server/templates/install.sh index 4cb36c02..58d4dd2a 100644 --- a/syftbox/server/templates/install.sh +++ b/syftbox/server/templates/install.sh @@ -134,12 +134,14 @@ pre_install() { } run_client() { + echo success "Starting SyftBox client..." exec ~/.local/bin/syftbox client } prompt_run_client() { # prompt if they want to start the client + echo prompt=$(echo "${yellow}Start the client now? [y/n] ${reset}") while [ "$start_client" != "y" ] && [ "$start_client" != "Y" ] && [ "$start_client" != "n" ] && [ "$start_client" != "N" ] do @@ -148,11 +150,12 @@ prompt_run_client() { if [ "$start_client" = "y" ] || [ "$start_client" = "Y" ] then run_client + else prompt_restart_shell fi } prompt_restart_shell() { - # default + echo warn "RESTART your shell or RELOAD shell profile" echo " \`source ~/.zshrc\` (for zsh)" echo " \`source ~/.bash_profile\` (for bash)" @@ -163,8 +166,6 @@ prompt_restart_shell() { } post_install() { - echo - if [ $RUN_CLIENT -eq 1 ] then run_client elif [ $ASK_RUN_CLIENT -eq 1 ] From 112bc888e61e883565ed2127165dc7e683089d12 Mon Sep 17 00:00:00 2001 From: khoaguin Date: Thu, 10 Oct 2024 16:59:11 +0700 Subject: [PATCH 4/5] change server IP from `20.168.10.234` to domain `syftbox.openmined.org` at some client side places --- README.md | 4 ++-- scripts/live_andrew.sh | 2 +- scripts/live_madhava.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 026828aa..455b9e17 100644 --- a/README.md +++ b/README.md @@ -66,13 +66,13 @@ uv run syftbox/client/client.py ### Run Client ``` -syftbox client --config_path=./config.json --sync_folder=~/Desktop/SyftBox --email=your@email.org --port=8082 --server=http://20.168.10.234:8080 +syftbox client --config_path=./config.json --sync_folder=~/Desktop/SyftBox --email=your@email.org --port=8082 --server=http://syftbox.openmined.org:8080 ``` ### Deploy This builds the latest source to a wheel and deploys and restarts the server: -http://20.168.10.234:8080 +http://syftbox.openmined.org:8080 ``` ./scripts/deploy.sh diff --git a/scripts/live_andrew.sh b/scripts/live_andrew.sh index 6f0d297f..cd8b1ea4 100755 --- a/scripts/live_andrew.sh +++ b/scripts/live_andrew.sh @@ -1,2 +1,2 @@ #!/bin/bash -uv run syftbox/client/client.py --config_path=./users/live_andrew.json --sync_folder=./users/live_andrew --email=andrew@openmined.org --port=8082 --server=http://20.168.10.234:8080 +uv run syftbox/client/client.py --config_path=./users/live_andrew.json --sync_folder=./users/live_andrew --email=andrew@openmined.org --port=8082 --server=http://syftbox.openmined.org:8080 diff --git a/scripts/live_madhava.sh b/scripts/live_madhava.sh index bd655b8e..36a18a13 100755 --- a/scripts/live_madhava.sh +++ b/scripts/live_madhava.sh @@ -1,2 +1,2 @@ #!/bin/bash -uv run syftbox/client/client.py --config_path=./users/live_madhava.json --sync_folder=./users/live_madhava --email=madhava@openmined.org --port=8081 --server=http://20.168.10.234:8080 +uv run syftbox/client/client.py --config_path=./users/live_madhava.json --sync_folder=./users/live_madhava --email=madhava@openmined.org --port=8081 --server=http://syftbox.openmined.org:8080 From e39fd928091c7416332a60eb5e75bf75bd092040 Mon Sep 17 00:00:00 2001 From: Madhava Jay Date: Fri, 11 Oct 2024 09:54:54 +1000 Subject: [PATCH 5/5] Tweaking plugin print --- syftbox/client/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/syftbox/client/client.py b/syftbox/client/client.py index f2d140d3..10523ee4 100644 --- a/syftbox/client/client.py +++ b/syftbox/client/client.py @@ -344,9 +344,10 @@ async def lifespan(app: CustomFastAPI, client_config: ClientConfig | None = None app.scheduler = scheduler app.running_plugins = {} app.loaded_plugins = load_plugins(client_config) - print("> Loaded plugins:", list(app.loaded_plugins.keys())) + print("> Loaded plugins:", sorted(list(app.loaded_plugins.keys()))) app.watchdog = start_watchdog(app) + print("> Starting autorun plugins:", sorted(client_config.autorun_plugins)) for plugin in client_config.autorun_plugins: start_plugin(app, plugin)