Skip to content

Commit faad7a9

Browse files
authored
Merge pull request #809 from ivan-hc/dev
Add common installer for both "AM" and "AppMan"
2 parents d4dca84 + 3873e3b commit faad7a9

File tree

4 files changed

+165
-84
lines changed

4 files changed

+165
-84
lines changed

AM-INSTALLER

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
_away_error() {
6+
${1} >/dev/null 2>&1
7+
}
8+
9+
_away_all() {
10+
${1} >/dev/null
11+
}
12+
13+
# Colors
14+
RED='\033[0;31m'; LightBlue='\033[1;34m'; Green='\033[0;32m'
15+
16+
_check_dependency() {
17+
program="$1"
18+
_away_all command -v "$program" || { echo "For Installation to work, install \"$program\" first!" && exit 1; }
19+
}
20+
21+
_check_dependency 'wget'
22+
_check_dependency 'curl'
23+
24+
# INSTALL "AM" SYSTEM-WIDE
25+
_install_am() {
26+
CACHEDIR="${XDG_CACHE_HOME:-$HOME/.cache}"
27+
mkdir -p "$CACHEDIR" || true
28+
rm -f "$CACHEDIR"/INSTALL-AM.sh || true
29+
wget -q https://raw.githubusercontent.com/ivan-hc/AM/main/INSTALL -O "$CACHEDIR"/INSTALL-AM.sh && chmod a+x "$CACHEDIR"/INSTALL-AM.sh
30+
sudo "$CACHEDIR"/INSTALL-AM.sh && rm -f "$CACHEDIR"/INSTALL-AM.sh
31+
}
32+
33+
# INSTALL "AM" LOCALLY, AS "APPMAN"
34+
_install_appman() {
35+
ZSHRC="${ZDOTDIR:-$HOME}/.zshrc"
36+
BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
37+
mkdir -p "$BINDIR"
38+
if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then
39+
echo '--------------------------------------------------------------------------'
40+
echo " Adding $BINDIR to PATH, you might need to"
41+
echo " close and reopen the terminal for this to take effect."
42+
if [ -e ~/.bashrc ] && ! grep 'PATH="$PATH:$BINDIR"' ~/.bashrc >/dev/null 2>&1; then
43+
printf '\n%s\n' 'BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"' >> ~/.bashrc
44+
printf '\n%s\n' 'if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then' >> ~/.bashrc
45+
printf ' PATH="$PATH:$BINDIR"\nfi\n' >> ~/.bashrc
46+
fi
47+
if [ -e "$ZPROFILE" ] && ! grep 'PATH="$PATH:$BINDIR"' "$ZSHRC" >/dev/null 2>&1; then
48+
printf '\n%s\n' 'BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"' >> "$ZSHRC"
49+
printf '\n%s\n' 'if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then' >> "$ZSHRC"
50+
printf ' PATH="$PATH:$BINDIR"\nfi\n' >> "$ZSHRC"
51+
fi
52+
fi
53+
wget -q https://raw.githubusercontent.com/ivan-hc/AM/main/APP-MANAGER -O "$BINDIR"/appman && chmod a+x "$BINDIR"/appman
54+
}
55+
56+
# CHOOSE BETWEEN "AM" AND "APPMAN"
57+
printf " Choose how to install \"AM\" and all its managed applications.
58+
59+
1) As \"${RED}AM\033[0m\", command \"${Green}am\033[0m\", this is a system-wide installation:
60+
- the command is a symlink /usr/local/bin/am for /opt/am/APP-MANAGER
61+
- all programs will be installed in /opt, into dedicated directories
62+
- a \"sudo\" password is required both here and to install/remove apps
63+
- you are the one with read-write permissions for \"AM\" and all programs
64+
- other users can only use programs you have installed, nothing else
65+
- other users can still use \"AppMan mode\" for their rootless configurations
66+
67+
2) As \"${LightBlue}AppMan\033[0m\", command \"${Green}appman\033[0m\", local installation:
68+
- the command is the script ~/.local/bin/appman
69+
- choose wherever you want to install all the apps, in your HOME
70+
- no \"sudo\" required at all
71+
- you can replicate your configurations on every system you want
72+
- more storage space required, if more users use \"AppMan\"
73+
74+
"
75+
read -r -p "Choose between \"AM\" (type 1) and \"AppMan\" (2), or leave blank to exit: " response
76+
case "$response" in
77+
1) _install_am || exit 1
78+
;;
79+
2) _install_appman || exit 1
80+
echo '--------------------------------------------------------------------------'
81+
printf " ${Green}\"AppMan\" has been successfully installed!\033[0m\n"
82+
printf " Please, run \"${LightBlue}appman -h\033[0m\" to see the list of the options.\n"
83+
echo '--------------------------------------------------------------------------'
84+
;;
85+
''|*) echo "Installation aborted, exiting." && exit 1
86+
;;
87+
esac

