Repository navigation
Expand file tree
/
Copy pathprogramsUp.zsh
More file actions
51 lines (44 loc) · 1.84 KB
/
Copy pathprogramsUp.zsh
File metadata and controls
51 lines (44 loc) · 1.84 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
updatePrograms() {
for dir in ~/Programs/*; do
if [[ -d "$dir"/update ]]; then
local metadata=$(cat "$dir"/update/meta)
local owner=$( echo "$metadata" | grep "Owner" | sed 's|Owner:||' )
[[ $owner = "brave" ]] && { echo "use updateBrave"; continue; }
local project=$(echo "$metadata" | grep "Project" | sed 's|Project:||')
local output=$(curl -fsS "https://api.github.com/repos/$owner/$project/releases/latest")
[[ -z "$output" ]] && { echo "no response for $project"; continue; }
local checkVersion=$(jq -r '.tag_name' <<< "$output")
echo "updatable Project : $project"
[[ "$checkVersion" = "null" ]] || [[ -z "$checkVersion" ]] && { echo "couldn't fetch version for $project"; continue; }
local currentVersion=$(echo "$metadata" | grep "Version" | sed 's|Version:||')
[[ "$checkVersion" = "$currentVersion" ]] && { echo "$project is up to date : $checkVersion"; continue; }
while true; do
read "response?$project is on $currentVersion, latest is $checkVersion; do you want to request the latest Version? [y/n]: "
case "$response" in
[Yy])
echo "Updating.."
local name
name=$(echo "$metadata" | grep "AssetName" | sed 's|AssetName:||')
local url=$(jq -r --arg name "$name" '.assets[] | select(.name == $name) | .browser_download_url' <<< "$output")
if [[ -z "$url" ]] || [[ "$url" = "null" ]]; then
echo "couldn't find asset matching $name"
echo "you may need to change asset name version to $checkVersion"
break
fi
if curl -fL -o "$dir/update/$name" "$url" ; then
sed -i "s|Version:.*|Version:$checkVersion|" "$dir"/update/meta
else
echo "Downloading falied"
break
fi
break;;
[Nn])
echo "not Updating"
break;;
*)
echo "choose y or n";;
esac
done
fi
done
}