forked from GNOME/gimp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flatpak-releases
executable file
·186 lines (172 loc) · 6.64 KB
/
flatpak-releases
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
# This is a very basic script for developper usage. It has a few known
# limitations (feel free to send patches for these):
# - It is targetted at GIMP usage primarily, hence able to check only
# Flathub (stable and beta remotes) and GNOME-nightly. Yet some
# generity is built-in so you can set your own application ID on
# command line and it should work.
# - It assumes the remotes are named 'flathub', 'flathub-beta' and
# 'gnome-nightly' (for stable, beta and nightly branches respectively)
# as these are the default names proposed by generated .flatpakref
# files (SuggestRemoteName field) when first installing software from
# this repository. So most people will have these remotes registered
# with these names. Yet it could technically be any name locally and
# this script is not verifying this.
# - It also assumes the flathub remotes are installed at all (it can't
# search without them being installed and won't install these for
# you).
# - It uses bash because I lazily didn't bother making it portable as
# it's really just a tool for core dev testing. Yet we of course
# welcome patches if some syntax needs to be rewritten for
# portability.
install=-1
show_runtime=0
appid=org.gimp.GIMP
remote='flathub'
branch='stable'
prefix='--user'
for var in "$@"
do
if [[ $var =~ ^-([0-9]+)$ ]]; then
install=${BASH_REMATCH[1]}
elif [[ $var = '--beta' ]]; then
remote='flathub-beta'
branch='beta'
elif [[ $var = '--nightly' ]]; then
remote='gnome-nightly'
branch='master'
elif [[ $var = '--system' ]]; then
prefix='--system'
elif [[ $var = '--runtime' ]]; then
show_runtime=1
elif [[ $var =~ ^- ]]; then
echo "Usage: ./flathub-releases [--beta] [--system] [-X] [org.example.app]"
echo
echo "List all flatpak builds stored on Flathub or GNOME repository."
echo "The builds for org.gimp.GIMP are looked up by default unless"
echo "you provide explicitely another AppStream ID."
echo
echo "Adding a -X number as option install the numbered release"
echo "instead of listing them."
echo
echo "Options:"
echo
echo "-0: install the last build."
echo "-1: install the previous build."
echo "-2: install the before-previous build (and so on)."
echo "-[0-9]+: and so on..."
echo
echo "--beta: list or install a beta release"
echo "--nightly: list or install a nightly release"
echo
echo "--runtime: list or install runtimes (can be associated with --beta and --nightly)"
echo
echo "--system: install as system flatpak (default to user install)"
echo
echo "Examples:"
echo
echo "* List all beta flatpak bulds:"
echo " flathub-releases --beta"
echo "* Install 2-build old beta flatpak:"
echo "* flathub-releases --beta -2"
echo "* Install the latest beta flatpak:"
echo "* flathub-releases --beta -0"
echo "* List all builds of the runtime used by the beta flatpak:"
echo "* flathub-releases --beta --runtime"
echo "* Install the previous runtime build to be used by the beta flatpak:"
echo "* flathub-releases --beta --runtime -1"
exit 1
else
appid=$var
fi
done
package_info_cmd="flatpak remote-info $remote $appid"
package_info=`$package_info_cmd 2>&1`
got_info="$?"
commit_prefix="app"
if [ "$got_info" -ne 0 ]; then
# By default flatpak will just use either the user or system install
# depending on what it finds. Funnily the command may fail if the
# remote is found not 0 or 1 but 2 times (both on user and system).
# Normally it would interactively ask to choose, but in this specific
# non-interactive case, it would just silently fail instead. So let's
# make a second try on user-installed remote (totally arbitrary
# choice).
user_system="--user"
package_info_cmd="flatpak remote-info $user_system $remote $appid"
package_info=`$package_info_cmd 2>&1`
got_info="$?"
fi
if [ "$got_info" -ne 0 ]; then
echo "Flathub query failed with the following error: $package_info"
exit 2
elif [ "$show_runtime" -eq 1 ]; then
# With the special --runtime option, we list the associated runtime instead of
# the application.
runtime=`echo "$package_info" | grep Runtime: |sed 's/^ *Runtime: //'`
appid=$runtime
# The beta runtime is in the stable repository.
if [[ $branch = 'beta' ]]; then
remote='flathub'
fi
package_info_cmd="flatpak remote-info $user_system $remote $appid//$branch"
package_info=`$package_info_cmd 2>&1`
got_info="$?"
if [ "$got_info" -ne 0 ]; then
if [ -z "$user_system" ]; then
# Do the user/system dance again. Previously we were doing this about the
# main package, not its runtime.
user_system="--user"
package_info_cmd="flatpak remote-info $user_system $remote $appid//$branch"
package_info=`$package_info_cmd 2>&1`
got_info="$?"
fi
if [ "$got_info" -ne 0 ]; then
echo "Flathub query failed with the following error: $package_info"
exit 2
fi
fi
commit_prefix="runtime"
fi
release_number=0
install_commit=
while [ "$got_info" -eq 0 ]
do
release_date=`echo "$package_info" | grep Date: |sed 's/^ *Date: //'`
release_commit=`echo "$package_info" | grep Commit: |sed 's/^ *Commit: //'`
release_subject=`echo "$package_info" | grep Subject: |sed 's/^ *Subject: //'`
if [ "$install" -eq -1 ]; then
# In non-install mode, just list the whole release.
printf "%2d: %s [%s] - $commit_prefix-commit: %s\n" $release_number "$release_subject" "$release_date" "$release_commit"
elif [ "$install" -eq "$release_number" ]; then
install_commit=$release_commit
break
fi
parent_commit=`echo "$package_info" | grep Parent: |sed 's/^ *Parent: //'`
release_number=$(( $release_number + 1 ))
package_info=`$package_info_cmd --commit $parent_commit 2>&1`
got_info="$?"
done
if [ "$install" -ne -1 ]; then
if [ -n "$install_commit" ]; then
# Flatpak doesn't have a way to install directly a commit, but we
# can install then update. This will work whether the flatpak is
# already installed or not.
echo "[1/2] Installing $appid"
flatpak install -y $prefix $remote $appid//$branch
echo "[2/2] Updating to commit '$install_commit' ($release_number's previous build)"
flatpak update -y $prefix --commit=$install_commit $appid//$branch
if [ "$?" -eq 0 ]; then
echo "Build $release_number released on $release_date was installed."
echo "Build subject: $release_subject"
echo "Build commit on $remote: $release_commit"
else
echo "Failure to install build $release_number released on $release_date."
exit 2
fi
else
echo "There was no $release_number's build to install. Aborting."
exit 1
fi
fi
exit 0