Skip to content

Commit d2836da

Browse files
silkehjoebonrichie
authored andcommitted
usysconf-epoch: Add epoch transition service
**Summary** Add the transition service for the epoch. This service installs the new software center and updates the eopkg URL. It then sends a notifcation to the user if possible.
1 parent 441c53d commit d2836da

File tree

5 files changed

+184
-8
lines changed

5 files changed

+184
-8
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=Perform the epoch transition
3+
After=network-online.target
4+
Wants=network-online.target
5+
6+
[Service]
7+
EnvironmentFile=-/etc/sysconfig/epoch
8+
ExecStart=/usr/lib64/usysconf/epoch.sh
9+
Type=oneshot
10+
11+
RemainAfterExit=yes
12+
TimeoutStartSec=60s
13+
14+
[Install]
15+
WantedBy=multi-user.target
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
STATE_DIR="${STATE_DIR:=/var/solus/usr-merge}"
5+
MERGE_FLAG_FILE="${MERGE_FLAG_FILE:=${STATE_DIR}/merge-complete}"
6+
7+
OLD_REPO="https://cdn.getsol.us/repo/shannon/eopkg-index.xml.xz"
8+
NEW_REPO="https://cdn.getsol.us/repo/polaris/eopkg-index.xml.xz"
9+
10+
export LC_ALL=C
11+
12+
declare -A DESKTOP_FLAG_FILES=(
13+
["budgie"]="/usr/bin/budgie-desktop"
14+
["gnome"]="/usr/bin/gnome-shell"
15+
["kde"]="/usr/bin/startplasma-wayland"
16+
["xfce"]="/usr/bin/xfce4-session"
17+
["mate"]="/usr/bin/mate-about"
18+
)
19+
declare -A DESKTOP_SOFTWARE_CENTRE=(
20+
["budgie"]="discover"
21+
["gnome"]="gnome-software"
22+
["kde"]="discover"
23+
["xfce"]="discover"
24+
["mate"]="discover"
25+
)
26+
declare -A SC_DESKTOP_FILES=(
27+
["discover"]="/usr/share/applications/org.kde.discover.desktop"
28+
["gnome-software"]="/usr/share/applications/org.gnome.Software.desktop"
29+
)
30+
31+
function update_repo() {
32+
local repo=""
33+
local active=""
34+
while read -r line
35+
do
36+
if [[ "${repo}" == "" ]]
37+
then
38+
repo="${line% *}"
39+
active="${line##"${repo}" }"
40+
continue
41+
fi
42+
43+
url="${line## }"
44+
if [[ "${url}" == "${OLD_REPO}" ]]
45+
then
46+
echo "Updating repo ${repo} to ${NEW_REPO}"
47+
48+
eopkg add-repo -y "${repo}" "${NEW_REPO}"
49+
50+
if [[ "${active}" == "[inactive]" ]]
51+
then
52+
eopkg disable-repo "${repo}"
53+
fi
54+
fi
55+
56+
repo=""
57+
done <<< "$(eopkg list-repo --no-color)"
58+
}
59+
60+
function is_installed() {
61+
eopkg info --no-color --short "${1}" | grep -P '^\[inst\]' >/dev/null
62+
}
63+
64+
function desktop_name() {
65+
local field
66+
67+
if [[ "$2" != "" ]]
68+
then
69+
field="^Name\[$2\]="
70+
else
71+
field="^Name="
72+
fi
73+
74+
local name
75+
name="$(grep "${field}" "${SC_DESKTOP_FILES[$1]}" | head -n1 || true)"
76+
77+
echo "${name#*=}"
78+
}
79+
80+
function sc_name() {
81+
local name
82+
83+
for lang in "${LANG%.*}" "${LANG%_*}" ""
84+
do
85+
name="$(desktop_name "$1" "${lang}")"
86+
if [[ "${name}" != "" ]]
87+
then
88+
echo "${name}"
89+
return
90+
fi
91+
done
92+
}
93+
94+
# Based on StackOverflow post by Fabio A.
95+
# See https://stackoverflow.com/a/49533938
96+
function _notify-send() {
97+
local user
98+
99+
for bus in /run/user/*/bus
100+
do
101+
user="$(stat -c '%U' "${bus}")"
102+
sudo -u "${user}" env DBUS_SESSION_BUS_ADDRESS="unix:path=$bus" notify-send "$@"
103+
done
104+
}
105+
106+
if [[ ! -e "${MERGE_FLAG_FILE}" ]]
107+
then
108+
echo "Not ready: not usr-merged"
109+
exit 1
110+
fi
111+
112+
if [[ "$(readlink /usr/bin/eopkg)" != "eopkg.bin" ]]
113+
then
114+
echo "Not ready: eopkg is not python3"
115+
exit 1
116+
fi
117+
118+
desktop=""
119+
removed_sc=false
120+
121+
# Install appropriate software centre
122+
for d in "${!DESKTOP_FLAG_FILES[@]}"
123+
do
124+
if [[ -e "${DESKTOP_FLAG_FILES[$d]}" ]]
125+
then
126+
desktop="${d}"
127+
break
128+
fi
129+
done
130+
131+
sc_package="${DESKTOP_SOFTWARE_CENTRE[$desktop]}"
132+
echo "Detected desktop: ${desktop}"
133+
134+
if ! is_installed "${sc_package}"
135+
then
136+
echo "Installing new SC: ${sc_package}"
137+
eopkg install --yes-all "${DESKTOP_SOFTWARE_CENTRE[$desktop]}"
138+
fi
139+
140+
if is_installed solus-sc
141+
then
142+
echo "Removing old SC"
143+
eopkg remove --yes-all solus-sc
144+
removed_sc=true
145+
fi
146+
147+
echo "Checking repository"
148+
update_repo
149+
150+
echo "Finished! Welcome to the new epoch."
151+
if [[ "${removed_sc}" == "true" ]]
152+
then
153+
_notify-send --urgency=critical \
154+
--icon=software \
155+
"Solus Software" \
156+
"Software Center is now '$(sc_name "${sc_package}")'" || true
157+
fi
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
enable usr-merge.service
2+
enable epoch.service
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name : usysconf-epoch
22
version : 1.0.0
3-
release : 17
3+
release : 18
44
source :
55
# We need something for a source
66
- https://getsol.us/sources/hotspot.txt : a12b7cb43c9d9134b5bb1b35e9096b66775d9e92e7611d1cc92b02edd6782a87
@@ -12,10 +12,9 @@ summary : Temporary package for hosting epoch and usr-merge scripts
1212
description: |
1313
Temporary package for hosting the epoch script
1414
install : |
15-
install -Dm00755 $pkgfiles/usr-merge.sh -t $installdir/usr/lib64/usysconf/
15+
install -Dm00755 -t $installdir/usr/lib64/usysconf/ $pkgfiles/*.sh
16+
install -Dm00644 -t $installdir/%libdir%/systemd/system/ $pkgfiles/*.service
1617
17-
# Systemd units to run this early in the boot
18-
install -Dm00644 $pkgfiles/usr-merge.service -t $installdir/%libdir%/systemd/system/
19-
20-
install -Ddm00755 $installdir/%libdir%/systemd/system/sysinit.target.wants
18+
install -Ddm00755 $installdir/%libdir%/systemd/system/{sysinit,multi-user}.target.wants
2119
ln -srv $installdir/%libdir%/systemd/system/usr-merge.service $installdir/%libdir%/systemd/system/sysinit.target.wants/usr-merge.service
20+
ln -srv $installdir/%libdir%/systemd/system/epoch.service $installdir/%libdir%/systemd/system/multi-user.target.wants/epoch.service

packages/u/usysconf-epoch/pspec_x86_64.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@
2020
</Description>
2121
<PartOf>system.base</PartOf>
2222
<Files>
23+
<Path fileType="library">/usr/lib64/systemd/system/epoch.service</Path>
24+
<Path fileType="library">/usr/lib64/systemd/system/multi-user.target.wants/epoch.service</Path>
2325
<Path fileType="library">/usr/lib64/systemd/system/sysinit.target.wants/usr-merge.service</Path>
2426
<Path fileType="library">/usr/lib64/systemd/system/usr-merge.service</Path>
27+
<Path fileType="library">/usr/lib64/usysconf/epoch.sh</Path>
2528
<Path fileType="library">/usr/lib64/usysconf/usr-merge.sh</Path>
2629
</Files>
2730
</Package>
2831
<History>
29-
<Update release="17">
30-
<Date>2024-10-22</Date>
32+
<Update release="18">
33+
<Date>2025-06-29</Date>
3134
<Version>1.0.0</Version>
3235
<Comment>Packaging update</Comment>
3336
<Name>Silke Hofstra</Name>

0 commit comments

Comments
 (0)