APP-MANAGER

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
AMVERSION="7.3"
3+
AMVERSION="7.4"
44

55
# Determine main repository and branch
66
AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main"

INSTALL

Lines changed: 61 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -14,100 +14,78 @@ currentuser=$(who | awk '{print $1}')
1414

1515
_check_dependency() {
1616
program="$1"
17-
_away_all command -v "$program" && return 0 || echo "For Installation to work, install \"$program\" first!" && exit 1
17+
_away_all command -v "$program" && return 0 || printf "${RED}WARNING: For Installation to work, install \"$program\" first!\033[0m\n" && exit 1
1818
}
1919

2020
_check_dependency 'wget'
2121
_check_dependency 'curl'
2222

23-
# CREATING THE MAIN DIRECTORY FOR "AM"
24-
mkdir -p /opt/am/.cache /opt/am/modules || exit 1
25-
cd /opt/am || exit 1
23+
# Colors
24+
RED='\033[0;31m'; LightBlue='\033[1;34m'; Green='\033[0;32m'
2625

27-
# CREATE THE SCRIPT NEEDED TO UNINSTALL "AM"
28-
printf '#!/bin/sh\n\nset -e\n' > /opt/am/remove
29-
printf '\n%s\n' 'if [ "$(id -u)" -ne 0 ]; then echo "Permission denied"; exit 1; fi' >> /opt/am/remove
30-
printf '%s\n' 'rm -f /usr/local/bin/am /etc/bash_completion.d/am-completion.sh' >> /opt/am/remove
31-
printf '%s\n' 'rm -R -f /opt/am' >> /opt/am/remove
32-
chmod a+x /opt/am/remove || exit 1
26+
# INSTALL "AM"
27+
_prepare_am_directory() {
28+
# CREATE AND ENTER THE MAIN DIRECTORY FOR "AM"
29+
mkdir -p /opt/am/.cache /opt/am/modules /usr/local/bin && cd /opt/am || exit 1
3330

34-
# DOWNLOAD THE MAIN SCRIPT
35-
wget -q https://raw.githubusercontent.com/ivan-hc/AM/main/APP-MANAGER
36-
chmod a+x /opt/am/APP-MANAGER || exit 1
31+
# CREATE THE SCRIPT NEEDED TO UNINSTALL "AM"
32+
printf '#!/bin/sh\n\nset -e\n' > /opt/am/remove
33+
printf '\n%s\n' 'if [ "$(id -u)" -ne 0 ]; then echo "Permission denied"; exit 1; fi' >> /opt/am/remove
34+
printf '%s\n' 'rm -f /usr/local/bin/am /etc/bash_completion.d/am-completion.sh' >> /opt/am/remove
35+
printf '%s\n' 'rm -R -f /opt/am' >> /opt/am/remove
36+
chmod a+x /opt/am/remove || exit 1
3737

38-
# LINK THE MAIN SCRIPT TO A KNOWN PATH
39-
ln -s /opt/am/APP-MANAGER /usr/local/bin/am || echo "WARNING: Something went wrong!"
38+
# DOWNLOAD AND LINK THE MAIN SCRIPT
39+
wget -q https://raw.githubusercontent.com/ivan-hc/AM/main/APP-MANAGER
40+
chmod a+x /opt/am/APP-MANAGER
41+
ln -s /opt/am/APP-MANAGER /usr/local/bin/am 2> /dev/null || printf "${RED}WARNING: Couldn't link am to \"/usr/local/bin/am\"!\033[0m\n"
4042

41-
# DOWNLOAD THE LIST OF THE AVAILABLE PROGRAMS
42-
wget -q "https://raw.githubusercontent.com/ivan-hc/AM/main/programs/$arch-apps" || exit 1
43+
# DOWNLOAD THE LIST OF THE AVAILABLE PROGRAMS
44+
wget -q "https://raw.githubusercontent.com/ivan-hc/AM/main/programs/$arch-apps" || exit 1
45+
}
4346

