Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Universal shebangs. Shellcheck fixes, globbing/expansion fixes, etc. #1409

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions api.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/bash
. "$HOME/.config/EmuDeck/backend/functions/all.sh"
#!/usr/bin/env bash

# shellcheck disable=1091
. "${HOME}/.config/EmuDeck/backend/functions/all.sh"

API_pull(){
local branch=$1
cd ~/.config/EmuDeck/backend && touch $emudeckLogs/git.log && git reset --hard && git clean -fd && git checkout $branch && git pull && appImageInit && echo "OK" || echo "KO" >&2
cd ~/.config/EmuDeck/backend && touch "${emudeckLogs:?}"/git.log && git reset --hard && git clean -fd && git checkout "${branch}" && git pull && appImageInit && echo "OK" || echo "KO" >&2
}

API_autoSave(){
Expand All @@ -27,7 +29,7 @@ API_shaders_3D(){
}

API_ar_snes(){
if [ "$arSnes" == 87 ]; then
if [ "${arSnes:?}" == 87 ]; then
RetroArch_snes_ar87 1> /dev/null && RetroArch_nes_ar87 1> /dev/null && echo "OK" || echo "KO" >&2
else
RetroArch_snes_ar43 1> /dev/null && RetroArch_nes_ar43 1> /dev/null && echo "OK" || echo "KO" >&2
Expand All @@ -47,7 +49,7 @@ API_setAR(){
}

API_setCloud(){
if [ $cloud_sync_status == "false" ]; then
if [ "${cloud_sync_status:?}" == "false" ]; then
setSetting cloud_sync_status "true" 1> /dev/null && echo "OK" || echo "KO" >&2
else
setSetting cloud_sync_status "false" 1> /dev/null && echo "OK" || echo "KO" >&2
Expand All @@ -57,13 +59,13 @@ API_setCloud(){
API_setToken(){
local token=$1
local user=$2
echo $token > "$emudeckFolder/.rat" && echo $user > "$emudeckFolder/.rau" && RetroArch_retroAchievementsSetLogin && DuckStation_retroAchievementsSetLogin && PCSX2QT_retroAchievementsSetLogin && echo "OK" || echo "KO" >&2
echo "${token}" > "${emudeckFolder:?}/.rat" && echo "${user}" > "${emudeckFolder}/.rau" && RetroArch_retroAchievementsSetLogin && DuckStation_retroAchievementsSetLogin && PCSX2QT_retroAchievementsSetLogin && echo "OK" || echo "KO" >&2
}

API_getToken(){
local escapedUserName=$1
local escapedPass=$2
curl --location --data-urlencode u='$escapedUserName' --data-urlencode p='$escapedPass' --request POST 'https://retroachievements.org/dorequest.php?r=login' && echo "OK" || echo "KO" >&2
curl --location --data-urlencode u="'${escapedUserName}'" --data-urlencode p="'${escapedPass}'" --request POST 'https://retroachievements.org/dorequest.php?r=login' && echo "OK" || echo "KO" >&2
}

API_cloudSyncHealth(){
Expand Down
70 changes: 39 additions & 31 deletions cloudSyncHealth.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/bash
#!/usr/bin/env bash

# shellcheck disable=2034

clear
. "$HOME/.config/EmuDeck/backend/functions/all.sh"
# shellcheck disable=1091
. "${HOME}/.config/EmuDeck/backend/functions/all.sh"

NONE='\033[00m'
RED='\033[01;31m'
Expand All @@ -12,86 +16,90 @@ WHITE='\033[01;37m'
BOLD='\033[1m'
UNDERLINE='\033[4m'
BLINK='\x1b[5m'

cloud_sync_upload_test(){
local emuName=$1
local emuName="${1}"

if [ ! -d $savesPath/$emuName ];then
# shellcheck disable=2154
if [ ! -d "${savesPath}/${emuName}" ];then
return 2
fi

echo "test" > "$savesPath/$emuName/.temp"
filePath="$savesPath/$emuName/.temp"
"$cloud_sync_bin" -q copyto --fast-list --checkers=50 --transfers=50 --low-level-retries 1 --retries 1 "$filePath" "$cloud_sync_provider":"$cs_user"Emudeck/saves/$emuName/.temp && rm -rf "$savesPath/$emuName/.temp" && return 0 || return 1
echo "test" > "${savesPath}/${emuName}/.temp"
filePath="${savesPath}/${emuName}/.temp"
# shellcheck disable=2154
"${cloud_sync_bin}" -q copyto --fast-list --checkers=50 --transfers=50 --low-level-retries 1 --retries 1 "${filePath}" "${cloud_sync_provider}":"${cs_user}Emudeck/saves/${emuName}/.temp" && rm -rf "${savesPath}/${emuName}/.temp" && return 0 || return 1
}

cloud_sync_dowload_test(){
local emuName=$1
local emuName="${1}"

if [ ! -d $savesPath/$emuName ];then
if [ ! -d "${savesPath}/${emuName}" ];then
return 2
fi

echo "test" > "$savesPath/$emuName/.temp"
filePath="$savesPath/$emuName/.temp"
"$cloud_sync_bin" -q copyto --fast-list --checkers=50 --transfers=50 --low-level-retries 1 --retries 1 "$cloud_sync_provider":"$cs_user"Emudeck/saves/$emuName/.temp "$filePath" && rm -rf "$savesPath/$emuName/.temp" && return 0 || return 1
echo "test" > "${savesPath}/${emuName}/.temp"
filePath="${savesPath}/${emuName}/.temp"
"${cloud_sync_bin}" -q copyto --fast-list --checkers=50 --transfers=50 --low-level-retries 1 --retries 1 "${cloud_sync_provider}":"${cs_user}Emudeck/saves/${emuName}/.temp" "$filePath" && rm -rf "${savesPath}/${emuName}/.temp" && return 0 || return 1

}

echo -e "${CYAN}CloudSync Status Report${NONE}"
echo ""

miArray=("Cemu" "citra" "dolphin" "duckstation" "MAME" "melonds" "mgba" "pcsx2" "ppsspp" "primehack" "retroarch" "rpcs3" "scummvm" "Vita3K" "yuzu" "ryujinx" )
miArray=( "Cemu" "citra" "dolphin" "duckstation" "MAME" "melonds" "mgba" "pcsx2" "ppsspp" "primehack" "retroarch" "rpcs3" "scummvm" "Vita3K" "yuzu" "ryujinx" )

upload="true"
download="true"
launchers="true"
echo -e "${YELLOW}Checking launchers${NONE}"
for entry in "$toolsPath/launchers/"*.sh
# shellcheck disable=2154
for entry in "${toolsPath}/launchers/"*.sh
do
if [ -f "$entry" ]; then
if grep -q "cloud_sync_startService" $entry; then
echo -e "$entry: ${GREEN}Success${NONE}"
if grep -q "cloud_sync_startService" "${entry}"; then
echo -e "${entry}: ${GREEN}Success${NONE}"
else
echo -e "$entry: ${RED}Failure${NONE}"
echo -e "${entry}: ${RED}Failure${NONE}"
launchers="false"
fi
fi
done

if grep -q "cloud_sync_startService" "$toolsPath/launchers/esde/emulationstationde.sh"; then
echo -e "$toolsPath/launchers/esde/emulationstationde.sh: ${GREEN}Success${NONE}"
if grep -q "cloud_sync_startService" "${toolsPath}/launchers/esde/emulationstationde.sh"; then
echo -e "${toolsPath}/launchers/esde/emulationstationde.sh: ${GREEN}Success${NONE}"
else
echo -e "$toolsPath/launchers/esde/emulationstationde.sh: ${RED}Failure${NONE}"
echo -e "${toolsPath}/launchers/esde/emulationstationde.sh: ${RED}Failure${NONE}"
fi

echo -e "${YELLOW}Checking for Windows old .lnk files${NONE}"
find "$savesPath" -type f -name "*.lnk" | while read -r entry
find "${savesPath}" -type f -name "*.lnk" | while read -r entry
do
rm -rf $entry
echo "found and deleted: $entry"
rm -rf "${entry}"
echo "found and deleted: ${entry}"
done

found_files="false"

for entry in "$savesPath"/**/*.lnk
for entry in "${savesPath}"/**/*.lnk
do
if [ -f "$entry" ]; then
rm -rf $entry
echo "found and deleted: $entry"
rm -rf "${entry}"
echo "found and deleted: ${entry}"
found_files="true"
fi
done

if [ "$found_files" = "false" ]; then
if [ "${found_files}" = "false" ]; then
echo "No files with the '.lnk' extension found."
fi

echo -e ""
echo -e "${YELLOW}Testing uploading${NONE}"
# Recorrer el array y ejecutar la función cloud_sync_upload_test para cada elemento
for elemento in "${miArray[@]}"; do
echo -ne "Testing $elemento upload..."
if cloud_sync_upload_test $elemento;then
echo -ne "Testing ${elemento} upload..."
if cloud_sync_upload_test "${elemento}"; then
echo -e "${GREEN}Success${NONE}"
elif [ $? = 2 ]; then
echo -e "${YELLOW}Save folder not found${NONE}"
Expand All @@ -104,8 +112,8 @@ echo ""
echo -e "${YELLOW}Testing downloading${NONE}"
# Recorrer el array y ejecutar la función cloud_sync_upload_test para cada elemento
for elemento in "${miArray[@]}"; do
echo -ne "Testing $elemento download..."
if cloud_sync_dowload_test $elemento;then
echo -ne "Testing ${elemento} download..."
if cloud_sync_dowload_test "${elemento}";then
echo -e "${GREEN}Success${NONE}"
elif [ $? = 2 ]; then
echo -e "${YELLOW}Save folder not found${NONE}"
Expand Down
94 changes: 52 additions & 42 deletions export.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
#!/usr/bin/env bash

clear
if [ ! -f "$HOME/.config/EmuDeck/backend/functions/all.sh" ]; then

if [ ! -f "${HOME}/.config/EmuDeck/backend/functions/all.sh" ]; then
text="$(printf "<b>EmuDeck installation not found</b>")"
zenity --error \
--title="EmuDeck Export tool" \
Expand All @@ -9,22 +11,29 @@ if [ ! -f "$HOME/.config/EmuDeck/backend/functions/all.sh" ]; then
--text="${text}" 2>/dev/null
exit
fi
. "$HOME/.config/EmuDeck/backend/functions/all.sh"
function customLocation(){

# shellcheck disable=1091
. "${HOME}/.config/EmuDeck/backend/functions/all.sh"
function customLocation () {
zenity --file-selection --directory --title="Select the root of the drive with your backup" 2>/dev/null
}
function checkSpace(){
local origin=$1
local destination=$2
local neededSpace=$(du -s "$emulationPath/saves" | awk '{print $1}')
local neededSpaceInHuman=$(du -sh "$origin" | awk '{print $1}')

function checkSpace () {
local origin="${1}"
local destination="${2}"
# shellcheck disable=2154,2155
local neededSpace=$(du -s "${emulationPath}/saves" | awk '{print $1}')
# shellcheck disable=2155
local neededSpaceInHuman=$(du -sh "${origin}" | awk '{print $1}')
#File Size on destination
local freeSpace=$(df -k "$destination" --output=avail | tail -1)
local freeSpaceInHuman=$(df -kh "$destination" --output=avail | tail -1)
local difference=$(($freeSpace - $neededSpace))
# shellcheck disable=2155
local freeSpace=$(df -k "${destination}" --output=avail | tail -1)
# shellcheck disable=2034,2155
local freeSpaceInHuman=$(df -kh "${destination}" --output=avail | tail -1)
local difference=$((freeSpace - neededSpace))

if [[ $difference -lt 0 ]]; then
text="$(printf "Make sure you have enough space in $destination. You need to have at least $neededSpaceInHuman available")"
text="$(printf "Make sure you have enough space in %s. You need to have at least %s available" "${destination}" "${neededSpaceInHuman}")"
zenity --question \
--title="EmuDeck Export tool" \
--width=450 \
Expand Down Expand Up @@ -59,27 +68,27 @@ else
fi

text="$(printf "Please pick the drive to export your saves.\n<b>Pick the root of the device, don't pick any subdirectory</b>")"
zenity --info \
# shellcheck disable=2154
zenity --info \
--title="EmuDeck Export tool" \
--width="${width}" \
--text="${text}" 2>/dev/null

destination=$(customLocation)
checkSpace "$emulationPath/saves/" "$destination"
checkSpace "${emulationPath}/saves/" "${destination}"

mkdir -p "$destination/EmuDeck/saves"
mkdir -p "${destination}/EmuDeck/saves"

for entry in "$emulationPath/saves/"*
for entry in "${emulationPath}/saves/"*
do
rsync -ravL --ignore-existing --progress "$entry" "$destination/EmuDeck/saves/" | awk -f $emudeckBackend/rsync.awk | zenity --progress --text="Exporting $entry to $destination/EmuDeck/saves/" --title="Exporting $entry..." --width=400 --percentage=0 --auto-close
# shellcheck disable=2154
rsync -ravL --ignore-existing --progress "${entry}" "${destination}/EmuDeck/saves/" | awk -f "${emudeckBackend}/rsync.awk" | zenity --progress --text="Exporting ${entry} to ${destination}/EmuDeck/saves/" --title="Exporting ${entry}..." --width=400 --percentage=0 --auto-close
done



size=0;
size=$((size + $(du -sb "$destination/EmuDeck/saves/" | cut -f1)))
if [ "$size" -gt 4096 ]; then
if [ -d "$emulationPath/storage" ]; then
size=$((size + $(du -sb "${destination}/EmuDeck/saves/" | cut -f1)))
if [ $size -gt 4096 ]; then
if [ -d "${emulationPath}/storage" ]; then
text="$(printf "<b>Storage folder found in your internal Drive!</b>\nLet's export that one too")"
zenity --question \
--title="EmuDeck Export tool" \
Expand All @@ -90,13 +99,13 @@ if [ "$size" -gt 4096 ]; then
ans=$?
if [ $ans -eq 0 ]; then

checkSpace "$emulationPath/storage/" "$destination"
checkSpace "${emulationPath}/storage/" "${destination}"

mkdir -p "$destination/EmuDeck/storage"
mkdir -p "${destination}/EmuDeck/storage"

for entry in "$emulationPath/storage/"*
for entry in "${emulationPath}/storage/"*
do
rsync -ravL --ignore-existing --progress "$entry" "$destination/EmuDeck/storage/" | awk -f $emudeckBackend/rsync.awk | zenity --progress --text="Exporting $entry to $destination/EmuDeck/storage/" --title="Exporting $entry..." --width=400 --percentage=0 --auto-close
rsync -ravL --ignore-existing --progress "${entry}" "${destination}/EmuDeck/storage/" | awk -f "${emudeckBackend}/rsync.awk" | zenity --progress --text="Exporting ${entry} to ${destination}/EmuDeck/storage/" --title="Exporting ${entry}..." --width=400 --percentage=0 --auto-close
done

else
Expand All @@ -105,7 +114,7 @@ if [ "$size" -gt 4096 ]; then

fi

if [ -d "$emulationPath/bios" ]; then
if [ -d "${emulationPath}/bios" ]; then
text="$(printf "Do you want to export all your bios?")"
zenity --question \
--title="EmuDeck Export tool" \
Expand All @@ -116,21 +125,21 @@ if [ "$size" -gt 4096 ]; then
ans=$?
if [ $ans -eq 0 ]; then

checkSpace "$emulationPath/bios/" "$destination"
checkSpace "${emulationPath}/bios/" "${destination}"

mkdir -p "$destination/EmuDeck/bios"
mkdir -p "${destination}/EmuDeck/bios"

for entry in "$emulationPath/bios/"*
for entry in "${emulationPath}/bios/"*
do
rsync -ravL --ignore-existing --progress "$entry" "$destination/EmuDeck/bios/" | awk -f $emudeckBackend/rsync.awk | zenity --progress --text="Exporting $entry to $destination/EmuDeck/bios/" --title="Exporting $entry..." --width=400 --percentage=0 --auto-close
rsync -ravL --ignore-existing --progress "${entry}" "${destination}/EmuDeck/bios/" | awk -f "${emudeckBackend}/rsync.awk" | zenity --progress --text="Exporting ${entry} to ${destination}/EmuDeck/bios/" --title="Exporting ${entry}..." --width=400 --percentage=0 --auto-close
done

else
echo "no bios"
fi
fi

if [ -d "$emulationPath/roms" ]; then
if [ -d "${emulationPath}/roms" ]; then
text="$(printf "Do you want to export all your roms?")"
zenity --question \
--title="EmuDeck Export tool" \
Expand All @@ -141,21 +150,22 @@ if [ "$size" -gt 4096 ]; then
ans=$?
if [ $ans -eq 0 ]; then

checkSpace "$emulationPath/roms/" "$destination"
checkSpace "${emulationPath}/roms/" "${destination}"

mkdir -p "$destination/EmuDeck/roms"
mkdir -p "${destination}/EmuDeck/roms"

for entry in "$emulationPath/roms/"*
for entry in "${emulationPath}/roms/"*
do
rsync -ravL --ignore-existing --progress "$entry" "$destination/EmuDeck/roms/" | awk -f $HOME/.config/EmuDeck/backend/rsync.awk | zenity --progress --text="Exporting $entry to $destination/EmuDeck/roms/" --title="Exporting $entry..." --width=400 --percentage=0 --auto-close
rsync -ravL --ignore-existing --progress "${entry}" "${destination}/EmuDeck/roms/" | awk -f "${HOME}/.config/EmuDeck/backend/rsync.awk" | zenity --progress --text="Exporting ${entry} to ${destination}/EmuDeck/roms/" --title="Exporting ${entry}..." --width=400 --percentage=0 --auto-close
done

else
echo "no roms"
fi
fi

if [ -d "$ESDEscrapData" ]; then
# shellcheck disable=2154
if [ -d "${ESDEscrapData}" ]; then
text="$(printf "Do you want to export all your EmulationStation media?")"
zenity --question \
--title="EmuDeck Export tool" \
Expand All @@ -166,13 +176,13 @@ if [ "$size" -gt 4096 ]; then
ans=$?
if [ $ans -eq 0 ]; then

checkSpace "$ESDEscrapData" "$destination"
checkSpace "${ESDEscrapData}" "${destination}"

mkdir -p "$destination/EmuDeck/tools/downloaded_media"
mkdir -p "${destination}/EmuDeck/tools/downloaded_media"

for entry in "$ESDEscrapData/"*
for entry in "${ESDEscrapData}/"*
do
rsync -ravL --ignore-existing --progress "$entry" "$destination/EmuDeck/tools/downloaded_media/" | awk -f $HOME/.config/EmuDeck/backend/rsync.awk | zenity --progress --text="Exporting $entry to $destination/EmuDeck/tools/downloaded_media/" --title="Exporting $entry..." --width=400 --percentage=0 --auto-close
rsync -ravL --ignore-existing --progress "${entry}" "${destination}/EmuDeck/tools/downloaded_media/" | awk -f "${HOME}/.config/EmuDeck/backend/rsync.awk" | zenity --progress --text="Exporting ${entry} to ${destination}/EmuDeck/tools/downloaded_media/" --title="Exporting ${entry}..." --width=400 --percentage=0 --auto-close
done

else
Expand Down
Loading