Skip to content

Commit

Permalink
Merge pull request #1205 from ivan-hc/dev
Browse files Browse the repository at this point in the history
Various fixes between APP-MANAGER, INSTALL and AM-INSTALLER
  • Loading branch information
ivan-hc authored Dec 11, 2024
2 parents 8913538 + ac9eea4 commit d2b87f0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 42 deletions.
29 changes: 15 additions & 14 deletions AM-INSTALLER
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@

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'

# For developers
AM_BRANCH="main"

# Check dependencies for this script
_check_dependency() {
program="$1"
_away_all command -v "$program" || { echo "For Installation to work, install \"$program\" first!" && exit 1; }
AMDEPENDENCES="chmod chown curl grep wget"
for dependency in $AMDEPENDENCES; do
if ! command -v "$dependency" >/dev/null 2>&1; then
printf "\n %b💀 ERROR! MISSING ESSENTIAL COMMAND \033[0m: %b\n\n Install the above and try again! \n\n" "${RED}" "$dependency"
exit 1
fi
done
}

_check_dependency 'wget'
_check_dependency 'curl'
_check_dependency

# 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
wget -q "https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/INSTALL" -O "$CACHEDIR"/INSTALL-AM.sh && chmod a+x "$CACHEDIR"/INSTALL-AM.sh
#cp ./INSTALL "$CACHEDIR"/INSTALL-AM.sh && chmod a+x "$CACHEDIR"/INSTALL-AM.sh # for developers
if command -v sudo >/dev/null 2>&1; then
SUDOCMD="sudo"
elif command -v doas >/dev/null 2>&1; then
Expand Down Expand Up @@ -58,7 +59,7 @@ _install_appman() {
printf ' export 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
wget -q "https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/APP-MANAGER" -O "$BINDIR"/appman && chmod a+x "$BINDIR"/appman
}

# CHOOSE BETWEEN "AM" AND "APPMAN"
Expand Down
20 changes: 13 additions & 7 deletions APP-MANAGER
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

AMVERSION="9.3-2"
AMVERSION="9.3-3"

# Determine main repository and branch
AMREPO="https://raw.githubusercontent.com/ivan-hc/AM/main"
Expand All @@ -17,8 +17,10 @@ DIR="$( cd "$( dirname "$0" )" && pwd )"
CLI=$(basename "$0")

# Determine system architecture and current user
arch="$HOSTTYPE"
export ARCH="$arch"
ARCH="$(uname -m)"
[ "$ARCH" = "amd64" ] && ARCH=x86_64
arch="$ARCH"
export ARCH arch

# XDG Variables
export BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
Expand All @@ -39,7 +41,10 @@ LightBlue='\033[1;34m'
DIVIDING_LINE="-----------------------------------------------------------------------------"

# Prevent the use of "sudo" ("AM")
[ -n "$SUDO_COMMAND" ] && echo -e "\n Please do not use \"sudo\" to execute \"$CLI\", try again.\n" && exit 1
if [ -n "${SUDO_USER:-$DOAS_USER}" ]; then
printf "\n Please do not use \"sudo\" to execute \"$CLI\", try again.\n\n"
exit 1
fi

function _create_cache_dir() {
AMCACHEDIR="$CACHEDIR/$AMCLI"
Expand Down Expand Up @@ -255,13 +260,14 @@ function _am_dependences_check() {
}

function _check_ubuntu_mess() {
if ! unshare --user -p /bin/true >/dev/null 2>&1; then
if command -v unshare >/dev/null 2>&1 && ! unshare --user -p /bin/true >/dev/null 2>&1; then
echo "$DIVIDING_LINE"
echo ""
echo -e " ${RED}⚠️ WARNING: ACCESS TO USER NAMESPACES IS RESTRICTED! \033[0m"
echo ""
echo " Some apps may not run, you need to enable access to user namespaces,"
echo -e " please visit ${LightBlue}https://github.com/ivan-hc/AM#ubuntu-mess\033[0m to know more."
echo " Some apps may not run, you need to enable access to user namespaces, see"
echo -e " ${LightBlue}https://github.com/ivan-hc/AM/blob/main/docs/troubleshooting.md#ubuntu-mess\033[0m"
echo " to know more."
echo ""
echo "$DIVIDING_LINE"
fi
Expand Down
43 changes: 22 additions & 21 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
#!/bin/sh

_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'

# DETERMINE SYSTEM ARCHITECTURE AND CURRENT USER
arch=$(uname -m)
currentuser=$(who | awk '{print $1}')
# For developers
AM_BRANCH="main"

# Check dependencies for this script
_check_dependency() {
program="$1"
_away_all command -v "$program" && return 0 || printf "${RED}WARNING: For Installation to work, install \"$program\" first!\033[0m\n" && exit 1
AMDEPENDENCES="chmod chown curl grep wget"
for dependency in $AMDEPENDENCES; do
if ! command -v "$dependency" >/dev/null 2>&1; then
printf "\n %b💀 ERROR! MISSING ESSENTIAL COMMAND \033[0m: %b\n\n Install the above and try again! \n\n" "${RED}" "$dependency"
exit 1
fi
done
}

_check_dependency 'wget'
_check_dependency 'curl'
_check_dependency

# Colors
RED='\033[0;31m'; LightBlue='\033[1;34m'; Green='\033[0;32m'
if [ -z "${SUDO_USER:-$DOAS_USER}" ]; then
echo 'Please use sudo or doas'
exit 1
fi

# INSTALL "AM"
_prepare_am_directory() {
Expand All @@ -36,26 +37,26 @@ _prepare_am_directory() {
chmod a+x /opt/am/remove || exit 1

# DOWNLOAD AND LINK THE MAIN SCRIPT
wget -q https://raw.githubusercontent.com/ivan-hc/AM/main/APP-MANAGER
wget -q "https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/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_am_modules() {
# DOWNLOAD MODULES
cd /opt/am/modules || exit
MODULES=$(curl -Ls https://raw.githubusercontent.com/ivan-hc/AM/main/APP-MANAGER | tr '"' '\n' | grep "[a-z]\.am$")
MODULES=$(curl -Ls "https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/APP-MANAGER" | tr '"' '\n' | grep "[a-z]\.am$")
for module_name in $MODULES; do
if ! test -f ./"$module_name"; then
if [ ! -f ./"$module_name" ]; then
echo " ◆ Downloading $module_name..."
wget -q "https://raw.githubusercontent.com/ivan-hc/AM/main/modules/$module_name"
wget -q "https://raw.githubusercontent.com/ivan-hc/AM/$AM_BRANCH/modules/$module_name"
chmod a+x ./"$module_name"
fi
done
cd ..

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

echo '--------------------------------------------------------------------------'
Expand Down

0 comments on commit d2b87f0

Please sign in to comment.