-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·151 lines (125 loc) · 4.43 KB
/
setup.sh
File metadata and controls
executable file
·151 lines (125 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
# ----------------------------------------------------------
# Flatpak Information
# ----------------------------------------------------------
app="com.ml4w.settings"
repo="ml4w-repo"
public_key="ml4w-apps-public-key.asc"
public_key_url="https://mylinuxforwork.github.io/ml4w-flatpak-repo/$public_key"
# ----------------------------------------------------------
# Check if command exists
# ----------------------------------------------------------
_commandExists() {
local package="$1"
if ! type $package >/dev/null 2>&1; then
return 1
else
return 0
fi
}
# ----------------------------------------------------------
# Check if flatpak repo is installed
# ----------------------------------------------------------
_is_flatpak_repo_installed() {
local repo_name="$1"
flatpak_output=$(flatpak remotes)
if [[ $flatpak_output == *"$repo_name"* ]]; then
echo ":: Repo '$repo_name' is already added."
return 0
else
echo ":: Repo '$repo_name' is NOT added."
return 1
fi
}
# ----------------------------------------------------------
# Check if flatpak is already installed in repo
# ----------------------------------------------------------
_is_flatpak_installed() {
if flatpak list --columns=application,origin | grep -qE "^$app\s+$repo$"; then
echo ":: Flatpak '$app' from repository '$repo' is installed."
return 0
else
echo ":: Flatpak '$app' from repository '$repo' is NOT installed."
return 1
fi
}
# ----------------------------------------------------------
# Check if flatpak is user installed
# ----------------------------------------------------------
_is_flatpak_installed_user() {
flatpak_output=$(flatpak list --user --columns=application,origin)
if [[ $flatpak_output == *"$app"* ]]; then
echo ":: Flatpak '$app' is installed for the current user but should be installed system-wide."
echo ":: It will now be uninstalled first."
return 0
else
echo ":: Flatpak '$app' is NOT installed for the current user."
return 1
fi
}
# ----------------------------------------------------------
# Check if flatpak is already installed
# ----------------------------------------------------------
if ! _commandExists "flatpak"; then
echo "ERROR: Please install flatpak first."
exit
fi
# ----------------------------------------------------------
# Check if wget is already installed
# ----------------------------------------------------------
if ! _commandExists "wget"; then
echo "ERROR: Please install wget first."
exit
fi
# ----------------------------------------------------------
# Adding flathub
# ----------------------------------------------------------
if ! _is_flatpak_repo_installed "flathub"; then
sudo flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
fi
# ----------------------------------------------------------
# Adding ml4w-repo
# ----------------------------------------------------------
if ! _is_flatpak_repo_installed "ml4w-repo"; then
echo ":: Downloading Public Key"
if [ ! -d "$HOME/.cache" ]; then
mkdir -p "$HOME/.cache"
fi
if [ -f "$HOME/.cache/$public_key" ]; then
rm "$HOME/.cache/$public_key"
fi
wget -P "$HOME/.cache" "$public_key_url"
if [ ! -f "$HOME/.cache/$public_key" ]; then
echo "ERROR: Download of Public Key failed."
exit
fi
sudo flatpak remote-add --if-not-exists ml4w-repo https://mylinuxforwork.github.io/ml4w-flatpak-repo/ml4w-apps.flatpakrepo --gpg-import=$HOME/.cache/$public_key
fi
# ----------------------------------------------------------
# Cleanup
# ----------------------------------------------------------
if [ -f "$HOME/.cache/$public_key" ]; then
echo ":: Removing public key of $repo"
rm "$HOME/.cache/$public_key"
fi
# ----------------------------------------------------------
# Uninstall app from current user
# ----------------------------------------------------------
if _is_flatpak_installed_user "$app"; then
flatpak uninstall -y --user $app
fi
# ----------------------------------------------------------
# Install app
# ----------------------------------------------------------
if _is_flatpak_installed $app ml4w-repo; then
echo ":: Checking updates for '$app'"
flatpak -y update $app
else
echo ":: Installing $app"
sudo flatpak install -y --reinstall ml4w-repo $app
fi
# ----------------------------------------------------------
# Finishing up
# ----------------------------------------------------------
echo
echo ":: Setup complete. Run the app with 'flatpak run $app'"