Skip to content

Commit

Permalink
update.am
Browse files Browse the repository at this point in the history
  • Loading branch information
zen0bit committed May 12, 2024
1 parent 62121c6 commit 8c3d1b5
Showing 1 changed file with 22 additions and 117 deletions.
139 changes: 22 additions & 117 deletions modules/update.am
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ function _update_apps() {
fi
echo -e '\n All self-updatable programs are excluded'
sleep 0.1
for f in "$APPSPATH/"*/; do
cd "$f" 2>/dev/null &&
echo -e '-----------------------------------------------------------------------------\n\
>> START OF ALL PROCESSES <<\n-----------------------------------------------------------------------------'
for f in "$APPSPATH"/*/; do
cd $f 2>/dev/null &&
if test -f ./AM-updater; then
start=$(date +%s) && \
sh -x ./AM-updater > /dev/null 2>&1 && \
printf ' Updating %s...\r' "$(basename "$PWD")" && \
end=$(date +%s) && \
echo -e "$(basename "$PWD" | _make_upper) is updated, (($end-$start)) seconds elapsed!" &
APPNAME=$(basename "$PWD")
start=$(date +%s) && sh -x ./AM-updater > /dev/null 2>&1
printf '\n Updating %s...\r' "$APPNAME" && end=$(date +%s) &&
echo -e "$(echo "$APPNAME" | _make_upper) is updated, $((end-start)) seconds elapsed!" &
else
echo "" > /dev/null 2>&1
fi
Expand All @@ -78,21 +77,23 @@ function _update_apps() {
rm -R -f "$APPSPATH"/*/tmp
if [ -z "$2" ]; then
echo '-----------------------------------------------------------------------------'
$AMCLIPATH -s
"$AMCLIPATH" -s
fi
echo -e '-----------------------------------------------------------------------------\n >> END OF ALL PROCESSES << \n-----------------------------------------------------------------------------'
sleep 0.2
exit
}

