Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/update
blob: a09b7e7240d183be845b1795a874c5aac6ce69d6 (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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/oksh

BASE="${0%/*}/.."
. "${BASE}/conf/default.conf"

UPATE_UPSTREAM=0
UPDATE_AUR=0
STATS=0
VERBOSE=0
OPTIONS=`getopt -n update -o huasv -l help,upstream,aur,stats,verbose -- "$@"`
if test $? != 0; then
	echo "ERROR: internal error which using getopt.." >&2;
	exit 1
fi
eval set -- "$OPTIONS"
while true; do
	case "$1" in
		-h|--help)
			echo "update [options]"
			echo ""
			echo "-u --upstream  update from update git state and package repo"
			echo "-a --aur       update from the AUR"
			echo "-s --stats     compute and print statistics"
			echo "-v --verbose   be verbose"
			exit 0
			;;

		-u|--uptream)
			UPDATE_UPSTREAM=1
			shift
			;;

		-a|--aur)
			UPDATE_AUR=1
			shift
			;;

		-s|--status)
			STATS=1
			shift
			;;

		-v|--verbose)
			VERBOSE=1
			shift
			;;

		--)
			shift
			break
			;;

		*)
			echo "ERROR: Internal error in getopt" >&2
			exit 1
	esac
done

shift `expr $OPTIND - 1`

if test ! -d "${state_dir}"; then
	echo "no upstream git state repo of packages.. exiting.."
	exit 1
fi

if test ! -d "${packages_dir}"; then
	echo "no directory for uptream package descriptions.. exiting.."
	exit 1
fi

if test ! -d "${aur_state_dir}"; then
	echo "no AUR state directory exists of .. exiting.."
	exit 1
fi

if test "${UPDATE_UPSTREAM}" = 1; then
	echo "Updating main state git repo.."

	git -C "${state_dir}" pull

	find "${state_dir}"/{core,extra}-{any,x86_64} -type f | sort > /tmp/update_packages.$$

	nof_updated_packages=0
	nof_cloned_packages=0
	nof_checked_out_packages=0

	for pkgfile in `cat /tmp/update_packages.$$`; do
		repo=`echo "${pkgfile}" | rev | cut -f 2 -d / | rev`
		OLDIFS="$IFS"
		IFS=" "
		while read pkgname pkgver tag revision; do
			if test "${VERBOSE}" = 1; then
				echo -n "${repo} ${pkgname}"
			fi
			nof_checked_out_packages=`expr ${nof_checked_out_packages} + 1`
			if test ! -d "${packages_dir}/${repo}/${pkgname}"; then
				if test "${VERBOSE}" = 1; then
					echo ".. cloning .."
				fi
				cd "${packages_dir}/${repo}" || exit 1
				pkgctl repo clone --protocol=https "${pkgname}"
				nof_updated_packages=`expr ${nof_updated_packages} + 1`
				sleep 10
			else
				# get all revisions from the package repo, check if
				# we find the state sha in there, if not, do an
				# update of the repo. Doing a full git pull on
				# every update is not acceptable as it creates too
				# much load
				cd "${packages_dir}/${repo}/${pkgname}" || exit 1
				git show-ref --tags > /tmp/update_package_revisions.$$
				grep -F "${revision}" "/tmp/update_package_revisions.$$" 2>&1 >/tmp/update_package_revision_found.$$
				if test $? = 0; then
					if test "${VERBOSE}" = 1; then
						tag=`cat /tmp/update_package_revision_found.$$ | cut -d ' ' -f 2`
						echo ".. ${revision} (${tag}) exists in package history .."
					fi
				else
					if test "${VERBOSE}" = 1; then
						echo ".. updating .."
					fi
					git -C "${packages_dir}/${repo}/${pkgname}" pull
					nof_cloned_packages=`expr ${nof_cloned_packages} + 1`
					sleep 10
				fi
				rm -f /tmp/update_package_revisions.$$ /tmp/update_package_revision_found.$$
			fi
		done < $pkgfile
		IFS="$OLDIFS"
	done

	if test "${STATS}" = 1; then
		echo "Checking statistics.."

		nof_packages=`cat /tmp/update_packages.$$ | wc -l`

		echo "${nof_packages} packages in state repo"
		echo "${nof_checked_out_packages} packages are checked out totally"
		echo "${nof_cloned_packages} packages have been newly cloned"
		echo "${nof_updated_packages} packages have been updated"
	fi
fi

rm -f /tmp/update_packages.$$

if test "${UPDATE_AUR}" = 1; then
	echo "Updating AUR state.."

	rm -f "${aur_state_dir}/packages"
	wget --quiet -O "${aur_state_dir}/packages.gz" https://aur.archlinux.org/packages.gz
	gunzip "${aur_state_dir}/packages.gz"

	if test "${STATS}" = 1; then
		echo "Checking statistics.."

		nof_aur_packages=`wc -l ${aur_state_dir}/packages | cut -f 1 -d ' '`

		echo "${nof_aur_packages} packages in AUR"

		sleep 10
	fi
fi

# TODO: update all single package directories
# TODO: update all AUR package directories