├── .gitignore ├── README.md ├── install.sh ├── src ├── install-docker ├── install-tor ├── apt-set-proxy ├── mkswap-mem ├── logger ├── docker-vault ├── ency └── aws-bucket └── assets └── hashicorp-keyring /.gitignore: -------------------------------------------------------------------------------- 1 | # IDE 2 | .idea/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Scripts 2 | 3 | ### Install 4 | 5 | ```bash 6 | bash <(curl -fsSL https://raw.githubusercontent.com/shahradelahi/scripts/canary/install.sh) 7 | ``` -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | git clone https://github.com/shahradelahi/scripts.git /tmp/scripts 6 | 7 | chmod -R +x /tmp/scripts/src 8 | sudo mv /tmp/scripts/src/* /usr/local/bin 9 | 10 | rm -rf /tmp/scripts -------------------------------------------------------------------------------- /src/install-docker: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | sudo apt-get install ca-certificates curl gnupg 4 | sudo install -m 0755 -d /etc/apt/keyrings 5 | 6 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg 7 | 8 | sudo chmod a+r /etc/apt/keyrings/docker.gpg 9 | 10 | echo \ 11 | "deb [arch=\"$(dpkg --print-architecture)\" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ 12 | \"$(. /etc/os-release && echo "$VERSION_CODENAME")\" stable" | 13 | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null 14 | 15 | sudo apt-get update 16 | sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin 17 | 18 | sudo apt autoremove 19 | -------------------------------------------------------------------------------- /src/install-tor: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | curl -fsSL https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc \ 4 | -Lx http://188.121.112.83:2050 | gpg --dearmor | tee /usr/share/keyrings/tor-archive-keyring.gpg >/dev/null 5 | 6 | echo \ 7 | "deb [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] https://deb.torproject.org/torproject.org $(. /etc/os-release && echo "$VERSION_CODENAME") main" | 8 | sudo tee /etc/apt/sources.list.d/tor.list >/dev/null 9 | 10 | sudo tee /etc/apt/apt.conf.d/69proxy <<'EOF' 11 | Acquire::http::Proxy "http://188.121.112.83:2050"; 12 | Acquire::https::Proxy "http://188.121.112.83:2050"; 13 | EOF 14 | 15 | sudo apt-get update 16 | sudo apt-get install -y tor nyx obfs4proxy 17 | 18 | sudo rm /etc/apt/apt.conf.d/69proxy 19 | -------------------------------------------------------------------------------- /src/apt-set-proxy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | read -p "Proxy (leave blank to remove): " proxy 4 | 5 | function is_proxy_working() { 6 | echo "Checking connectivity..." 7 | Content="$(curl -m 5 -Lx $1 https://www.cloudflare.com/cdn-cgi/trace/)" 8 | ProxyIP="$(echo "$Content" | grep ip | awk -F= '{print $2}')" 9 | if [ -n "$ProxyIP" ]; then 10 | return 0 11 | else 12 | return 1 13 | fi 14 | } 15 | 16 | if [ -z "$proxy" ]; then 17 | echo "Removing Apt Proxy..." 18 | sudo rm -f /etc/apt/apt.conf.d/01proxy 19 | echo "Done." 20 | exit 0 21 | fi 22 | 23 | # checking if not starts with http:// or https:// 24 | if [[ ! "$proxy" =~ ^https?:// ]]; then 25 | echo "ERR: Proxy is not valid. You should use http or https." 26 | exit 1 27 | fi 28 | 29 | if ! is_proxy_working "$proxy"; then 30 | echo "ERR: Proxy is not working." 31 | exit 1 32 | fi 33 | 34 | echo "Proxy is working." 35 | echo "Adding to Apt Proxy..." 36 | 37 | sudo su -c "tee /etc/apt/apt.conf.d/01proxy <<'EOF' 38 | Acquire::http::Proxy \"$proxy\"; 39 | Acquire::https::Proxy \"$proxy\"; 40 | EOF" 41 | 42 | echo "Done." 43 | -------------------------------------------------------------------------------- /src/mkswap-mem: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | Size=$1 6 | Swappiness=${2-"30"} 7 | VfsCachePressure=${3-"50"} 8 | 9 | if [ -n "$Size" ]; then 10 | 11 | sudo fallocate -l "${Size}" /swapfile 12 | sudo chmod 600 /swapfile 13 | sudo mkswap /swapfile 14 | sudo swapon /swapfile 15 | 16 | swaps=$(sudo swapon -s) 17 | if [[ $swaps != *"/swapfile"* ]]; then 18 | echo "ERR: Swap file not created" 19 | exit 1 20 | fi 21 | 22 | sudo sed -i "/\/swapfile/d" /etc/fstab 23 | sudo cp /etc/fstab /etc/fstab.bak 24 | echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab >/dev/null 25 | 26 | sudo sed -i "/vm.swappiness/d" /etc/sysctl.conf 27 | sudo sysctl "vm.swappiness=${Swappiness}" 28 | echo "vm.swappiness=${Swappiness}" | sudo tee -a /etc/sysctl.conf >/dev/null 29 | 30 | sudo sed -i "/vm.vfs_cache_pressure/d" /etc/sysctl.conf 31 | sudo sysctl "vm.vfs_cache_pressure=${VfsCachePressure}" 32 | echo "vm.vfs_cache_pressure=${VfsCachePressure}" | sudo tee -a /etc/sysctl.conf >/dev/null 33 | 34 | echo "Swap file created with size $Size" 35 | 36 | else 37 | echo "Usage: $0 " 38 | exit 1 39 | fi 40 | -------------------------------------------------------------------------------- /src/logger: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Yanked from https://github.com/P3TERX/warp.sh/blob/main/warp.sh 4 | 5 | FontColor_Red="\033[31m" 6 | FontColor_Red_Bold="\033[1;31m" 7 | FontColor_Green="\033[32m" 8 | FontColor_Cyan="\033[36m" 9 | FontColor_Green_Bold="\033[1;32m" 10 | FontColor_Yellow="\033[33m" 11 | FontColor_Yellow_Bold="\033[1;33m" 12 | FontColor_Purple="\033[35m" 13 | FontColor_Purple_Bold="\033[1;35m" 14 | FontColor_Reset="\033[0m" 15 | 16 | log() { 17 | local LEVEL="$1" 18 | local MSG="$2" 19 | case "${LEVEL}" in 20 | INFO) 21 | local LEVEL="[${FontColor_Cyan}${LEVEL}${FontColor_Reset}]" 22 | local MSG="${LEVEL} ${MSG}" 23 | ;; 24 | WARN) 25 | local LEVEL="[${FontColor_Yellow}${LEVEL}${FontColor_Reset}]" 26 | local MSG="${LEVEL} ${MSG}" 27 | ;; 28 | ERROR) 29 | local LEVEL="[${FontColor_Red}${LEVEL}${FontColor_Reset}]" 30 | local MSG="${LEVEL} ${MSG}" 31 | ;; 32 | *) ;; 33 | esac 34 | echo -e "${MSG}" 35 | } 36 | 37 | # Usage: 38 | # 39 | # source logger 40 | # log INFO "This is an INFO message." 41 | 42 | # if it was called directly, execute the function and pass all arguments to it 43 | if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then 44 | log "$@" 45 | fi 46 | -------------------------------------------------------------------------------- /src/docker-vault: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | function install_vault() { 6 | sudo apt update 7 | sudo apt install jq gpg -y 8 | curl -fsSL https://apt.releases.hashicorp.com/gpg \ 9 | -Lx http://188.121.112.83:2050 | gpg --dearmor | tee /usr/share/keyrings/hashicorp-archive-keyring.gpg >/dev/null 10 | echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list 11 | sudo apt update && sudo apt install vault -y 12 | } 13 | 14 | function arg_exists() { 15 | shift 16 | local found="$(echo "$@" | grep -e " $1 " -e "^$1 " -e " $1$")" 17 | if [ -n "$found" ]; then 18 | return 0 19 | else 20 | return 1 21 | fi 22 | } 23 | 24 | function login_vault() { 25 | local address="$1" 26 | local secret="$2" 27 | local result=$(echo "$secret" | sudo vault login -address "$address" -method=token -) 28 | if [[ "$result" == *"Success! You are now authenticated."* ]]; then 29 | echo "LoggedIn." 30 | else 31 | echo "Failed." 32 | exit 1 33 | fi 34 | } 35 | 36 | function logout_vault() { 37 | sudo vault logout -address "https://vault.arvanbourse.com" 38 | } 39 | 40 | if [ ! -f "$(pwd)/docker-compose.yml" ]; then 41 | echo "We could not find a Docker Compose file in the current directory." 42 | exit 1 43 | fi 44 | 45 | function has_access() { 46 | local secrets_path="$1" 47 | local result=$(sudo vault kv get -address "$vault_address" -format=json "$secrets_path" 2>&1) 48 | if [[ "$result" == *"permission denied"* ]] || [[ "$result" == *"Error"* ]]; then 49 | return 1 50 | else 51 | return 0 52 | fi 53 | } 54 | 55 | vault_address="$1" 56 | if [ -z "$vault_address" ]; then 57 | read -p "Vault Address: " -r vault_address 58 | fi 59 | 60 | read -p "Vault Secret: " -s -r vault_secret 61 | echo "" 62 | 63 | read -p "Secret Path (spread with comma): " -r vault_secret_path 64 | if [ -z "$vault_secret_path" ]; then 65 | echo "Secret path is empty." 66 | exit 1 67 | fi 68 | NO_REASON=',' read -ra VAULT_SECRET_PATHS <<<"$vault_secret_path" 69 | FIRST_SECRET_PATH="${VAULT_SECRET_PATHS[0]}" 70 | 71 | read -p "Docker compose options (leave blank to skip): " -r COMPOSE_OPTS 72 | 73 | echo "Checking for access..." 74 | if ! has_access "$vault_secret_path"; then 75 | echo -n "Logging into the vault... " 76 | login_vault "$vault_address" "$FIRST_SECRET_PATH" 77 | fi 78 | 79 | if ! has_access "$vault_secret_path"; then 80 | echo "Failed to gain access to the vault." 81 | exit 1 82 | fi 83 | 84 | function write_secrets() { 85 | local SECRET_PATH="$1" 86 | if [ -z "$SECRET_PATH" ]; then 87 | echo "Secret path is empty." 88 | exit 1 89 | fi 90 | local VAULT_DATA=$(sudo vault kv get -address "$vault_address" -format=json "$SECRET_PATH" | jq -r '.data.data | to_entries[] | "\(.key)=\(.value)"') 91 | if [ -f .env.local ]; then 92 | echo "$VAULT_DATA" >>.env 93 | else 94 | echo "$VAULT_DATA" >.env 95 | fi 96 | awk '!seen[$0]++' .env >.env.tmp && mv .env.tmp .env 97 | } 98 | 99 | function remove_secrets() { 100 | echo -n "Removing secrets... " 101 | rm -f .env 102 | echo "Done." 103 | } 104 | 105 | echo "Fetching secrets..." 106 | for VAULT_SECRET_PATH in "${VAULT_SECRET_PATHS[@]}"; do 107 | echo " - $VAULT_SECRET_PATH" 108 | write_secrets "$VAULT_SECRET_PATH" 109 | done 110 | 111 | # Check if --prune flag exists 112 | if arg_exists "--prune" "$@"; then 113 | echo -n "Running Docker system prune (this may take some time)... " 114 | sudo docker system prune -a -f 115 | echo "Done." 116 | fi 117 | 118 | if [ -z "$COMPOSE_OPTS" ]; then 119 | COMPOSE_OPTS="" 120 | fi 121 | 122 | if arg_exists "--remove-orphans" "$@"; then 123 | COMPOSE_OPTS="$COMPOSE_OPTS --remove-orphans" 124 | fi 125 | 126 | COMPOSE_COMMAND="$(echo "docker compose up -d $COMPOSE_OPTS" | sed 's/ */ /g')" 127 | 128 | echo "Command: $COMPOSE_COMMAND" 129 | echo "" 130 | 131 | echo -n "Starting Docker compose... " 132 | echo "" 133 | sudo bash -c "$COMPOSE_COMMAND" 134 | echo "Done." 135 | 136 | remove_secrets 137 | -------------------------------------------------------------------------------- /assets/hashicorp-keyring: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP PUBLIC KEY BLOCK----- 2 | 3 | mQINBGO9u+MBEADmE9i8rpt8xhRqxbzlBG06z3qe+e1DI+SyjscyVVRcGDrEfo+J 4 | W5UWw0+afey7HFkaKqKqOHVVGSjmh6HO3MskxcpRm/pxRzfni/OcBBuJU2DcGXnG 5 | nuRZ+ltqBncOuONi6Wf00McTWviLKHRrP6oWwWww7sYF/RbZp5xGmMJ2vnsNhtp3 6 | 8LIMOmY2xv9LeKMh++WcxQDpIeRohmSJyknbjJ0MNlhnezTIPajrs1laLh/IVKVz 7 | 7/Z73UWX+rWI/5g+6yBSEtj368N7iyq+hUvQ/bL00eyg1Gs8nE1xiCmRHdNjMBLX 8 | lHi0V9fYgg3KVGo6Hi/Is2gUtm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qQCY2lGcD5k05z 56 | bBC4TvxwVxv0ftl2C5Bd0ydl/2YM7GfLrmZmTijK067t4OO+2SROT2oYPDsMtZ6S 57 | E8vUXvoGpQ8tf5Nkrn2t0zDG3UDtgZY5UVYnZI+xT7WHsCz//8fY3QMvPXAuc33T 58 | vVdiSfP0aBnZXj6oGs/4Vl1Dmm62XLr13+SMoepMWg2Vt7C8jqKOmhFmSOWyOmRH 59 | UZJR7nKvTpFnL8atSyFDa4o1bk2U3alOscWS8u8xJ/iMcoONEBhItft6olpMVdzP 60 | CTrnCAqMjTSPlQU/9EGtp21KQBed2KdAsJBYuPgwaQeyNIvQEOXmINavl58VD72Y 61 | 2T4TFEY8dUiExAYpSodbwBL2fr8DJxOX68WH6e3fF7HwX8LRBjZq0XUwh0KxgHN+ 62 | b9gGXBvgWnJr4NSQGGPiSQVNNHt2ZcBAClYhm+9eC5/VwB+Etg4+1wDmggztiqE= 63 | =FdUF 64 | -----END PGP PUBLIC KEY BLOCK----- 65 | 66 | -------------------------------------------------------------------------------- /src/ency: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Function to display script usage 4 | function usage() { 5 | cat < | ency -e aes -t 15 | echo | ency -d aes -t | ency -d hex 16 | 17 | EOF 18 | } 19 | 20 | function has_argument() { 21 | [[ "$1" == *=* ]] && [[ -n "${1#*=}" ]] || [[ ! -z "$2" && "$2" != -* ]] 22 | } 23 | 24 | function arg_exists() { 25 | local arg_to_check="$1" 26 | 27 | # Loop through the command line arguments 28 | for arg in $2; do 29 | if [ "$arg" == "$arg_to_check" ]; then 30 | return 0 # Argument found, return success status (0) 31 | fi 32 | done 33 | 34 | return 1 # Argument not found, return failure status (1) 35 | } 36 | 37 | function extract_argument() { 38 | echo "${2:-${1#*=}}" 39 | } 40 | 41 | # Function to handle options and arguments 42 | function handle_options() { 43 | rest="" 44 | while [ $# -gt 0 ]; do 45 | case $1 in 46 | -h | --help) 47 | usage 48 | exit 0 49 | ;; 50 | -e | --encode | -d | --decode) 51 | if ! has_argument "$@"; then 52 | echo "File not specified." >&2 53 | usage 54 | exit 1 55 | fi 56 | if [ "$1" == "-e" ] | [ "$1" == "-e" ]; then 57 | action="enc" 58 | else 59 | action="dec" 60 | fi 61 | method="$(extract_argument "$@")" 62 | shift 63 | ;; 64 | -t | --transform) 65 | if ! has_argument "$@"; then 66 | echo "transform arg has no value." >&2 67 | usage 68 | exit 1 69 | fi 70 | text="$(extract_argument "$@")" 71 | shift 72 | ;; 73 | -k | --key) 74 | if ! has_argument "$@"; then 75 | echo "transform arg has no value." >&2 76 | usage 77 | exit 1 78 | fi 79 | secret="$(extract_argument "$@")" 80 | shift 81 | ;; 82 | esac 83 | rest=$(echo "$rest $1" | xargs) 84 | shift 85 | done 86 | } 87 | 88 | # Main script execution 89 | handle_options "$@" 90 | nargs=($rest) 91 | 92 | if [ -z "$method" ] | [ -z "$action" ]; then 93 | echo "$method $action $text" 94 | usage 95 | exit 1 96 | fi 97 | 98 | if [ -z "$text" ]; then 99 | read -p "text: " -r text 100 | fi 101 | 102 | to_hex() { 103 | echo -n "$1" | od -A n -t x1 | tr -d '\n' | sed 's/ *//g' 104 | } 105 | 106 | from_hex() { 107 | bytes=$(echo -n "$text" | sed 's/\(..\)/\\x\1/g') 108 | utf8_string=$(echo -n -e "$bytes") 109 | echo "$utf8_string" 110 | } 111 | 112 | # Function to encrypt a string with AES 113 | aes_encrypt_string() { 114 | local plaintext="$(to_hex "$1")" 115 | local key="$(to_hex "$2")" 116 | local iv=$(echo -n "$key" | md5sum | awk '{print $1}') 117 | 118 | echo -n "$plaintext" | openssl enc -aes-256-cbc -a -K "$key" -iv "$iv" 119 | } 120 | 121 | # Function to decrypt an AES-encrypted string 122 | aes_decrypt_string() { 123 | local encrypted_text="$1" 124 | local key="$(to_hex "$2")" 125 | local iv=$(echo -n "$key" | md5sum | awk '{print $1}') 126 | 127 | echo "$encrypted_text" | openssl enc -d -aes-256-cbc -a -A -K "$key" -iv "$iv" 128 | } 129 | 130 | function handle_encode() { 131 | case $method in 132 | hex) 133 | hex_string=$(to_hex "$text") 134 | if arg_exists "-0x" "$rest"; then 135 | echo "0x$hex_string" 136 | exit 0 137 | fi 138 | echo "$hex_string" 139 | exit 0 140 | ;; 141 | sha1) 142 | echo -n "$text" | openssl sha1 -hex | awk '{print $2}' 143 | exit 0 144 | ;; 145 | aes) 146 | if [ -z "$secret" ] || [ "$secret" == "" ]; then 147 | read -p "secret(hidden): " -s -r secret 148 | fi 149 | encrypted=$(aes_encrypt_string "$text" "$secret") 150 | echo "$encrypted" 151 | exit 0 152 | ;; 153 | *) 154 | exit 1 155 | ;; 156 | esac 157 | } 158 | 159 | function handle_decode() { 160 | case $method in 161 | hex) 162 | utf8_string=$(from_hex "$text") 163 | echo "$utf8_string" 164 | exit 0 165 | ;; 166 | aes) 167 | if [ -z "$secret" ] || [ "$secret" == "" ]; then 168 | read -p "secret(hidden): " -s -r secret 169 | fi 170 | decrypted=$(aes_decrypt_string "$text" "$secret") 171 | echo "$decrypted" 172 | exit 0 173 | ;; 174 | *) 175 | exit 1 176 | ;; 177 | esac 178 | } 179 | 180 | if [ "$action" == "enc" ]; then 181 | handle_encode "$@" 182 | elif [ "$action" == "dec" ]; then 183 | handle_decode 184 | else 185 | echo "Action is missing..." 186 | exit 1 187 | fi 188 | -------------------------------------------------------------------------------- /src/aws-bucket: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | #set -x # This will print the commands as they are executed 4 | set -e # This will make the script exit if an error happens 5 | #set -u # This will make the script exit if an undefined variable is used 6 | #set -o pipefail # This will make the script exit if a command in a pipe fails 7 | 8 | # Install: 9 | # sudo chmod +x ./aws-bucket && sudo mv ./aws-bucket /usr/bin/aws-bucket 10 | 11 | install() { 12 | local sysArch="$(uname -m)" 13 | if [ "$sysArch" == "armv7l" ] || [ "$sysArch" == "armv6l" ]; then 14 | curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip" 15 | elif [ "$sysArch" == "x86_64" ]; then 16 | curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" 17 | else 18 | echo "Architecture not supported." 19 | exit 1 20 | fi 21 | 22 | unzip awscliv2.zip 23 | sudo ./aws/install 24 | 25 | if [ ! -f "$(which aws)" ]; then 26 | echo "AWS CLI is not installed." 27 | fi 28 | 29 | rm -rf awscliv2.zip aws 30 | echo "AWS CLI is installed." 31 | } 32 | 33 | AwsPath="$(which aws)" 34 | if [ -z "$AwsPath" ]; then 35 | echo "AWS CLI is not installed." 36 | read -p "Do you want to install it? [y/N] " -r installAws 37 | if [ "$installAws" == "y" ] || [ "$installAws" == "Y" ]; then 38 | install 39 | else 40 | echo "AWS CLI is required." 41 | exit 1 42 | fi 43 | fi 44 | 45 | usage() { 46 | cat <>"$HOME/.aws/credentials" 109 | echo "aws_access_key_id = $aws_access_key_id" >>"$HOME/.aws/credentials" 110 | echo "aws_secret_access_key = $aws_secret_access_key" >>"$HOME/.aws/credentials" 111 | fi 112 | 113 | function cp() { 114 | local source="$1" 115 | local destination="$2" 116 | if [ -z "$source" ]; then 117 | echo "Source is empty." 118 | exit 1 119 | fi 120 | if [ -z "$destination" ]; then 121 | echo "Destination is empty." 122 | exit 1 123 | fi 124 | if [ -z "$aws_endpoint" ]; then 125 | aws s3 --profile "bucket" cp "$source" "$destination" 126 | else 127 | aws s3 --profile "bucket" cp "$source" "$destination" --endpoint-url "$aws_endpoint" 128 | fi 129 | } 130 | 131 | function handle() { 132 | case "$1" in 133 | cp) 134 | shift 135 | cp "$@" 136 | ;; 137 | ls) 138 | shift 139 | if [ -z "$aws_endpoint" ]; then 140 | aws s3 --profile "bucket" ls "$@" 141 | else 142 | aws s3 --profile "bucket" ls "$@" --endpoint-url "$aws_endpoint" 143 | fi 144 | ;; 145 | rm) 146 | shift 147 | if [ -z "$aws_endpoint" ]; then 148 | aws s3 --profile "bucket" rm "$@" 149 | else 150 | aws s3 --profile "bucket" rm "$@" --endpoint-url "$aws_endpoint" 151 | fi 152 | ;; 153 | sync) 154 | shift 155 | if [ -z "$aws_endpoint" ]; then 156 | aws s3 --profile "bucket" sync "$@" 157 | else 158 | aws s3 --profile "bucket" sync "$@" --endpoint-url "$aws_endpoint" 159 | fi 160 | ;; 161 | *) 162 | echo "Did you forgot commands?" 163 | usage 164 | exit 1 165 | ;; 166 | esac 167 | } 168 | 169 | handle $args 170 | --------------------------------------------------------------------------------