function _update_all() {
if test -f "$APPSPATH/$2"/AM-updater; then
start=$(date +%s); "$APPSPATH/$2"/AM-updater > /dev/null 2>&1 | echo -ne " UPDATING $(echo "$2" | _make_upper)\r"
if test -f "$APPSPATH/$2/AM-updater"; then
start=$(date +%s)
"$APPSPATH/$2/AM-updater" > /dev/null 2>&1
printf ' UPDATING %s\r' "$(echo $2 | _make_upper)"
end=$(date +%s)
echo -e "$("$2" | _make_upper) is updated, (($end-$start)) seconds elapsed!" && return
echo -e "$(echo $2 | _make_upper) is updated, $((end-start)) seconds elapsed!" && return
else
printf ' %s CANNOT MANAGE UPDATES FOR %s' "$(echo "$AMCLI" | _make_upper)" "$(echo "$2" | _make_upper)"
UPDATERS=$(cd "$APPSPATH/$2" 2>/dev/null && find . -name "*update*" -print 2>/dev/null)
echo ' %s CANNOT MANAGE UPDATES FOR %s' "$(echo $AMCLI | _make_upper)" "$(echo $2 | _make_upper)"
UPDATERS=$(cd $APPSPATH/$2 2>/dev/null && find . -name "*update*" -print 2>/dev/null)
if [ -n "$UPDATERS" ]; then
echo ' This program probably includes its own update system!'
fi
Expand All @@ -103,15 +104,15 @@ function _update_all() {
function _update_rest() {
if ! test -d "$APPSPATH/$2"; then
printf ' ERROR: %s is not installed, see "-f"' "$2"
elif ! test -f "$APPSPATH/$2"/AM-updater; then
elif ! test -f "$APPSPATH/$2/AM-updater"; then
printf ' ERROR: %s cannot manage updates for %s' "$AMCLI" "$2"
elif ! grep -q 'api.github.com' "$APPSPATH/$2"/AM-updater; then
elif ! grep -q "api.github.com" "$APPSPATH/$2/AM-updater"; then
printf ' ERROR: %s source is not on Github' "$2"
elif ! grep -q '/releases | jq ' "$APPSPATH/$2"/AM-updater; then
elif ! grep -q "/releases | jq " "$APPSPATH/$2/AM-updater"; then
printf ' ERROR: %s does not redirect to a generic "releases"' "$2"
else
sed -i 's#/releases | jq #/releases/latest | jq #g' "$APPSPATH/$2"/AM-updater
$AMCLIPATH -u "$2"
sed -i 's#/releases | jq #/releases/latest | jq #g' $APPSPATH/$2/AM-updater
"$AMCLIPATH" -u "$2"
fi
}

Expand All @@ -131,111 +132,15 @@ case "$1" in
done
shift
;;

'--force-latest')
case $2 in
''|'--apps')
rm -R -f $AMPATH/.cache/*
function _list_updatable_apps() {
_check_version
cd $APPSPATH && find -name 'AM-updater' -printf " %h\n" 2>/dev/null | sort -u | xargs -n 1 basename 2>/dev/null > $AMPATH/.cache/updatable-args
ARGS=$(cat $AMPATH/.cache/updatable-args)
for arg in $ARGS; do
app_version=$(cat "$AMPATH/.cache/version-args" | grep -w "$arg |" | sed 's:.*| ::')
echo "$arg $app_version" >> $AMPATH/.cache/updatable-args-list
done
}

_list_updatable_apps

echo "-----------------------------------------------------------------------------"
echo -e ' "'"$(echo $AMCLI | tr a-z A-Z)"'" CAN MANAGE UPDATES FOR THE FOLLOWING PROGRAMS:\n'
if test -f "$AMPATH/.cache/updatable-args-list"; then
cat "$AMPATH/.cache/updatable-args-list"
else
echo " None"
fi
echo -e '\n All self-updatable programs are excluded'; sleep 0.1
echo "-----------------------------------------------------------------------------"
echo -e " >> START OF ALL PROCESSES <<\n-----------------------------------------------------------------------------"

for f in $APPSPATH/*/; do
cd $f 2>/dev/null &&
if test -f ./AM-updater; then
APPNAME=$(echo "$(printf '%s\n' "${PWD##*/}")")
start=$(date +%s) && sh -x ./AM-updater > /dev/null 2>&1 | echo -ne ' Updating "'"$APPNAME"'"...\r' && end=$(date +%s) &&
echo -e "$(echo "$APPNAME" | tr a-z A-Z) is updated, $(($end-$start)) seconds elapsed!" &
else
echo "" > /dev/null 2>&1
fi
done
wait

echo "-----------------------------------------------------------------------------"

if test -f $AMPATH/.cache/updatable-args-list; then
mv $AMPATH/.cache/updatable-args-list $AMPATH/.cache/updatable-args-list-old
_list_updatable_apps
OLDVER="$AMPATH/.cache/updatable-args-list-old"
NEWVER="$AMPATH/.cache/updatable-args-list"
if cmp --silent -- "$NEWVER" "$OLDVER"; then
echo ' Nothing to do here!'
else
echo -e " The following apps have been updated:\n"
diff --new-line-format="" --unchanged-line-format="" "$NEWVER" "$OLDVER"
echo ""
fi
else
echo ' No apps to update here!'
fi

rm -R -f $APPSPATH/*/tmp
if [ -z "$2" ]; then
echo "-----------------------------------------------------------------------------"
$AMCLIPATH -s
fi
echo -e "-----------------------------------------------------------------------------\n >> END OF ALL PROCESSES << \n-----------------------------------------------------------------------------"; sleep 0.2
exit;;
*)
if test -f $APPSPATH/$2/AM-updater; then
start=$(date +%s); $APPSPATH/$2/AM-updater > /dev/null 2>&1 | echo -ne " UPDATING $(echo $2 | tr a-z A-Z)\r"; end=$(date +%s)
echo -e "$(echo $2 | tr a-z A-Z) is updated, $(($end-$start)) seconds elapsed!" && break
else
echo ' "'"$(echo $AMCLI | tr a-z A-Z)"'" CANNOT MANAGE UPDATES FOR "'"$(echo $2 | tr a-z A-Z)"'"'
UPDATERS=$(cd $APPSPATH/$2 2>/dev/null && find . -name "*update*" -print 2>/dev/null)

if [ -n "$UPDATERS" ]; then
echo ' This program probably includes its own update system!'
fi

exit
'')
echo " USAGE: $AMCLI $1 [ARGUMENT]"; exit
;;
*)
_update_rest "${@}"
;;
esac
done

shift
;;
'--force-latest')
case $2 in
'')
echo " USAGE: $AMCLI $1 [ARGUMENT]"; exit
;;
*)
if ! test -d $APPSPATH/$2; then
echo ' ERROR: "'$2'" is not installed, see "-f"'
elif ! test -f $APPSPATH/$2/AM-updater; then
echo ' ERROR: "'$AMCLI'" cannot manage updates for "'$2'"'
elif ! grep -q "api.github.com" $APPSPATH/$2/AM-updater; then
echo ' ERROR: "'$2'" source is not on Github'
elif ! grep -q "/releases | jq " $APPSPATH/$2/AM-updater; then
echo ' ERROR: "'$2'" does not redirect to a generic "releases"'
else
sed -i 's#/releases | jq #/releases/latest | jq #g' $APPSPATH/$2/AM-updater
$AMCLIPATH -u $2
fi
;;
esac
;;
esac

0 comments on commit 8c3d1b5

Please sign in to comment.