feat(default-flatpaks): Make repo configurable

This commit is contained in:
zelikos 2023-10-02 21:03:58 -04:00
parent 634cf88d23
commit 874afef229
No known key found for this signature in database
GPG key ID: AA0CB476ECFA09E7
3 changed files with 60 additions and 8 deletions

View file

@ -18,11 +18,25 @@ if grep -qz 'fedora' <<< $(flatpak remotes); then
flatpak remote-delete fedora --force
fi
# Set up system Flathub if not already installed
flatpak remote-add --if-not-exists --system flathub https://flathub.org/repo/flathub.flatpakrepo
REPO_INFO="/etc/flatpak/system/repo-info.yml"
REPO_URL=$(yq '.repo-url' $REPO_INFO)
REPO_NAME=$(yq '.repo-name' $REPO_INFO)
REPO_TITLE=$(yq '.repo-title' $REPO_INFO)
# In case fedora flatpak repo is already removed, but Flathub was left disabled by mistake
flatpak remote-modify flathub --enable --system --title="Flathub (System)"
# Set up system-wide Flatpak repository
flatpak remote-add --if-not-exists --system $REPO_NAME $REPO_URL
# If configured remote is flathub, enable it here.
# Flathub is already installed on Fedora, but not enabled by default,
# so the above command won't add it again
if [[ $REPO_NAME == "flathub" ]]; then
flatpak remote-modify --system $REPO_NAME --enable
fi
# Change repository title to configured title, if not null
if [[ ! $REPO_TITLE == "null" ]]; then
flatpak remote-modify --system $REPO_NAME --title="$REPO_TITLE"
fi
# Lists of flatpaks
FLATPAK_LIST=$(flatpak list --columns=application)
@ -33,7 +47,7 @@ REMOVE_LIST=$(cat /etc/flatpak/system/remove)
if [[ -n $INSTALL_LIST ]]; then
for flatpak in $INSTALL_LIST; do
if grep -qvz $flatpak <<< $FLATPAK_LIST; then
flatpak install --system --noninteractive flathub $flatpak
flatpak install --system --noninteractive $REPO_NAME $flatpak
fi
done
fi

View file

@ -11,11 +11,23 @@ if [[ -f $VER_FILE && $VER = $VER_RAN ]]; then
exit 0
fi
# Setup Flathub
# Remove Fedora's flatpak repo, if it exists
if grep -qz 'fedora' <<< $(flatpak remotes); then
flatpak remote-delete --user fedora --force
fi
flatpak remote-add --if-not-exists --user flathub https://flathub.org/repo/flathub.flatpakrepo
REPO_INFO="/etc/flatpak/user/repo-info.yml"
REPO_URL=$(yq '.repo-url' $REPO_INFO)
REPO_NAME=$(yq '.repo-name' $REPO_INFO)
REPO_TITLE=$(yq '.repo-title' $REPO_INFO)
# Set up per-user Flatpak repository
flatpak remote-add --if-not-exists --user $REPO_NAME $REPO_URL
# Change repository title to configured title, if not null
if [[ ! $REPO_TITLE == "null" ]]; then
flatpak remote-modify --user $REPO_NAME --title="$REPO_TITLE"
fi
# Lists of flatpaks
FLATPAK_LIST=$(flatpak list --columns=application)
@ -26,7 +38,7 @@ REMOVE_LIST=$(cat /etc/flatpak/user/remove)
if [[ -n $INSTALL_LIST ]]; then
for flatpak in $INSTALL_LIST; do
if grep -qvz $flatpak <<< $FLATPAK_LIST; then
flatpak install --user --noninteractive flathub $flatpak
flatpak install --user --noninteractive $REPO_NAME $flatpak
fi
done
fi

View file

@ -10,8 +10,11 @@ cp -r "$BLING_DIRECTORY"/files/usr/lib/systemd/user/user-flatpak-setup.service /
SYS_INSTALL_LIST=/usr/etc/flatpak/system/install
SYS_REMOVE_LIST=/usr/etc/flatpak/system/remove
SYS_REPO_INFO=/usr/etc/flatpak/system/repo-info.yml
USER_INSTALL_LIST=/usr/etc/flatpak/user/install
USER_REMOVE_LIST=/usr/etc/flatpak/user/remove
USER_REPO_INFO=/usr/etc/flatpak/user/repo-info.yml
echo "Enabling flatpaks module"
systemctl enable system-flatpak-setup.service
@ -20,9 +23,32 @@ mkdir -p /usr/etc/flatpak
get_yaml_array SYSTEM_INSTALL '.system.install[]' "$1"
get_yaml_array SYSTEM_REMOVE '.system.remove[]' "$1"
REPO_URL=$(echo "$1" | yq -I=0 '.system.repo-url')
REPO_NAME=$(echo "$1" | yq -I=0 '.system.repo-name')
REPO_TITLE=$(echo "$1" | yq -I=0 '.system.repo-title')
touch $SYS_REPO_INFO
cat > $SYS_REPO_INFO <<EOF
repo-url: "$REPO_URL"
repo-name: "$REPO_NAME"
repo-title: "$REPO_TITLE"
EOF
get_yaml_array USER_INSTALL '.user.install[]' "$1"
get_yaml_array USER_REMOVE '.user.remove[]' "$1"
REPO_URL=$(echo "$1" | yq -I=0 '.user.repo-url')
REPO_NAME=$(echo "$1" | yq -I=0 '.user.repo-name')
REPO_TITLE=$(echo "$1" | yq -I=0 '.user.repo-title')
touch $USER_REPO_INFO
cat > $USER_REPO_INFO <<EOF
repo-url: "$REPO_URL"
repo-name: "$REPO_NAME"
repo-title: "$REPO_TITLE"
EOF
echo "Creating system Flatpak install list"
if [[ ${#SYSTEM_INSTALL[@]} -gt 0 ]]; then
touch $SYS_INSTALL_LIST