-
Notifications
You must be signed in to change notification settings - Fork 8
/
spotify-easyrpm
executable file
·689 lines (571 loc) · 19.2 KB
/
spotify-easyrpm
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
#!/bin/bash
#
#set -x
V_PRG_NAME="spotify-easyrpm"
V_CONFIG_FILE="${HOME}/.${V_PRG_NAME}"
V_SYS_ARCH="$(uname -i)"
V_PKGNAME="spotify-client"
V_TOPDIR=$(rpm --eval '%{_topdir}')
V_SOURCES_DIR="${V_TOPDIR}/SOURCES"
V_SPECS_DIR="${V_TOPDIR}/SPECS"
V_RPMS_DIR="${V_TOPDIR}/RPMS"
V_BUILDROOT_DIR="${V_TOPDIR}/BUILDROOT"
V_SNAP_EXTRACT_DIR="${V_SOURCES_DIR}/spotify-snap"
SYSTEMD_UNIT_DIR="${HOME}/.local/share/systemd/user"
SYSTEMD_UNIT="${SYSTEMD_UNIT_DIR}/${V_PRG_NAME}.service"
SYSTEMD_TIMER="${SYSTEMD_UNIT_DIR}/${V_PRG_NAME}.timer"
V_LOCAL_REPO="/var/cache/${V_PRG_NAME}"
f_logo() {
clear
cat <<EOF
┌─┐┌─┐┌─┐┌┬┐┬┌─┐┬ ┬ ┌─┐┌─┐┌─┐┬ ┬┬─┐┌─┐┌┬┐
└─┐├─┘│ │ │ │├┤ └┬┘───├┤ ├─┤└─┐└┬┘├┬┘├─┘│││
└─┘┴ └─┘ ┴ ┴└ ┴ └─┘┴ ┴└─┘ ┴ ┴└─┴ ┴ ┴
Version: 3.0.5
EOF
sleep 2
cat <<EOF
Spotify RPM tool for openSUSE / SLE
SUPPORT: https://github.com/megamaced/spotify-easyrpm/issues
MODE: ${V_RUN_MODE}
CHANNEL: ${PREF_CHANNEL}
EOF
}
f_help() {
cat <<EOF
${V_PRG_NAME} is a script which can download the latest Spotify snap package from snapcraft.io
repository and convert it into an RPM. It is also capable of installing, scheduling and storing
the RPMs in a local filesystem repo for installing Spotify updates alongside regular system updates
${V_PRG_NAME}
- Regular prompt based mode to create an RPM and optionally install and create an update schedule
${V_PRG_NAME} --quiet
- Create the RPM
- Install the Spotify RPM
- Set up a daily scheduled update job
- Set up a local filesystem repo
${V_PRG_NAME} --set-channel edge
- Set either "edge" or "stable" version of Spotify client
${V_PRG_NAME} --create-schedule
- If you previously opted out creating an automated update schedule but now desire it
${V_PRG_NAME} --remove-schedule
- Removes the schedule and local repo if present
${V_PRG_NAME} --clean-repo
- Cleans up old versions from the local filesystem repo
EOF
exit 0
}
f_error() {
echo "$1" 1>&2
echo "Please submit bug report to https://github.com/megamaced/spotify-easyrpm/issues"
f_cleanup
exit 1
}
f_cleanup() {
rm "${V_SOURCES_DIR:?}"/*.snap > /dev/null 2>&1
rm -r "${V_SNAP_EXTRACT_DIR}" > /dev/null 2>&1
rm -r "${V_SOURCES_DIR:?}"/"${V_PKGNAME}"* > /dev/null 2>&1
rm -r "${V_BUILDROOT_DIR:?}"/"${V_PKGNAME}"* > /dev/null 2>&1
}
f_root_check() {
if [[ "$(id -u)" == "0" ]]; then
f_error "Do not run as root"
fi
}
f_arch_check() {
if [[ "${V_SYS_ARCH}" == x86_64 ]]; then
V_RPM_ARCH=x86_64
else
f_error "Unsupported architecture. Aborting"
fi
}
f_config() {
if [ -f "${V_CONFIG_FILE}" ]; then
source "${V_CONFIG_FILE}"
else
cat << EOF > "${V_CONFIG_FILE}"
# PREFS
PREF_PROMPT_SCHEDULE=YES
PREF_PROMPT_CHANNEL=YES
PREF_CHANNEL=stable
EOF
source "${V_CONFIG_FILE}"
fi
if [ -z "${PREF_CHANNEL}" ]; then
echo "PREF_CHANNEL=stable" >> "${V_CONFIG_FILE}"
source "${V_CONFIG_FILE}"
fi
if [[ ! "${PREF_CHANNEL}" == "stable" ]] && [[ ! "${PREF_CHANNEL}" == "edge" ]]; then
sed -i "s/\(PREF_CHANNEL=\)\(.*\)/\1stable/" "${V_CONFIG_FILE}"
source "${V_CONFIG_FILE}"
fi
if [ -z "${PREF_PROMPT_CHANNEL}" ]; then
echo "PREF_PROMPT_CHANNEL=YES" >> "${V_CONFIG_FILE}"
source "${V_CONFIG_FILE}"
fi
}
f_release_channel() {
if [[ "${PREF_PROMPT_CHANNEL}" == "YES" ]] && [[ "${V_RUN_MODE}" == "prompt" ]]; then
while true
do
read -rp "Do you wish to download the Spotify stable or edge release (s/e)?" Q_RELEASE_CHANNEL
case $Q_RELEASE_CHANNEL in
s ) sed -i "s/\(PREF_PROMPT_CHANNEL=\)\(.*\)/\1NO/" "${V_CONFIG_FILE}"
sed -i "s/\(PREF_CHANNEL=\)\(.*\)/\1stable/" "${V_CONFIG_FILE}"
source "${V_CONFIG_FILE}"
echo "Use --set-channel option to change it again"
sleep 3
break;;
e ) sed -i "s/\(PREF_PROMPT_CHANNEL=\)\(.*\)/\1NO/" "${V_CONFIG_FILE}"
sed -i "s/\(PREF_CHANNEL=\)\(.*\)/\1edge/" "${V_CONFIG_FILE}"
source "${V_CONFIG_FILE}"
echo "Use --set-channel option to change it again"
sleep 3
break;;
esac
done
fi
V_HTTP_REPO="$(curl -s -H 'Snap-Device-Series: 16' http://api.snapcraft.io/v2/snaps/info/spotify | jq -r '."channel-map"[] | select(.channel.name=='\"$PREF_CHANNEL\"') | .download.url')"
V_HTTP_VERSION="$(curl -s -H 'Snap-Device-Series: 16' http://api.snapcraft.io/v2/snaps/info/spotify | jq -r '."channel-map"[] | select(.channel.name=='\"$PREF_CHANNEL\"') | .version')"
V_HTTP_SNAP="$(basename ${V_HTTP_REPO})"
}
f_download() {
echo "Downloading the latest Spotify snap"
if ! wget -q -P "${V_SOURCES_DIR}"/ "${V_HTTP_REPO}"; then
f_error "Failed to download Spotify. Aborting"
fi
}
f_create_rpmbuild_dirs() {
echo "Creating build dirs in ${V_TOPDIR}"
if ! mkdir -p "${V_TOPDIR}"/{BUILD,BUILDROOT,OTHER,RPMS,SOURCES,SPECS,SRPMS}; then
f_error "Failed to create rpmbuild root. Aborting"
fi
V_RPMBUILD_OWNER_CHECK="$(find "${V_TOPDIR}" -not -user "$(id -u)")"
if [[ ! -z "${V_RPMBUILD_OWNER_CHECK}" ]]; then
echo "Detected some directories / files not owned by you. Fixing ${V_RPMBUILD_OWNER_CHECK}"
for i in ${V_RPMBUILD_OWNER_CHECK}; do
sudo chown "$(id -u)" "$i"
done
fi
if [[ ! -f "${HOME}"/.rpmmacros ]]; then
echo "Creating ${HOME}/.rpmmacros"
cat << EOF >> "${HOME}"/.rpmmacros
# Generated by ${V_PRG_NAME}
%_topdir ${V_TOPDIR}
EOF
fi
}
f_extract_snap() {
echo "Extracting snap and preparing"
unsquashfs -d "${V_SNAP_EXTRACT_DIR}" "${V_SOURCES_DIR}"/"${V_HTTP_SNAP}" || f_error "Failed to extract snap"
mkdir -p "${V_SOURCES_DIR}"/"${V_PKGNAME}"/usr/{share/applications,bin}
mv "${V_SNAP_EXTRACT_DIR}"/usr/share/spotify "${V_SOURCES_DIR}"/"${V_PKGNAME}"/usr/share
mv "${V_SNAP_EXTRACT_DIR}"/usr/bin/spotify "${V_SOURCES_DIR}"/"${V_PKGNAME}"/usr/bin
}
f_script_location_check() {
if [[ ! -f /usr/bin/"${V_PRG_NAME}" ]] || ! diff ${0} /usr/bin/"${V_PRG_NAME}" > /dev/null 2>&1; then
echo "Copying ${V_PRG_NAME} to /usr/bin/${V_PRG_NAME} for the schedule to work"
sudo cp ${0} /usr/bin/"${V_PRG_NAME}"
fi
}
f_schedule_prompt() {
echo "Checking for an existing schedule"
if [[ ! -f "${SYSTEMD_TIMER}" ]]; then
if [[ "${V_RUN_MODE}" == "create-schedule" ]] || [[ "${PREF_PROMPT_SCHEDULE}" != "NO" ]]; then
while true
do
read -rp "Do you wish to set up an automated update schedule (y/n)?" Q_SCHEDULE_ANSWER
case $Q_SCHEDULE_ANSWER in
y ) f_create_repo
f_create_systemd_unit
f_script_location_check
break;;
n ) echo "Ok skipping...If you want to create this in the future just run ${V_PRG_NAME} --create-schedule"
sed -i "s/\(PREF_PROMPT_SCHEDULE=\)\(.*\)/\1NO/" "${V_CONFIG_FILE}"
break;;
esac
done
else
echo "Skipping schedule prompt as you previously opted out"
fi
else
echo "Found existing schedule. Skipping"
f_update_local_repo
fi
}
f_remove_schedule() {
if [[ -f "${SYSTEMD_UNIT}" ]]; then
echo "Removing ${V_PRG_NAME} from your systemd unit files"
systemctl --user disable spotify-easyrpm
rm "${SYSTEMD_UNIT}"
systemctl --user daemon-reload
fi
if [[ -f "${SYSTEMD_TIMER}" ]]; then
echo "Removing ${V_PRG_NAME} from your systemd timers"
systemctl --user disable spotify-easyrpm.timer
rm "${SYSTEMD_TIMER}"
systemctl --user daemon-reload
fi
}
f_remove_repo() {
if [[ -f /etc/zypp/repos.d/${V_PRG_NAME}.repo ]]; then
echo "Removing ${V_PRG_NAME} zypper repo"
sudo zypper rr "${V_PRG_NAME}"
fi
if [[ -d "${V_LOCAL_REPO}" ]]; then
echo "Removing ${V_PRG_NAME} repo from filesystem"
sudo rm -r "${V_LOCAL_REPO}"
fi
}
f_install_build_deps() {
if ! rpm -q rpm-build > /dev/null 2>&1; then
echo "Installing build dependencies (rpm-build)"
if ! sudo zypper --non-interactive in rpm-build; then
f_error "Failed to install build dependencies (rpm-build). Aborting"
fi
fi
if ! rpm -q update-desktop-files > /dev/null 2>&1; then
echo "Installing build dependencies (update-desktop-files)"
if ! sudo zypper --non-interactive in update-desktop-files; then
f_error "Failed to install build dependencies (update-desktop-files). Aborting"
fi
fi
if ! rpm -q squashfs > /dev/null 2>&1; then
echo "Installing build dependencies (squashfs)"
if ! sudo zypper --non-interactive in squashfs; then
f_error "Failed to install build dependencies (squashfs). Aborting"
fi
fi
if ! rpm -q jq > /dev/null 2>&1; then
echo "Installing build dependencies (jq)"
if ! sudo zypper --non-interactive in jq; then
f_error "Failed to install build dependencies (jq). Aborting"
fi
fi
}
f_prepare_src() {
echo "Preparing RPM src tarball"
f_desktop_entry
tar czf "${V_SOURCES_DIR}"/"${V_PKGNAME}"-"${V_HTTP_VERSION}".tar.gz -C "${V_SOURCES_DIR}"/ "${V_PKGNAME}"
}
f_desktop_entry() {
cat << EOF > "${V_SOURCES_DIR}"/"${V_PKGNAME}"/usr/share/applications/spotify.desktop
[Desktop Entry]
Name=Spotify
GenericName=Music Player
Comment=Spotify streaming music client
Icon=/usr/share/spotify/icons/spotify-linux-64.png
Exec=spotify %U
TryExec=spotify
Terminal=false
Type=Application
Categories=Audio;Music;Player;AudioVideo;
MimeType=x-scheme-handler/spotify;
EOF
}
f_ver_compare() {
V_HTTP_VERSION_NUM="$( echo ${V_HTTP_VERSION} | sed 's/\.[^.]*$//' | sed 's/\.//g' )"
V_INSTALL_VERSION_NUM="$( rpm -q "${V_PKGNAME}" | cut -f3 -d"-" | sed 's/\.[^.]*$//' | sed 's/\.//g' )"
declare -a V_REPO_VERSION_NUMS="$( find ${V_LOCAL_REPO} -type f -name "*.rpm" | sort | cut -f4 -d"-" | sed 's/\.[^.]*$//' | sed 's/\.//g' )"
echo "Comparing snapcraft.io repo version to installed or local machine repo version (if any)"
for V_REPO_VERSION_NUM in ${V_REPO_VERSION_NUMS[@]}; do
if [[ $V_HTTP_VERSION_NUM == $V_REPO_VERSION_NUM ]] || [[ $V_HTTP_VERSION_NUM -lt $V_REPO_VERSION_NUM ]]; then
V_MATCHEDVERSION=TRUE
break
fi
done
if [[ $V_HTTP_VERSION_NUM == $V_INSTALL_VERSION_NUM ]]; then
V_MATCHEDVERSION=TRUE
fi
if [[ "${V_MATCHEDVERSION}" == "TRUE" ]]; then
if [[ "${V_RUN_MODE}" != "prompt" ]]; then
echo "${V_PKGNAME} ${V_HTTP_VERSION} is already installed or available from local machine repo. Quitting"
f_cleanup
exit 0
else
while true
do
echo "The latest $PREF_CHANNEL version at snapcraft.io is ${V_HTTP_VERSION} which is already installed or available from local machine repo. "
read -rp "Continue anyway? (y/n)" Q_SAME_VER_CONTINUE
case $Q_SAME_VER_CONTINUE in
y ) echo "ok"
break;;
n ) f_schedule_prompt
f_cleanup
echo "bye"
exit;;
esac
done
fi
fi
}
f_rpm_spec() {
echo "Writing new build file"
cat << EOF > "${V_SPECS_DIR}"/spotify.spec
#
# spec file for package ${V_PKGNAME}
#
# Copyright (c) 2018 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
Name: ${V_PKGNAME}
Version: ${V_HTTP_VERSION}
Release: 0
License: https://www.spotify.com/legal/end-user-agreement
Summary: Spotify streaming music client
Vendor: Spotify AB
Url: https://www.spotify.com
Source: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: update-desktop-files
Requires: libasound2
Requires: libatk-bridge-2_0-0
Requires: libatomic1
Requires: libcurl4
Requires: libgbm1
Requires: libglib-2_0-0
Requires: libgtk-3-0
Requires: mozilla-nss
%if 0%{?sle_version} <= 150000 && 0%{?is_opensuse} || 0%{?sle_version} <= 150000 && !0%{?is_opensuse}
Requires: libopenssl1_0_0
%else
Requires: libopenssl1_1
%endif
Requires: libxshmfence1
Requires: libXss1
Requires: libXtst6
Requires: xdg-utils
Requires: libayatana-appindicator3-1
Recommends: libavcodec.so
Recommends: libavformat.so
Suggests: libnotify4
AutoReq: no
%description
The Spotify desktop client unofficially supports Linux, meaning that there is a
native client for Linux but we do not offer official support for client-related
problems on this platform. If you are having severe problems with the native
Linux client, there are a few alternatives that you can try:
- Using the web player: https://play.spotify.com (requires Adobe Flash plugin)
- Running the native Windows client in Wine (not recommended, but should work)
Otherwise, the native Linux client is the recommended way to listen to Spotify
on Linux systems.
%prep
%setup -q -n %{name}
%install
mkdir -p %{buildroot}%{_prefix}
cp -r usr %{buildroot}/
%post
%desktop_database_post
if [[ ! -f %{_libdir}/libcurl-gnutls.so.4 ]]; then
ln -s %{_libdir}/libcurl.so.4 %{_libdir}/libcurl-gnutls.so.4
fi
%postun
%desktop_database_postun
%clean
%files
%defattr(-,root,root)
%dir %{_datadir}/spotify
%{_datadir}/spotify/*
%{_datadir}/applications/spotify.desktop
%{_bindir}/spotify
EOF
}
f_run_build() {
echo "Running rpm build"
if ! rpmbuild -bb --quiet --clean "${V_SPECS_DIR}"/spotify.spec; then
f_error "Spotify RPM failed to build. Aborting"
else
echo "Spotify RPM created in ${V_RPMS_DIR}/${V_RPM_ARCH}/"
fi
}
f_install_prompt() {
if [[ "${V_RUN_MODE}" != "prompt" ]]; then
f_rpm_install
else
while true
do
read -rp "Do you wish to install the Spotify RPM (y/n)?" Q_RPM_INSTALL
case $Q_RPM_INSTALL in
y ) f_rpm_install
break;;
n ) echo "OK not installing now"
break;;
esac
done
fi
}
f_rpm_install() {
echo "Installing ${V_PKGNAME}-${V_HTTP_VERSION}"
if ! sudo zypper --non-interactive --no-gpg-checks in "${V_RPMS_DIR}"/"${V_RPM_ARCH}"/"${V_PKGNAME}"-"${V_HTTP_VERSION}"*"${V_RPM_ARCH}".rpm; then
f_error "Failed to install ${V_PKGNAME}-${V_HTTP_VERSION}"
fi
}
f_create_repo() {
if ! rpm -q createrepo_c > /dev/null 2>&1; then
echo "Installing CreateRepo for local filesystem repo"
if ! sudo zypper --non-interactive in createrepo_c; then
f_error "Failed to install createrepo. Aborting"
fi
fi
if [[ ! -d "${V_LOCAL_REPO}" ]]; then
echo "Creating local filesystem repo at ${V_LOCAL_REPO}"
if ! sudo mkdir -p ${V_LOCAL_REPO}; then
f_error "Failed to create local filesystem repo at ${V_LOCAL_REPO}. Aborting"
fi
fi
if ! sudo find ${V_LOCAL_REPO} -type d -exec chmod 777 {} \+; then
f_error "Failed to chmod ${V_LOCAL_REPO}"
fi
if ! sudo find ${V_LOCAL_REPO} -type f -exec chmod 666 {} \+; then
f_error "Failed to chmod ${V_LOCAL_REPO}"
fi
f_update_local_repo
if [[ ! -f /etc/zypp/repos.d/${V_PRG_NAME}.repo ]]; then
echo "Adding local file system repository to zypper"
if ! sudo zypper ar -G --refresh "${V_LOCAL_REPO}" "${V_PRG_NAME}"; then
f_error "Failed to add local repo to zypper. Aborting"
fi
fi
}
f_create_systemd_unit() {
if [[ ! -f "${SYSTEMD_TIMER}" ]]; then
echo "Creating automated Spotify builds"
mkdir -p "${SYSTEMD_UNIT_DIR}"
cat << EOF > "${SYSTEMD_UNIT}"
[Unit]
Description=${V_PRG_NAME} script
[Service]
ExecStart=/usr/bin/${V_PRG_NAME} --scheduled
EOF
cat << EOF > "${SYSTEMD_TIMER}"
[Unit]
Description=${V_PRG_NAME} timer
[Timer]
OnBootSec=5min
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
EOF
sed -i "s/\(PREF_PROMPT_SCHEDULE=\)\(.*\)/\1YES/" "${V_CONFIG_FILE}"
fi
systemctl --user daemon-reload
systemctl --user disable "${V_PRG_NAME}"
systemctl --user enable "${V_PRG_NAME}.timer"
}
f_update_local_repo() {
if [[ "${V_RUN_MODE}" != "clean-repo" ]]; then
echo "Moving any Spotify RPMs from your rpmbuild ${V_RPMS_DIR} to your local repo ${V_LOCAL_REPO}"
find "${V_RPMS_DIR}"/"${V_RPM_ARCH}"/ -name "${V_PKGNAME}-*${V_RPM_ARCH}.rpm" -type f -exec mv -t "${V_LOCAL_REPO}" {} \+
fi
if ! createrepo -q "${V_LOCAL_REPO}"; then
f_error "Failed to create / update local repo. Aborting"
fi
}
f_clean_repo() {
sudo find "${V_LOCAL_REPO}" -type f -name "*.rpm" -exec rm {} \;
f_update_local_repo
echo "done!"
}
f_set_channel() {
sed -i "s/\(PREF_CHANNEL=\)\(.*\)/\1$PREF_CHANNEL/" "${V_CONFIG_FILE}"
sed -i "s/\(PREF_PROMPT_CHANNEL=\)\(.*\)/\1NO/" "${V_CONFIG_FILE}"
echo "done!"
}
f_main() {
while [ "$1" != "" ]; do
case "$1" in
-h | --help ) V_RUN_MODE="help"
f_logo
f_help
exit 0
;;
--quiet ) V_RUN_MODE="quiet"
f_logo
f_install_build_deps
f_create_rpmbuild_dirs
f_release_channel
f_ver_compare
f_download
f_extract_snap
f_prepare_src
f_rpm_spec
f_run_build
f_install_prompt
f_create_repo
f_create_systemd_unit
f_script_location_check
break
;;
--scheduled | -scheduled ) V_RUN_MODE="scheduled"
f_release_channel
f_ver_compare
f_download
f_extract_snap
f_prepare_src
f_rpm_spec
f_run_build
f_update_local_repo
break
;;
--create-schedule ) V_RUN_MODE="create-schedule"
f_logo
f_schedule_prompt
break
;;
--remove-schedule ) V_RUN_MODE="remove-schedule"
f_logo
f_remove_schedule
f_remove_repo
break
;;
--clean-repo ) V_RUN_MODE="clean-repo"
f_logo
f_clean_repo
break
;;
--set-channel ) V_RUN_MODE="set-channel"
shift
PREF_CHANNEL="$1"
f_logo
f_set_channel
break
;;
* ) V_RUN_MODE="invalid"
f_logo
echo "Unrecognised option. Run --help for more info"
exit 1
esac
shift
done
if [[ -z "${V_RUN_MODE}" ]]; then
V_RUN_MODE="prompt"
f_logo
f_install_build_deps
f_create_rpmbuild_dirs
f_release_channel
f_ver_compare
f_download
f_extract_snap
f_prepare_src
f_rpm_spec
f_run_build
f_install_prompt
f_schedule_prompt
fi
}
### EXECUTION BEGINS ###
f_root_check
f_arch_check
f_config
f_cleanup
f_main "$@"
f_cleanup