|
| 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 |
0 commit comments