-
Notifications
You must be signed in to change notification settings - Fork 0
/
pritunl-profile-encode.sh
executable file
·45 lines (41 loc) · 1.37 KB
/
pritunl-profile-encode.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
42
43
44
45
#!/bin/bash
# Define a private function to read file data or download from URL
# This function is used internally to fetch the profile data
__get_profile_data() {
# Check if the input is a file
if [ -f "$1" ]; then
# If it's a file, read its contents
cat "$1"
else
# If it's not a file, assume it's a URL and download the data
curl -sSL "$1"
fi
}
# Define a public function to encode a profile and copy it to the clipboard
# This function takes a file path or URL as input, encodes the data to base64,
# and copies it to the clipboard
encode_profile_and_copy() {
# Check if a file path or URL is provided as an argument
if [ $# -eq 0 ]; then
# If no argument is provided, print an error message and usage instructions
echo "Error: No argument provided"
echo "Usage: $(basename "$0") <url or file path>"
echo "Examples:"
echo " Using a URL: $(basename "$0") https://vpn.domain.tld/key/a1b2c3d4e5.tar"
echo " Using a local file path: $(basename "$0") ./pritunl.profile.tar"
return 1
fi
# Get the profile data using the private function
__get_profile_data "$1" |
# Encode the data to base64
base64 --wrap 0 |
# Copy the encoded data to the clipboard
{
# Use pbcopy for macOS
pbcopy
} || {
# Use xclip or xsel for Linux or WSL
xclip -selection clipboard || xsel --clipboard --input
}
}
encode_profile_and_copy "$@"