Skip to content

Commit 2b987bb

Browse files
committed
Bugfix install procedure. Remove bad \! from printf
that shell tries to expand. Also `type' doesn't seem to work inside a function scope for some reason. So use grep instead, on the tempfile of aliases that we construct from the existing alias file for flatpak packages. Plus, check for installed binary name, so we skip flatpak if the software was installed via package manager.
1 parent 7939fd2 commit 2b987bb

File tree

1 file changed

+42
-38
lines changed

1 file changed

+42
-38
lines changed

machine-setup.sh

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,37 @@
66
#
77

88
apt_install_standard_packages() {
9-
local apt_packages="chromium-browser
10-
curl
11-
emacs26
12-
ffmpeg
13-
flatpak
14-
gawk
15-
git
16-
gnome-tweak-tool
17-
gparted
18-
jq
19-
kazam
20-
openjdk-8-jdk
21-
openjdk-11-jdk
22-
openjdk-14-jdk
23-
postgresql
24-
python3
25-
python3-pip
26-
python3-venv
27-
rlwrap
28-
silversearcher-ag
29-
tmux
30-
vim"
9+
declare -A installed_name_to_apt_package_array=(
10+
[chromium]="chromium-browser"
11+
[curl]="curl"
12+
[emacs26]="emacs26"
13+
[ffmpeg]="ffmpeg"
14+
[flatpak]="flatpak"
15+
[gawk]="gawk"
16+
[git]="git"
17+
[gnome-tweaks]="gnome-tweak-tool"
18+
[gparted]="gparted"
19+
[jq]="jq"
20+
[kazam]="kazam"
21+
[java]="openjdk-8-jdk openjdk-11-jdk openjdk-14-jdk"
22+
[psql]="postgresql"
23+
[python3]="python3"
24+
[pip3]="python3-pip"
25+
[rlwrap]="rlwrap"
26+
[ag]="silversearcher-ag"
27+
[tmux]="tmux"
28+
[vim]="vim"
29+
)
30+
3131
sudo add-apt-repository universe
3232
sudo add-apt-repository multiverse
3333
sudo add-apt-repository -y ppa:kelleyk/emacs
3434
sudo apt-get update
3535

36-
for package in ${apt_packages}
37-
do if ! which ${package} > /dev/null
38-
then sudo apt-get install -y ${package}
36+
for package in "${!installed_name_to_apt_package_array[@]}"
37+
do if which ${package} > /dev/null
38+
then printf "Skipping %s \n" ${package}
39+
else sudo apt-get install -y "${installed_name_to_apt_package_array[${package}]}"
3940
fi
4041
done
4142
}
@@ -75,23 +76,22 @@ flatpak_install_packages_repo_with_restart() {
7576
# - Trigger restart iff first-time configuration.
7677
local remote_name="flathub"
7778
if flatpak remotes --columns=name | grep -q "${remote_name}"
78-
then printf "INFO: About to install packages from %s\n" "${remote_name}"
79-
else printf "INFO: About to add remote with name %s, and RESTART!\n" "${remote_name}"
79+
then printf "INFO: About to install packages from %s.\n" "${remote_name}"
80+
else printf "INFO: About to add remote with name %s.\n" "${remote_name}"
8081
flatpak remote-add --if-not-exists \
8182
"${remote_name}" \
8283
"https://flathub.org/repo/flathub.flatpakrepo"
83-
shutdown -r
8484
fi
8585
}
8686

8787
flatpak_install_packages() {
8888
local flatpak_aliases_file="$HOME/.bash_aliases_flatpak"
89+
8990
declare -A app_alias_to_app_ID_array=(
9091
[bitwarden]="com.bitwarden.desktop"
9192
[bookworm]="com.github.babluboy.bookworm"
9293
[dropbox]="com.dropbox.Client"
9394
[gimp]="org.gimp.GIMP"
94-
[gnome-font-viewer]="org.gnome.font-viewer"
9595
[inkscape]="org.inkscape.Inkscape"
9696
[keepassx]="org.keepassxc.KeePassXC"
9797
[postman]="com.getpostman.Postman"
@@ -107,26 +107,30 @@ flatpak_install_packages() {
107107
__ensure_distinct() { tr -s '\n' | sort | uniq ; }
108108

109109
# set up to update bash aliases file, for flatpak apps
110-
touch "${flatpak_aliases_file}"
110+
touch -m "${flatpak_aliases_file}"
111+
cat /dev/null > "${flatpak_aliases_file}.tmp"
112+
111113
cat "${flatpak_aliases_file}" |
112-
__ensure_distinct > "${flatpak_aliases_file}.tmp"
114+
__ensure_distinct |
115+
tee "${flatpak_aliases_file}.tmp" > /dev/null
113116

114117
# check app alias, and flatpak install if not already apt installed
115118
for app_alias in "${!app_alias_to_app_ID_array[@]}"
116-
do if which ${app_alias} > /dev/null
117-
then printf "Skipping flatpak install of ${app_alias}, because %s.\n" \
118-
"$(type -a ${app_alias})"
119-
else echo "${app_alias_to_app_ID_array[${app_alias}]}"
120-
flatpak install -y flathub "${app_alias_to_app_ID_array[${app_alias}]}"
121-
cat >> "${flatpak_aliases_file}.tmp" <<EOF
119+
do if which "${app_alias}" > /dev/null ||
120+
grep -q -E "${app_alias}" "${flatpak_aliases_file}.tmp"
121+
then printf "Skipping flatpak install of ${app_alias}.\n"
122+
else printf "About to install ${app_alias_to_app_ID_array[${app_alias}]}.\n"
123+
flatpak install -y flathub "${app_alias_to_app_ID_array[${app_alias}]}"
124+
cat >> "${flatpak_aliases_file}.tmp" <<EOF
122125
alias ${app_alias}='flatpak run ${app_alias_to_app_ID_array[${app_alias}]}'
123126
EOF
124127
fi
125128
done
126129

127130
# update bash aliases file, with revised flatpak apps
128131
cat "${flatpak_aliases_file}.tmp" |
129-
__ensure_distinct > "${flatpak_aliases_file}"
132+
__ensure_distinct |
133+
tee "${flatpak_aliases_file}" > /dev/null
130134

131135
# cleanup tmp file
132136
rm "${flatpak_aliases_file}.tmp"

0 commit comments

Comments
 (0)