49 lines
1.1 KiB
Bash
49 lines
1.1 KiB
Bash
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
umask 077
|
|
cat <<EOF > .gitea_token
|
|
REPLACE:gitea-token
|
|
EOF
|
|
|
|
fetch() {
|
|
local script_name=$1
|
|
local target=$2
|
|
local token_file=".gitea_token"
|
|
local gitea_user="user"
|
|
local gitea_repo="repo"
|
|
local gitea_domain="http://127.0.0.1:3333"
|
|
local gitea_access_token
|
|
|
|
if [[ -f "$token_file" ]]; then
|
|
gitea_access_token=$(<"$token_file")
|
|
else
|
|
echo "Cannot find the Gitea token file. Ensure it exists at $token_file."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Fetching ${script_name}..."
|
|
|
|
mkdir -p "$(dirname "$target")"
|
|
|
|
if curl -fsSL \
|
|
--header "Authorization: token $gitea_access_token" \
|
|
"${gitea_domain}/api/v1/repos/${gitea_user}/${gitea_repo}/raw/${script_name}" \
|
|
-o "$target"; then
|
|
|
|
chmod +x "$target"
|
|
echo "Successfully fetched ${script_name} to ${target}."
|
|
|
|
else
|
|
echo "Failed to fetch ${script_name} from ${gitea_repo}."
|
|
exit 2
|
|
fi
|
|
}
|
|
|
|
fetch "script/fetch_and_execute.sh" "/usr/local/lib/fetch-and-execute.sh"
|
|
|
|
path_to_fetch_script="/usr/local/lib/fetch-and-execute.sh"
|
|
source "$path_to_fetch_script"
|
|
|
|
#fetch_and_execute "script/vm-setup/machine_setup.sh" REPLACE:generic-dev-machine
|