summarylogtreecommitdiffstats
path: root/update.sh
blob: 16dbd1c1b488b280bab7666a96e48a90fd5d7736 (plain)
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
#!/bin/bash

url=$( grep -oP '(?<=url = ).+' .SRCINFO | tr -d "'" )
repo_name=$( echo "$url" | sed -e 's~^https://github.com/~~' -e 's~\.git$~~' )

last_version=$(curl -s "https://api.github.com/repos/${repo_name}/releases/latest" | grep -oP '(?<="tag_name": ")[^"]+')
old_version=$(grep -oP '(?<=^pkgver=).*' ./PKGBUILD)

echo "last pygad version: $last_version"

if [[ $old_version != $last_version ]]; then
	sed -i "s/pkgver=.*/pkgver=$last_version/" PKGBUILD
	if command -v updpkgsums &> /dev/null; then
		updpkgsums
	else
		echo "enter new md5sums: "
		read -r md5sums
		sed -i "s/md5sums=.*/md5sums=('$md5sums')/" PKGBUILD
	fi
	makepkg --printsrcinfo > .SRCINFO

	echo "update $old_version -> $last_version"

	git add PKGBUILD .SRCINFO

	# Read the PKGBUILD file and extract the maintainer's name and contact information
	maintainer_line=$(grep -m1 '^# Maintainer:' PKGBUILD)
	maintainer=${maintainer_line##*Maintainer:}
	# Trim leading and trailing whitespace from the maintainer's name
	maintainer=$(echo "$maintainer" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')

	git commit -m "$old_version -> $last_version : Upgrade package

	This commit upgrades the package from version $old_version to $last_version. This upgrade ensures that users have access to the latest version with the most up-to-date functionality.

	Signed-off-by: $maintainer"

	git --no-pager show
	echo "Do you want to push this commit to the remote repository? (y/n)"
	read -r answer
	if [[ $answer == "y" ]]; then
		git push origin master
		echo "pushed"
	else
		echo "not pushed"


	fi
else
	echo "no updates found"
fi