-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswift.sh
executable file
·41 lines (32 loc) · 1.13 KB
/
swift.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# Step 1: Install OpenStack CLI Utilities
echo "Installing OpenStack CLI utilities..."
pip install python-openstackclient python-swiftclient
# Step 2: Configure the environment
read -p "Enter the auth URL: " auth_url
read -p "Enter the token: " token
# Step 3: Prompt for the prefix
read -p "Enter a prefix to add to the file: " prefix
# Check if a prefix is provided
if [[ -z "$prefix" ]]; then
echo "Error: Please enter a prefix."
exit 1
fi
# Step 4: Loop through all files in the current directory
for filename in *; do
# Skip hidden files and directories
if [[ "$filename" == "." || "$filename" == ".." ]]; then
continue
fi
# Construct the target path in OpenStack storage
target_path="$prefix-$filename"
# Upload the file to Swift with the provided prefix
swift --os-auth-token $token --os-storage-url $auth_url upload IVDO "$filename" --object-name "$target_path"
# Check for upload success
if [[ $? -eq 0 ]]; then
echo "File $filename uploaded successfully to $target_path"
else
echo "Error uploading file $filename."
fi
done
echo "Finished processing all files in the current directory."