Skip to content
Draft
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
52 changes: 22 additions & 30 deletions assets/linux/updateBiglyBT
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,29 @@ exists () {
type "$1" >/dev/null 2>/dev/null
}

if [ "$1" = "rerun" ]; then
ISRERUN=1
else
ISRERUN=0
fi
declare PARAMS=( "${@:3}" )
[[ "$1" = "rerun" ]] && declare -ri ISRERUN=1


if [ $ISRERUN -eq 1 ]; then
PARAMS=( "${@:3}" )
else
SCRIPT=`realpath $0`
SCRIPTPATH=`dirname $SCRIPT`
if [[ ! $ISRERUN ]]; then
SCRIPT=$(realpath "$0")
SCRIPTPATH=$(dirname "$SCRIPT")

if [ "$1" = "" ]; then
if [[ ! "$1" ]]; then
# No params were passed in, make ones up
PARAMS=( "com.biglybt.update.Updater" "updateonly" "${SCRIPTPATH}" "${HOME}/.biglybt" )
else
PARAMS=( "${@}" )
fi

for i in "${!PARAMS[@]}"; do
if [ "${PARAMS[$i]}" = "updateonly" ] || [ "${PARAMS[$i]}" = "restart" ]; then
PARAM_IDX_APPPATH=$(( $i + 1 ))
PARAM_IDX_APPPATH=$(( i + 1 ))
break
fi
done

if [ ! -w "${PARAMS[${PARAM_IDX_APPPATH}]}" ]; then
# Can't write to appdir, going to need super user

if [ "$EUID" -ne 0 ]; then
if (( EUID != 0 )); then
if exists "pkexec"; then
CMD="pkexec"
elif exists "gksudo"; then
Expand All @@ -50,15 +43,14 @@ else
CMD="sudo"
else
echo "Can't get write access to ${PARAMS[${PARAM_IDX_APPPATH}]}"
echo "Please run ${SCRIPT} with higher access level"
echo "Please run $SCRIPT with higher access level"
exit 1
fi

echo Running as root..
$CMD $SCRIPT "rerun" "${USER}" ${PARAMS[@]}
if [ $? -ne 0 ]; then
echo "Could not run with ${CMD}. Trying one more time with sudo"
sudo $SCRIPT "rerun" "${USER}" ${PARAMS[@]}
echo "Running as root..."
if ! $CMD "$SCRIPT" "rerun" "$USER" "${PARAMS[@]}"; then
echo "Could not run with $CMD. Trying one more time with sudo"
sudo "$SCRIPT" "rerun" "$USER" "${PARAMS[@]}"
fi
exit
fi
Expand All @@ -68,18 +60,18 @@ else
fi

for i in "${!PARAMS[@]}"; do
if [ "${PARAMS[$i]}" = "updateonly" ] || [ "${PARAMS[$i]}" = "restart" ]; then
PARAM_IDX_USERPATH=$(( $i + 2 ))
if [[ "${PARAMS[$i]}" = "updateonly" || "${PARAMS[$i]}" = "restart" ]]; then
PARAM_IDX_USERPATH=$(( i + 2 ))
break
fi
done

echo Running Updater..
java -cp "${PARAMS[${PARAM_IDX_USERPATH}]}/plugins/azupdater/Updater.jar" ${PARAMS[@]}
echo "Running Updater..."
java -cp "${PARAMS[${PARAM_IDX_USERPATH}]}/plugins/azupdater/Updater.jar" "${PARAMS[@]}"

if [ $ISRERUN -eq 1 ]; then
echo Ensuring $2 still owns ${PARAMS[${PARAM_IDX_USERPATH}]}
chown -R $2:$2 ${PARAMS[${PARAM_IDX_USERPATH}]}
if [[ $ISRERUN ]]; then
echo "Ensuring $2 still owns ${PARAMS[${PARAM_IDX_USERPATH}]}"
chown -R "$2":"$2" "${PARAMS[${PARAM_IDX_USERPATH}]}"
fi

echo Done
echo Done