44-
# DOWNLOAD MODULES
45-
MODULES=$(curl -Ls https://api.github.com/repos/ivan-hc/AM/contents/modules | sed 's/[()",{}]/ /g; s/ /\n/g' | grep -o 'https.*raw.*modules.*am$' | grep -v "sync\|update")
46-
for module in $MODULES; do
47-
for v in $module; do
48-
cd /opt/am/modules || exit
49-
mkdir -p tmp
50-
cd tmp || exit
51-
wget -q "$v"
52-
cd ..
53-
mv tmp/*.am ./
54-
chmod a+x ./*.am
55-
rmdir tmp
47+
_download_am_modules() {
48+
# DOWNLOAD MODULES
49+
cd /opt/am/modules || exit
50+
MODULES=$(curl -Ls https://api.github.com/repos/ivan-hc/AM/contents/modules | sed 's/[()",{}]/ /g; s/ /\n/g' | grep -o 'https.*raw.*modules.*am$' | grep -v "sync\|update")
51+
for v in $MODULES; do
52+
MODULENAME=$(echo "$v" | sed 's:.*/::')
53+
if ! test -f ./"$MODULENAME"; then
54+
echo " ◆ Downloading $MODULENAME..."
55+
wget -q "$v"
56+
chmod a+x ./"$MODULENAME"
57+
fi
5658
done
57-
done
58-
59-
# ENABLE NON-ROOT PERMISSIONS TO THE MAIN DIRECTORY FOR THE CURRENT USER
60-
chown -R $currentuser /opt/am 2> /dev/null
61-
62-
# ADD THE BASH COMPLETION SCRIPT
63-
echo '#!/usr/bin/env bash
64-
complete -W "$(cat /opt/am/list 2>/dev/null)" am' >> /opt/am/am-completion.sh
65-
chmod a+x /opt/am/am-completion.sh
66-
67-
if test -f /etc/bash_completion.d; then
68-
mv /opt/am/am-completion.sh /etc/bash_completion.d/
69-
else
70-
mkdir -p /etc/bash_completion.d
71-
sudo mv /opt/am/am-completion.sh /etc/bash_completion.d/
72-
fi
73-
74-
# SHOW THE MESSAGE
75-
echo '
76-
_____ _____
77-
/\ \ /\ \ A A
78-
/::\ \ /::\____\ P M
79-
/::::\ \ /::::| | P
80-
/::::::\ \ /:::::| | M &
81-
/:::/\:::\ \ /::::::| | A
82-
/:::/__\:::\ \ /:::/|::| | N
83-
/::::\ \:::\ \ /:::/ |::| |
84-
/::::::\ \:::\ \ /:::/ |::|___|______
85-
/:::/\:::\ \:::\ \ /:::/ |::::::::\ \
86-
/:::/ \:::\ \:::\____\/:::/ |:::::::::\____\
87-
\::/ \:::\ /:::/ /\::/ / ~~~~~/:::/ /
88-
\/____/ \:::\/:::/ / \/____/ /:::/ /
89-
\::::::/ / /:::/ /
90-
\::::/ / /:::/ /
91-
/:::/ / /:::/ /╔═╗╔╗╔┌─┐┌─┐┌─┐┬─┐
92-
/:::/ / /:::/ / ╠═╣║║║├─┤│ ┬├┤ ├┬┘
93-
/:::/ / /:::/ / ╩ ╩╝╚╝┴ ┴└─┘└─┘┴└─
94-
/:::/ /╔═╗╔═╗┬ ┬┌─┐┌─┐┌┬┐┬┌─┐┌┐┌
95-
\::/ / ╠═╝╠═╝│ ││ ├─┤ │ ││ ││││
96-
\/____/ ╩ ╩ ┴─┘┴└─┘┴ ┴ ┴ ┴└─┘┘└┘ by Ivan Alex HC
97-
98-
>> 𝘋𝘢𝘵𝘢𝘣𝘢𝘴𝘦 & 𝘴𝘰𝘭𝘶𝘵𝘪𝘰𝘯𝘴 𝘧𝘰𝘳 𝘢𝘭𝘭 𝘈𝘱𝘱𝘐𝘮𝘢𝘨𝘦𝘴 𝘢𝘯𝘥 𝘱𝘰𝘳𝘵𝘢𝘣𝘭𝘦 𝘢𝘱𝘱𝘴 𝘧𝘰𝘳 𝘎𝘕𝘜/𝘓𝘪𝘯𝘶𝘹 <<
59+
cd ..
9960

100-
##########################################################################
101-
__________________________________________________________________________
102-
103-
SITE: https://portable-linux-apps.github.io
104-
105-
REPOSITORY: https://github.com/ivan-hc/AM
106-
__________________________________________________________________________
107-
108-
##########################################################################
61+
# ENABLE NON-ROOT PERMISSIONS TO THE MAIN DIRECTORY FOR THE CURRENT USER
62+
chown -R $currentuser /opt/am 2> /dev/null
63+
}
10964

