diff --git a/autodl-initializer.sh b/autodl-initializer.sh index 83635ac..51f0e9a 100644 --- a/autodl-initializer.sh +++ b/autodl-initializer.sh @@ -1,17 +1,28 @@ #!/bin/bash -# This script is a initialization helper for container -# instances on AutoDL based on my flavour. It does: +# This script is a initialization helper for container instances +# on AutoDL based on my flavour. It does: # - Set up locale to avoid garbled text display. -# - Set up APT mirrors to speed up package installaion. -# - Install specified packages, then clean up APT caches. +# - Set up APT mirrors and install packages, clean cache when done. +# - Install `uv`, a powerful replacement for `pip`. # - Clean up bash history. # +# Some behavior can be suppressed by set/unset variables in script. +# # Also, there are some tips for your customization and simplifying server configuring. # - Add your SSH public keys. (Also can be done in AutoDL portal.) # - Add your custom hook function in this bash, do anything you like. # - Write files to your destination path. -# - Install `uv`, a powerful replacement for `pip` +# +# Usage: +# Download the script, then: +# 1. Review the custom options below. +# 2. Add your function hooks. +# 3. Write files to your destinations. +# 4. Run the script by `bash autodl-initializer.sh` +# 5. Restart/relogin to your shell, and have a rock! +# + @@ -28,6 +39,7 @@ SYSTEM_LOCALE="en_US.UTF-8" # Set the APT mirror URL. Scheme (http/https) is needed. # Example: 'http://mirrors.kernel.org' # Note: AutoDL instances have default fast mirrors. +# Disable this function by setting the var to empty. APT_MIRROR="" APT_SOURCE_FILE="/etc/apt/sources.list" @@ -35,6 +47,7 @@ APT_SOURCES_LIST_D="/etc/apt/sources.list.d" # List of packages to install, with spaces separated names. # Example: "tmux git curl htop" +# No package will be installed when this var is empty. PACKAGES_TO_INSTALL="tmux git curl nano htop nvtop" # SSH public key for authorization. @@ -42,6 +55,7 @@ PACKAGES_TO_INSTALL="tmux git curl nano htop nvtop" SSH_PUBLIC_KEY="" # uv install +# uv won't be installed when either of following vars is empty. UV_DOWNLOAD_URL="https://github.com/astral-sh/uv/releases/latest/download/uv-x86_64-unknown-linux-gnu.tar.gz" UV_INSTALL_PATH="${HOME}/.local/bin" @@ -76,6 +90,10 @@ add_hook_function() { # } # # Add the function to the hook list. # add_hook_function my_custom_setup + +# >>> Example of function hook. +# If you don't like this, feel free to delete it. +# Prevent conda activate base env automatically. disable_conda_auto_base() { local condarc="${HOME}/.condarc" if ! grep -qF "auto_activate_base" $condarc; then @@ -84,6 +102,7 @@ disable_conda_auto_base() { fi } add_hook_function disable_conda_auto_base +# <<< Delete the hook above. @@ -107,18 +126,25 @@ write_file() { cat > "$dest" } +# Tmux config write_file "${HOME}/.tmux.conf" <>> Skipping APT packages installation." @@ -518,6 +544,13 @@ clean_bash_history() { > ~/.bash_history } +# Show hints after finishing. +hint_after_finish() { + echo "--- Initialization finished. ---" + echo "Restart the shell to let the changes take effect." + echo "The simplest way is re-connect the server by SSH." +} + @@ -534,17 +567,21 @@ check_root set_locale replace_apt_mirror install_packages -clean_apt_cache add_ssh_key +# Install uv turbo_autodl_network install_uv # Execute the functions in the hook list. execute_hooks -# Clean the bash history as the final step. +# Clean the caches as the final step. +clean_apt_cache clean_bash_history +# Hint +hint_after_finish + # Exit with success status. exit 0 \ No newline at end of file