Skip to content

Commit

Permalink
Merge pull request #809 from ivan-hc/dev
Browse files Browse the repository at this point in the history
Add common installer for both "AM" and "AppMan"
  • Loading branch information
ivan-hc authored Aug 4, 2024
2 parents d4dca84 + 3873e3b commit faad7a9
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 84 deletions.
87 changes: 87 additions & 0 deletions AM-INSTALLER
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/sh

set -e

_away_error() {
${1} >/dev/null 2>&1
}

_away_all() {
${1} >/dev/null
}

# Colors
RED='\033[0;31m'; LightBlue='\033[1;34m'; Green='\033[0;32m'

_check_dependency() {
program="$1"
_away_all command -v "$program" || { echo "For Installation to work, install \"$program\" first!" && exit 1; }
}

_check_dependency 'wget'
_check_dependency 'curl'

# INSTALL "AM" SYSTEM-WIDE
_install_am() {
CACHEDIR="${XDG_CACHE_HOME:-$HOME/.cache}"
mkdir -p "$CACHEDIR" || true
rm -f "$CACHEDIR"/INSTALL-AM.sh || true
wget -q https://raw.githubusercontent.com/ivan-hc/AM/main/INSTALL -O "$CACHEDIR"/INSTALL-AM.sh && chmod a+x "$CACHEDIR"/INSTALL-AM.sh
sudo "$CACHEDIR"/INSTALL-AM.sh && rm -f "$CACHEDIR"/INSTALL-AM.sh
}

# INSTALL "AM" LOCALLY, AS "APPMAN"
_install_appman() {
ZSHRC="${ZDOTDIR:-$HOME}/.zshrc"
BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
mkdir -p "$BINDIR"
if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then
echo '--------------------------------------------------------------------------'
echo " Adding $BINDIR to PATH, you might need to"
echo " close and reopen the terminal for this to take effect."
if [ -e ~/.bashrc ] && ! grep 'PATH="$PATH:$BINDIR"' ~/.bashrc >/dev/null 2>&1; then
printf '\n%s\n' 'BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"' >> ~/.bashrc
printf '\n%s\n' 'if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then' >> ~/.bashrc
printf ' PATH="$PATH:$BINDIR"\nfi\n' >> ~/.bashrc
fi
if [ -e "$ZPROFILE" ] && ! grep 'PATH="$PATH:$BINDIR"' "$ZSHRC" >/dev/null 2>&1; then
printf '\n%s\n' 'BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"' >> "$ZSHRC"
printf '\n%s\n' 'if ! echo $PATH | grep "$BINDIR" >/dev/null 2>&1; then' >> "$ZSHRC"
printf ' PATH="$PATH:$BINDIR"\nfi\n' >> "$ZSHRC"
fi
fi
wget -q https://raw.githubusercontent.com/ivan-hc/AM/main/APP-MANAGER -O "$BINDIR"/appman && chmod a+x "$BINDIR"/appman
}

# CHOOSE BETWEEN "AM" AND "APPMAN"
printf " Choose how to install \"AM\" and all its managed applications.
1) As \"${RED}AM\033[0m\", command \"${Green}am\033[0m\", this is a system-wide installation:
- the command is a symlink /usr/local/bin/am for /opt/am/APP-MANAGER
- all programs will be installed in /opt, into dedicated directories
- a \"sudo\" password is required both here and to install/remove apps
- you are the one with read-write permissions for \"AM\" and all programs
- other users can only use programs you have installed, nothing else
- other users can still use \"AppMan mode\" for their rootless configurations
2) As \"${LightBlue}AppMan\033[0m\", command \"${Green}appman\033[0m\", local installation:
- the command is the script ~/.local/bin/appman
- choose wherever you want to install all the apps, in your HOME
- no \"sudo\" required at all
- you can replicate your configurations on every system you want
- more storage space required, if more users use \"AppMan\"
"
read -r -p "Choose between \"AM\" (type 1) and \"AppMan\" (2), or leave blank to exit: " response
case "$response" in
1) _install_am || exit 1
;;
2) _install_appman || exit 1
echo '--------------------------------------------------------------------------'
printf " ${Green}\"AppMan\" has been successfully installed!\033[0m\n"
printf " Please, run \"${LightBlue}appman -h\033[0m\" to see the list of the options.\n"
echo '--------------------------------------------------------------------------'
;;
''|*) echo "Installation aborted, exiting." && exit 1
;;
esac
2 changes: 1 addition & 1 deletion APP-MANAGER
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

AMVERSION="7.3"
AMVERSION="7.4"

# Determine main repository and branch
AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main"
Expand Down
144 changes: 61 additions & 83 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -14,100 +14,78 @@ currentuser=$(who | awk '{print $1}')

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

_check_dependency 'wget'
_check_dependency 'curl'

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

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

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

# LINK THE MAIN SCRIPT TO A KNOWN PATH
ln -s /opt/am/APP-MANAGER /usr/local/bin/am || echo "WARNING: Something went wrong!"
# DOWNLOAD AND LINK THE MAIN SCRIPT
wget -q https://raw.githubusercontent.com/ivan-hc/AM/main/APP-MANAGER
chmod a+x /opt/am/APP-MANAGER
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"

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

# DOWNLOAD MODULES
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")
for module in $MODULES; do
for v in $module; do
cd /opt/am/modules || exit
mkdir -p tmp
cd tmp || exit
wget -q "$v"
cd ..
mv tmp/*.am ./
chmod a+x ./*.am
rmdir tmp
_download_am_modules() {
# DOWNLOAD MODULES
cd /opt/am/modules || exit
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")
for v in $MODULES; do
MODULENAME=$(echo "$v" | sed 's:.*/::')
if ! test -f ./"$MODULENAME"; then
echo " ◆ Downloading $MODULENAME..."
wget -q "$v"
chmod a+x ./"$MODULENAME"
fi
done
done