110-
Run "am -h" to see the list of the options
111-
##########################################################################
112-
'
65+
_enable_bash_completion() {
66+
# ADD THE BASH COMPLETION SCRIPT
67+
echo '#!/usr/bin/env bash' > /opt/am/am-completion.sh
68+
echo 'complete -W "$(cat /opt/am/list 2>/dev/null)" am' >> /opt/am/am-completion.sh
69+
chmod a+x /opt/am/am-completion.sh
70+
71+
if test -f /etc/bash_completion.d; then
72+
mv /opt/am/am-completion.sh /etc/bash_completion.d/
73+
else
74+
mkdir -p /etc/bash_completion.d
75+
sudo mv /opt/am/am-completion.sh /etc/bash_completion.d/
76+
fi
77+
}
11378

79+
echo '--------------------------------------------------------------------------'
80+
printf " ${Green}Installing \"AM\" in /opt/am\033[0m\n"
81+
_prepare_am_directory
82+
echo '--------------------------------------------------------------------------'
83+
printf " ${Green}Installing modules\033[0m\n"
84+
_download_am_modules
85+
echo '--------------------------------------------------------------------------'
86+
printf " ${Green}Enable bash completion\033[0m\n"
87+
_enable_bash_completion
88+
echo '--------------------------------------------------------------------------'
89+
printf " ${Green}\"AM\" has been successfully installed!\033[0m\n"
90+
printf " Please, run \"${LightBlue}am -h\033[0m\" to see the list of the options.\n"
91+
echo '--------------------------------------------------------------------------'

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,20 @@ This section explains how to install "AM" or "AppMan".
253253

254254
If you don't know the difference, please read "[Differences between "AM" and "AppMan"](#differences-between-am-and-appman)" first.
255255

256+
You can choose to continue reading and see the installation methods in detail (jump to "[Core dependences](#core-dependences)"), or you can choose to use the common installer for "AM" and "AppMan", named "[AM-INSTALLER](https://github.com/ivan-hc/AM/blob/main/AM-INSTALLER)", by downloading the script and making it executable, like this:
257+
```
258+
wget -q https://raw.githubusercontent.com/ivan-hc/AM/main/AM-INSTALLER
259+
chmod a+x ./AM-INSTALLER
260+
./AM-INSTALLER
261+
```
262+
Type "1" to install "AM" (requires "sudo" password), "2" to install "AppMan". Any other key will abort the installation.
263+
264+
| ![AM-INSTALLER](https://github.com/user-attachments/assets/82b21979-e99d-4bee-b466-716bac1e7e45) |
265+
| - |
266+
267+
This "[AM-INSTALLER](https://github.com/ivan-hc/AM/blob/main/AM-INSTALLER)" script acts as a "launcher" to speed up the processes available in the guides "[How to install "AM"](#how-to-install-am)" and "[How to install "AppMan"](#how-to-install-appman)". "AppMan" will be installed in ~/.local/bin and the script will take care of enabling it in "$PATH".
268+
269+
------------------------------------------------------------------------
256270
#### Core dependences
257271
Below are the **essential system dependencies** that you must install before proceeding:
258272
- "`coreutils`" (contains "`cat`", "`chmod`", "`chown`"...);
@@ -284,6 +298,8 @@ The following are optional dependencies that some programs may require:
284298

285299
The script "[INSTALL](https://github.com/ivan-hc/AM/blob/main/INSTALL)" is the one that take care of this.
286300

301+
https://github.com/user-attachments/assets/857d28d4-d2ae-42a0-9fe2-95fd62d48d65
302+
287303
#### Using "Wget"
288304
```
289305
wget https://raw.githubusercontent.com/ivan-hc/AM/main/INSTALL

0 commit comments

Comments
 (0)