Skip to content

Commit

Permalink
Merge pull request #733 from ivan-hc/dev
Browse files Browse the repository at this point in the history
$BINDIR support to "install.am" / enanche  future installation scripts (in "template.am")
  • Loading branch information
ivan-hc authored Jun 27, 2024
2 parents 55dbb1c + 9de44e4 commit 45cbc98
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
32 changes: 17 additions & 15 deletions modules/install.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
# THIS MODULE IS USED TO INSTALL APPS FROM THE DATABASE OR FROM LOCAL SCRIPTS
#############################################################################

BINDIR="${XDG_BIN_HOME:-$HOME/.local/bin}"

# If you use the --latest option, add the "latest" flag to scripts that point to a very common "release"
function _if_latest() {
if grep -q 'force-latest' "$AMCACHEDIR"/install-args; then
sed -i 's#/releases | jq #/releases/latest | jq #g' ./"$arg"
sed -i 's#/releases#/releases/latest#g' ./"$arg"
fi
}

Expand All @@ -31,11 +33,11 @@ function _install_common_patch() {
function _install_appman_local_patch() {
sed -i "s#/opt/#$APPSPATH/#g" ./"$arg"
sed -i "s# /opt# $APPSPATH#g" ./"$arg"
sed -i "s# /usr/local/bin# $HOME/.local/bin#g" ./"$arg"
sed -i 's# "/usr/local/bin# "'"$HOME"'/.local/bin#g' ./"$arg"
sed -i "s# /usr/bin# $HOME/.local/bin#g" ./"$arg"
sed -i "s# /usr/local/games# $HOME/.local/bin#g" ./"$arg"
sed -i "s# /usr/games# $HOME/.local/bin#g" ./"$arg"
sed -i "s# /usr/local/bin# $BINDIR#g" ./"$arg"
sed -i 's# "/usr/local/bin# "'"$BINDIR"'#g' ./"$arg"
sed -i "s# /usr/bin# $BINDIR#g" ./"$arg"
sed -i "s# /usr/local/games# $BINDIR#g" ./"$arg"
sed -i "s# /usr/games# $BINDIR#g" ./"$arg"
sed -i "s# /usr/share/applications# $DATADIR/applications#g" ./"$arg"
sed -i "s# /usr/local/share/applications# $DATADIR/applications#g" ./"$arg"
sed -i "s# /usr/share/pixmaps# $DATADIR/icons#g" ./"$arg"
Expand All @@ -58,12 +60,12 @@ function _apply_patches() {

# Post-installation processes
function _post_installation_processes() {
echo -ne " Configuring $(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]')...\r" && echo -ne " \r" &&
echo -ne " Configuring $(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]')...\r" && echo -ne " \r"

# Add a command to line 2 of the "remove" script to prevent use without root privileges
# and take control of the directory to be able to manage and update the app without root privileges
if [ "$AMCLI" == am ] 2>/dev/null; then
$SUDOCOMMAND sed -i '1 a if [ -z "$SUDO_COMMAND" ]; then echo "Permission denied"; exit 1; fi' "$APPSPATH"/"$(cd "$APPSPATH" && ls -td * | head -1)"/remove 2> /dev/null
$SUDOCOMMAND sed -i '1 a if [ "$(id -u)" -ne 0 ]; then echo "Permission denied"; exit 1; fi' "$APPSPATH"/"$(cd "$APPSPATH" && ls -td * | head -1)"/remove 2> /dev/null
$SUDOCOMMAND chown -R $currentuser "$APPSPATH"/"$(cd "$APPSPATH" && ls -td * | head -1)" 2> /dev/null
fi
# Check if an AM-updater script exists, so the CLI can manage updates for the installed app
Expand All @@ -78,14 +80,14 @@ function _post_installation_processes() {
if [ -z "$(ls -A "$APPSPATH"/"$(cd "$APPSPATH" && ls -td * | head -1)"/icons)" ]; then
wget -q "$AMCATALOGUEICONS"/"$arg".png -O "$APPSPATH"/"$(cd "$APPSPATH" && ls -td * | head -1)"/icons/"$arg"
fi
fi &&
fi
# Patch .desktop to change paths if the app is installed locally
if [ "$AMCLI" == appman ] 2>/dev/null; then
sed -i "s#Icon=/opt#Icon=$HOME/$APPSDIR#g" "$DATADIR"/applications/AM*.desktop 2> /dev/null
sed -i "s#Exec=$arg#Exec=$HOME/.local/bin/$arg#g" "$DATADIR"/applications/AM*.desktop 2> /dev/null
sed -i 's#Exec=$APP#Exec='"$HOME"'/.local/bin/$APP#g' "$DATADIR"/applications/AM*.desktop 2> /dev/null
sed -i "s#Exec=/usr/bin/#Exec=$HOME/.local/bin/#g" "$DATADIR"/applications/AM*.desktop 2> /dev/null
sed -i "s#Exec=/opt/#Exec=$HOME/.local/bin/#g" "$DATADIR"/applications/AM*.desktop 2> /dev/null
sed -i "s#Exec=$arg#Exec=$BINDIR/$arg#g" "$DATADIR"/applications/AM*.desktop 2> /dev/null
sed -i 's#Exec=$APP#Exec='"$BINDIR"'/$APP#g' "$DATADIR"/applications/AM*.desktop 2> /dev/null
sed -i "s#Exec=/usr/bin/#Exec=$BINDIR/#g" "$DATADIR"/applications/AM*.desktop 2> /dev/null
sed -i "s#Exec=/opt/#Exec=$BINDIR/#g" "$DATADIR"/applications/AM*.desktop 2> /dev/null
fi
}

Expand Down Expand Up @@ -290,8 +292,8 @@ while [ -n "$1" ]; do
rm -R -f "$AMCACHEDIR/multirepo-args"
_install_arg
else
echo -e "\n ◆ FOUND $(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]') FROM MULTIPLE SOURCES:\n" &&
printf " Select a URL from this menu (read carefully) or press CTRL+C to abort:\n\n"; sleep 1;
printf '\n%s\n' " ◆ FOUND $(echo "\"$arg\"" | tr '[:lower:]' '[:upper:]') FROM MULTIPLE SOURCES:"
printf '%s\n\n' " Select a URL from this menu (read carefully) or press CTRL+C to abort:"; sleep 1
select d in $(cat "$AMCACHEDIR/multirepo-args"); do test -n "$d" && break; echo ">>> Invalid Selection"; done
cd "$AMCACHEDIR" || return; mkdir -p tmp; cd tmp || return; wget -q "$d/$arg"; cd ..; mv ./tmp/"$arg" ./"$arg"; rmdir ./tmp
rm -R -f "$AMCACHEDIR/multirepo-args"
Expand Down
16 changes: 8 additions & 8 deletions modules/template.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ function _template_if_github_source() {
# CHECK THE DOWNLOAD LINK, THE ONE THAT POINTS TO THE LATEST RELEASE, NOTE THAT IT MAY BE A DEVELOPMENT VERSION, ADD "/latest" AFTER "/releases" TO POINT TO THE LAST STABLE VERSION
q="'"
if [ "$templatetype" == 0 ]; then
FUNCTION='curl -Ls https://api.github.com/repos/'"$RESPONSE"'/releases | jq '"$q"'.'"$q"' | grep browser_download_url | grep -i appimage | cut -d '"$q"'"'"$q"' -f 4 | head -1'
FUNCTION='curl -Ls https://api.github.com/repos/'"$RESPONSE"'/releases | grep browser_download_url | grep -i appimage | cut -d '"$q"'"'"$q"' -f 4 | head -1'
elif [ "$templatetype" == 2 ]; then
FUNCTION='curl -Ls https://api.github.com/repos/'"$RESPONSE"'/releases | jq '"$q"'.'"$q"' | grep browser_download_url | cut -d '"$q"'"'"$q"' -f 4 | head -1'
FUNCTION='curl -Ls https://api.github.com/repos/'"$RESPONSE"'/releases | grep browser_download_url | cut -d '"$q"'"'"$q"' -f 4 | head -1'
fi
sed -i "s#FUNCTION)#$FUNCTION)#g" ./am-scripts/"$arch"/"$arg"
}
Expand All @@ -49,9 +49,9 @@ function _template_then_github_source() {
;;
'Y'|'y'|*)
if [ "$templatetype" == 0 ]; then
echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | jq '.' | grep browser_download_url | grep -i appimage | cut -d '"' -f 4 | head -1
echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | grep browser_download_url | grep -i appimage | cut -d '"' -f 4 | head -1
elif [ "$templatetype" == 2 ]; then
echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | jq '.' | grep browser_download_url | cut -d '"' -f 4 | head -1
echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | grep browser_download_url | cut -d '"' -f 4 | head -1
fi
echo -e "\n The URL above is an example of what both\n the install and update scripts will point to.\n"
;;
Expand All @@ -74,9 +74,9 @@ function _template_then_github_source() {
;;
'Y'|'y'|*)
if [ "$templatetype" == 0 ]; then
echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | jq '.' | grep browser_download_url | grep -i "$response" | grep -i appimage | cut -d '"' -f 4 | head -1
echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | grep browser_download_url | grep -i "$response" | grep -i appimage | cut -d '"' -f 4 | head -1
elif [ "$templatetype" == 2 ]; then
echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | jq '.' | grep browser_download_url | grep -i "$response" | cut -d '"' -f 4 | head -1
echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | grep browser_download_url | grep -i "$response" | cut -d '"' -f 4 | head -1
fi
echo -e "\n The URL above is an example of what both\n the install and update scripts will point to.\n"
;;
Expand All @@ -97,9 +97,9 @@ function _template_then_github_source() {
;;
'Y'|'y'|*)
if [ "$templatetype" == 0 ]; then
echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | jq '.' | grep browser_download_url | grep -v "$response" | grep -i appimage | cut -d '"' -f 4 | head -1
echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | grep browser_download_url | grep -v "$response" | grep -i appimage | cut -d '"' -f 4 | head -1
elif [ "$templatetype" == 2 ]; then
echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | jq '.' | grep browser_download_url | grep -v "$response" | cut -d '"' -f 4 | head -1
echo ""; curl -Ls $HeaderAuthWithGITPAT https://api.github.com/repos/"$RESPONSE"/releases | grep browser_download_url | grep -v "$response" | cut -d '"' -f 4 | head -1
fi
echo -e "\n The URL above is an example of what both\n the install and update scripts will point to.\n"
;;
Expand Down

0 comments on commit 45cbc98

Please sign in to comment.