# ENABLE NON-ROOT PERMISSIONS TO THE MAIN DIRECTORY FOR THE CURRENT USER
chown -R $currentuser /opt/am 2> /dev/null

# ADD THE BASH COMPLETION SCRIPT
echo '#!/usr/bin/env bash
complete -W "$(cat /opt/am/list 2>/dev/null)" am' >> /opt/am/am-completion.sh
chmod a+x /opt/am/am-completion.sh

if test -f /etc/bash_completion.d; then
mv /opt/am/am-completion.sh /etc/bash_completion.d/
else
mkdir -p /etc/bash_completion.d
sudo mv /opt/am/am-completion.sh /etc/bash_completion.d/
fi

# SHOW THE MESSAGE
echo '
_____ _____
/\ \ /\ \ A A
/::\ \ /::\____\ P M
/::::\ \ /::::| | P
/::::::\ \ /:::::| | M &
/:::/\:::\ \ /::::::| | A
/:::/__\:::\ \ /:::/|::| | N
/::::\ \:::\ \ /:::/ |::| |
/::::::\ \:::\ \ /:::/ |::|___|______
/:::/\:::\ \:::\ \ /:::/ |::::::::\ \
/:::/ \:::\ \:::\____\/:::/ |:::::::::\____\
\::/ \:::\ /:::/ /\::/ / ~~~~~/:::/ /
\/____/ \:::\/:::/ / \/____/ /:::/ /
\::::::/ / /:::/ /
\::::/ / /:::/ /
/:::/ / /:::/ /╔═╗╔╗╔┌─┐┌─┐┌─┐┬─┐
/:::/ / /:::/ / ╠═╣║║║├─┤│ ┬├┤ ├┬┘
/:::/ / /:::/ / ╩ ╩╝╚╝┴ ┴└─┘└─┘┴└─
/:::/ /╔═╗╔═╗┬ ┬┌─┐┌─┐┌┬┐┬┌─┐┌┐┌
\::/ / ╠═╝╠═╝│ ││ ├─┤ │ ││ ││││
\/____/ ╩ ╩ ┴─┘┴└─┘┴ ┴ ┴ ┴└─┘┘└┘ by Ivan Alex HC

>> 𝘋𝘢𝘵𝘢𝘣𝘢𝘴𝘦 & 𝘴𝘰𝘭𝘶𝘵𝘪𝘰𝘯𝘴 𝘧𝘰𝘳 𝘢𝘭𝘭 𝘈𝘱𝘱𝘐𝘮𝘢𝘨𝘦𝘴 𝘢𝘯𝘥 𝘱𝘰𝘳𝘵𝘢𝘣𝘭𝘦 𝘢𝘱𝘱𝘴 𝘧𝘰𝘳 𝘎𝘕𝘜/𝘓𝘪𝘯𝘶𝘹 <<
cd ..

##########################################################################
__________________________________________________________________________

SITE: https://portable-linux-apps.github.io

REPOSITORY: https://github.com/ivan-hc/AM
__________________________________________________________________________

##########################################################################
# ENABLE NON-ROOT PERMISSIONS TO THE MAIN DIRECTORY FOR THE CURRENT USER
chown -R $currentuser /opt/am 2> /dev/null
}

Run "am -h" to see the list of the options
##########################################################################
'
_enable_bash_completion() {
# ADD THE BASH COMPLETION SCRIPT
echo '#!/usr/bin/env bash' > /opt/am/am-completion.sh
echo 'complete -W "$(cat /opt/am/list 2>/dev/null)" am' >> /opt/am/am-completion.sh
chmod a+x /opt/am/am-completion.sh

if test -f /etc/bash_completion.d; then
mv /opt/am/am-completion.sh /etc/bash_completion.d/
else
mkdir -p /etc/bash_completion.d
sudo mv /opt/am/am-completion.sh /etc/bash_completion.d/
fi
}

echo '--------------------------------------------------------------------------'
printf " ${Green}Installing \"AM\" in /opt/am\033[0m\n"
_prepare_am_directory
echo '--------------------------------------------------------------------------'
printf " ${Green}Installing modules\033[0m\n"
_download_am_modules
echo '--------------------------------------------------------------------------'
printf " ${Green}Enable bash completion\033[0m\n"
_enable_bash_completion
echo '--------------------------------------------------------------------------'
printf " ${Green}\"AM\" has been successfully installed!\033[0m\n"
printf " Please, run \"${LightBlue}am -h\033[0m\" to see the list of the options.\n"
echo '--------------------------------------------------------------------------'
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,20 @@ This section explains how to install "AM" or "AppMan".

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

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:
```
wget -q https://raw.githubusercontent.com/ivan-hc/AM/main/AM-INSTALLER
chmod a+x ./AM-INSTALLER
./AM-INSTALLER
```
Type "1" to install "AM" (requires "sudo" password), "2" to install "AppMan". Any other key will abort the installation.

| ![AM-INSTALLER](https://github.com/user-attachments/assets/82b21979-e99d-4bee-b466-716bac1e7e45) |
| - |

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".

------------------------------------------------------------------------
#### Core dependences
Below are the **essential system dependencies** that you must install before proceeding:
- "`coreutils`" (contains "`cat`", "`chmod`", "`chown`"...);
Expand Down Expand Up @@ -284,6 +298,8 @@ The following are optional dependencies that some programs may require:

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

https://github.com/user-attachments/assets/857d28d4-d2ae-42a0-9fe2-95fd62d48d65

#### Using "Wget"
```
wget https://raw.githubusercontent.com/ivan-hc/AM/main/INSTALL
Expand Down

0 comments on commit faad7a9

Please sign in to comment.