Skip to content

Commit 3fc1112

Browse files
committed
Install flatpaks as the user
1 parent 0715a6e commit 3fc1112

File tree

5 files changed

+33
-34
lines changed

5 files changed

+33
-34
lines changed

scripts/common/package-management.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,15 @@ function is_flatpak_installed() {
129129

130130
! does_bin_exist 'flatpak' && return 1 # False
131131

132-
if (flatpak list | grep -q "${PACKAGE_NAME}" > /dev/null); then
133-
if [ -z "${PACKAGE_BRANCH}" ]; then
134-
return 0 # True
135-
elif (flatpak list | grep "${PACKAGE_NAME}" | grep -q "${PACKAGE_BRANCH}" > /dev/null); then
136-
return 0 # True
132+
for INSTALLATION_METHOD in 'user' 'system'; do
133+
if (flatpak list | grep -q "${PACKAGE_NAME}" > /dev/null); then
134+
if [ -z "${PACKAGE_BRANCH}" ]; then
135+
return 0 # True
136+
elif (flatpak list | grep "${PACKAGE_NAME}" | grep -q "${PACKAGE_BRANCH}" > /dev/null); then
137+
return 0 # True
138+
fi
137139
fi
138-
fi
140+
done
139141

140142
return 1 # False
141143
}
@@ -290,8 +292,10 @@ function install_flatpak() {
290292

291293
is_flatpak_installed "${PACKAGE}" && return
292294

293-
echo -e " >>> Installing flatpak: \e[0;33m${PACKAGE}\e[0m (${REMOTE})..."
294-
call_flatpak install --user "${REMOTE}" "${PACKAGE}"
295+
local INSTALLATION_METHOD="user"
296+
297+
echo -e " >>> Installing ${INSTALLATION_METHOD} flatpak (${REMOTE}): \e[0;33m${PACKAGE}\e[0m (${REMOTE})..."
298+
call_flatpak install --${INSTALLATION_METHOD} "${REMOTE}" "${PACKAGE}"
295299
}
296300

297301
function install_vscode_package() {

scripts/configure-repositories.sh

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,24 @@ function add_repository {
3535
fi
3636
}
3737

38-
function add_system_flatpak_remote() {
39-
local REMOTE_NAME="${1}"
40-
local REMOTE_URL="${2}"
41-
42-
if ! flatpak remotes | grep -q "^${REMOTE_NAME}\s"; then
43-
echo -e "Adding the \e[0;33m${REMOTE_NAME}\e[0m system flatpak remote..."
44-
update_file_if_distinct "${REPO_DATA_DIR}/flatpak/keys/${REMOTE_NAME}" "${ROOT_VAR_LIB}/flatpak/repo/${REMOTE_NAME}.trustedkeys.gpg"
45-
run_as_su flatpak remote-add --if-not-exists "${REMOTE_NAME}" "${REMOTE_URL}"
46-
fi
47-
}
48-
49-
function add_user_flatpak_remote() {
50-
local REMOTE_NAME="${1}"
51-
local REMOTE_URL="${2}"
52-
53-
if ! flatpak remotes | grep -q "^${REMOTE_NAME}\s"; then
54-
echo -e "Adding the \e[0;33m${REMOTE_NAME}\e[0m user flatpak remote..."
55-
update_file_if_distinct "${REPO_DATA_DIR}/flatpak/keys/${REMOTE_NAME}" "${XDG_DATA_HOME}/flatpak/repo/${REMOTE_NAME}.trustedkeys.gpg"
56-
flatpak remote-add --user --if-not-exists "${REMOTE_NAME}" "${REMOTE_URL}"
38+
function add_flatpak_remote() {
39+
local INSTALLATION_METHOD="${1}"
40+
local REMOTE_NAME="${2}"
41+
local REMOTE_URL="${3}"
42+
43+
if ! flatpak remotes --"${INSTALLATION_METHOD}" | grep -q "^${REMOTE_NAME}$"; then
44+
echo -e "Adding the \e[0;33m${REMOTE_NAME}\e[0m ${INSTALLATION_METHOD} flatpak remote..."
45+
# update_file_if_distinct "${REPO_DATA_DIR}/flatpak/keys/${REMOTE_NAME}" "${XDG_DATA_HOME}/flatpak/repo/${REMOTE_NAME}.trustedkeys.gpg"
46+
flatpak remote-add --"${INSTALLATION_METHOD}" --if-not-exists "${REMOTE_NAME}" "${REMOTE_URL}"
5747
fi
5848
}
5949

6050
if does_bin_exist 'flatpak'; then
61-
add_system_flatpak_remote 'flathub' 'https://flathub.org/repo/flathub.flatpakrepo'
62-
add_system_flatpak_remote 'flathub-beta' 'https://flathub.org/beta-repo/flathub-beta.flatpakrepo'
51+
add_flatpak_remote 'system' 'flathub' 'https://flathub.org/repo/flathub.flatpakrepo'
52+
add_flatpak_remote 'system' 'flathub-beta' 'https://flathub.org/beta-repo/flathub-beta.flatpakrepo'
6353

64-
add_user_flatpak_remote 'flathub' 'https://flathub.org/repo/flathub.flatpakrepo'
65-
add_user_flatpak_remote 'flathub-beta' 'https://flathub.org/beta-repo/flathub-beta.flatpakrepo'
54+
add_flatpak_remote 'user' 'flathub' 'https://flathub.org/repo/flathub.flatpakrepo'
55+
add_flatpak_remote 'user' 'flathub-beta' 'https://flathub.org/beta-repo/flathub-beta.flatpakrepo'
6656
fi
6757

6858
if [ "${DISTRO_FAMILY}" = 'Arch' ]; then

scripts/install-packages.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ if [ "${DESKTOP_ENVIRONMENT}" = 'GNOME' ]; then
674674
install_flatpak 'org.gnome.seahorse.Application'
675675
fi
676676

677-
install_flatpak 'org.bitwarden.desktop'
677+
install_flatpak 'com.bitwarden.desktop'
678678

679679
################
680680
### Settings ###

scripts/uninstall-packages.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ elif [[ "${DISTRO_FAMILY}" == "Debian" ]]; then
1818
yes | run_as_su apt autoremove
1919
fi
2020

21-
does_bin_exist 'flatpak' && call_flatpak uninstall --unused
21+
if does_bin_exist 'flatpak'; then
22+
for INSTALLATION_METHOD in 'user' 'system'; do
23+
echo "Uninstalling unused ${INSTALLATION_METHOD} flatpak dependencies:"
24+
call_flatpak uninstall --"${INSTALLATION_METHOD}" --unused
25+
done
26+
fi
2227

2328
function keep_first_installed_package() {
2429
local FIRST_INSTALLED_PACKAGE=''

scripts/update-package-repositories.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fi
1717

1818
if does_bin_exist 'flatpak'; then
1919
echo -e 'Updating the \e[0;32msystem flatpak remotes\e[0m ...'
20-
run_as_su flatpak update --appstream
20+
run_as_su flatpak --system update --appstream
2121
echo -e 'Updating the \e[0;32muser flatpak remotes\e[0m ...'
2222
flatpak update --user --appstream
2323
fi

0 commit comments

Comments
 (0)