-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathucloudflared
More file actions
executable file
·77 lines (62 loc) · 2.17 KB
/
Copy pathucloudflared
File metadata and controls
executable file
·77 lines (62 loc) · 2.17 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Assign the basepath variable to $HOME/.ucloudflared
basepath="$HOME/.ucloudflared"
# Source the virtual environment activation script
source "$basepath/.venv/bin/activate"
# Print a message to confirm activation (optional)
echo "Virtual environment activated!"
# Detect architecture and store in ARCH variable
arch=$(uname -m)
if [[ $arch == aarch64 ]]; then
ARCH="linux-arm64"
elif [[ $arch == x86_64 ]]; then
ARCH="linux-amd64"
else
echo "ERROR: Unsupported architecture detected: $arch"
exit 1
fi
# Print the detected architecture (optional)
echo "Detected architecture: $ARCH"
# Define the threshold for time difference (in seconds)
THRESHOLD_SECONDS=$((2 * 24 * 60 * 60)) # 2 days in seconds
# Initialize flag as False
pull_image=false
timestamp_path=$basepath/timestamp.txt
# Check if timestamp.txt exists
if [[ -f $timestamp_path ]]; then
# Load the timestamp from the file
timestamp=$(<$timestamp_path)
# Get the current local time in seconds since epoch
current_time=$(date +%s)
# Calculate the time difference in seconds
time_diff=$((current_time - timestamp))
# Check if the time difference is less than the threshold
if [[ $time_diff -lt $THRESHOLD_SECONDS ]]; then
# Calculate remaining hours until exceeding threshold
remaining_hours=$(( ($THRESHOLD_SECONDS - $time_diff) / 3600 ))
echo "$remaining_hours hours left before pulling image."
else
# Set flag to True if time difference is greater than threshold
pull_image=true
date +%s > $timestamp_path
fi
else
# File doesn't exist, set flag to False
echo "timestamp.txt doesn't exist. Creating new one..."
date +%s > $timestamp_path
fi
# Print the final flag value
echo "Pull image? $pull_image"
if [[ "$pull_image" == "true" ]]; then
udocker pull ikhwanperwira/ucloudflared:$ARCH
fi
# Capture all script args
script_args="$@"
if [ "$(id -u)" -eq 0 ]; then
# Script is running as root
IS_ROOT="--allow-root"
else
# Script is not running as root
IS_ROOT=""
fi
# Execute the command with appropriate architecture
udocker "${IS_ROOT}" run -v $basepath:/home/nonroot -v $basepath/ping_group_range:/proc/sys/net/ipv4/ping_group_range ikhwanperwira/ucloudflared:$ARCH $script_args