Skip to content

Commit

Permalink
fixed flatpak
Browse files Browse the repository at this point in the history
  • Loading branch information
ernierasta committed May 4, 2018
1 parent 7881415 commit f4da5ce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 31 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ v0.6:
- added experimental support for flatpak (expect changes here)
- added xbps repository management functions

v0.6.1:
-------

- fixed flatpak
- changed flatpak simple app names to contain last domain part - solves Skype.client vs Spotify.client
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Then open new terminal window.
$ xb add neovim mc
$ xb son sshd
$ xb frepoadd flathub
$ xb fadd blender
$ xb fadd blender.blender
```

For full help run:
Expand All @@ -62,7 +62,7 @@ flatpak interface ... ;-).
- add autoinstall script,

~~- add flatpak support (probably as separate set of commands, flatpak is slower then xbps),~~
- fix short flatpak names (for now skype is there as "client", becouse of: com.skype.Client), test it more.
~~- fix short flatpak names (for now skype is there as "client", because of: com.skype.Client), test it more.~~
- maybe add more commands if needed ...

### Alternatives:
Expand Down
40 changes: 11 additions & 29 deletions xb
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,17 @@ slist() {

# flatpak functions

frepo_and_name_unprotected() {
local search="$1"
local apps="$2"
echo "$apps" | grep -i \\.$search
}

_flist_enumerable_repos(){
flatpak remotes | grep -v no-enumerate | cut -d' ' -f1
flatpak remotes | grep -v no-enumerate | cut -f1
}

# fall_apps will list all availabile flatpak apps
# problem is, if repo has flag: no-enumerate flatpak remote-ls will fail
# we need to find all repos without this flag and enumerate one by one ... yeah this sucks.
# result is cached for an hour. This will make autocompletion usable.
# result is cached for 5 minutes. This will make autocompletion usable.
fall_apps() {
local nocache="$1"
local cachef="/tmp/x-apps.cache"
local cachef="/tmp/xb-apps.cache"
local expire=300 # 5 min

if [ -z $nocache ] && [ -f "$cachef" ] && [ $(expr $(date +%s) - $(date -r "$cachef" +%s)) -le $expire ]; then
Expand All @@ -225,7 +219,7 @@ fall_apps() {
# the same as fall_apps but returns lovercase, friendly names
# we will cache it also
fall_apps_simple() {
local cachef="/tmp/x-appss.cache"
local cachef="/tmp/xb-appss.cache"
local expire=300 # 5 min

if [ -f "$cachef" ] && [ $(expr $(date +%s) - $(date -r "$cachef" +%s)) -le $expire ]; then
Expand All @@ -235,7 +229,7 @@ fall_apps_simple() {
echo > $cachef
apps="$(fall_apps "nocache" | sort -u)" #disable fullname caching
for app in "$apps"; do
echo "$app" | cut -d' ' -f2 | rev | cut -d'.' -f1| rev | tr '[:upper:]' '[:lower:]' | tee -a $cachef
echo "$app" | cut -d' ' -f2 | rev | cut -d'.' -f1,2| rev | tr '[:upper:]' '[:lower:]' | tee -a $cachef
done
fi
}
Expand All @@ -244,7 +238,7 @@ finstalled_apps_simple() {
local apps="$(flatpak list --app)"

for app in "$apps"; do
echo "$app" | cut -d' ' -f1 | rev | cut -d'.' -f1| rev | tr '[:upper:]' '[:lower:]' | cut -d'/' -f1
echo "$app" | cut -d' ' -f1 | rev | cut -d'.' -f1,2| rev | tr '[:upper:]' '[:lower:]' | cut -d'/' -f1
done
}

Expand All @@ -255,13 +249,12 @@ finstalled_apps_simple() {
# echo "$repo $app"
#}

# determine if script is running with sudo, if so, switch back to invoker
# determine if script is running with sudo, if so, switch back to invoker if desired
_run_sudo() {
local command="$1"
local install_as_user="$2"

if [ ! -z "$install_as_user" -a "$(whoami)" != "$(logname)" ]; then
echo "sudo -u $(logname) $command"
sudo -u $(logname) $command
else
$command
Expand All @@ -271,7 +264,7 @@ _run_sudo() {
_mkrunner() {
local runpath="/usr/local/bin"
local appfullname="$1"
local appshortname=$(echo "$appfullname" | rev | cut -d'.' -f1| rev | tr '[:upper:]' '[:lower:]')
local appshortname=$(echo "$appfullname" | rev | cut -d'.' -f1,2| rev | tr '[:upper:]' '[:lower:]')
echo -e "#/bin/bash\nflatpak run $app" > $runpath/$appshortname && \
chmod +x $runpath/$appshortname && \
echo "To run '$appfullname' run: '$appshortname' (runner installed to '/usr/local/bin')"
Expand All @@ -280,16 +273,8 @@ _mkrunner() {
frepo_and_name() {
local search="$1"
local apps="$(fall_apps)"
local count="$(echo "$apps" | grep -ic \\.$search)"

if [ "$count" -gt "1" ]; then
frepo_and_name_unprotected $search "$apps"
echo
echo "ERROR: app name is not precise, returned more then one app."
exit 1
fi

frepo_and_name_unprotected $search "$apps"
echo "$apps" | grep -i \\.$search
}

fname() {
Expand All @@ -313,7 +298,7 @@ fsearch() {
#alternative :
lapps="$(flatpak search "$pk")"
if [ "$lapps" = "No matches found" ]; then
lapps="$(frepo_and_name_unprotected "$pk" "$(fall_apps)")"
lapps="$(frepo_and_name "$pk" "$(fall_apps)")"
if [ ! -z "$lapps" ]; then
echo "INFO: No cache. Run 'fupgrade' for better search."
fi
Expand All @@ -339,10 +324,7 @@ fadd() {

repo_and_app="$(frepo_and_name "$pk")"
app=$(echo "$repo_and_app" | cut -d' ' -f2)

_run_sudo "flatpak install $user$repo_and_app" $user

_mkrunner "$app"
_run_sudo "flatpak install $user$repo_and_app" $user && _mkrunner "$app"
}

fdel() {
Expand Down

0 comments on commit f4da5ce

Please sign in to comment.