Skip to content

Commit

Permalink
fix(update): removes the requirement of privileged access
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabpain authored and ankitrgadiya committed Aug 11, 2023
1 parent 995a9c5 commit 8857138
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion riocli/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def update(silent: bool) -> None:
else:
update_appimage(version=latest)
except Exception as e:
click.secho('{} Failed to update the CLI'.format(e), fg=Colors.RED)
click.secho('{} Failed to update: {}'.format(Symbols.ERROR, e), fg=Colors.RED)
raise SystemExit(1) from e

click.secho('{} Update successful!'.format(Symbols.SUCCESS),
Expand Down
26 changes: 16 additions & 10 deletions riocli/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import sys
import typing
from pathlib import Path
from shutil import get_terminal_size
from shutil import get_terminal_size, move
from tempfile import TemporaryDirectory
from uuid import UUID

Expand Down Expand Up @@ -210,12 +210,6 @@ def update_appimage(version: str):
if not version:
raise ValueError('version cannot be empty')

if os.getuid() != 0:
click.secho(
'{} Please run this as the root user.'.format(Symbols.WARNING),
fg=Colors.YELLOW)
raise SystemExit(1)

# URL to get the latest release metadata
url = 'https://api.github.com/repos/rapyuta-robotics/rapyuta-io-cli/releases/latest'

Expand All @@ -237,11 +231,23 @@ def update_appimage(version: str):
raise Exception(
'Failed to retrieve the download URL for the latest AppImage')

with TemporaryDirectory() as tmp:
# Download and save the binary in a temp dir
# Download the AppImage
try:
response = requests.get(asset.browser_download_url)
except Exception as e:
raise Exception('Failed to download the new version: {}'.format(e))

with TemporaryDirectory() as tmp:
# Save the binary in a temp dir
save_to = Path(tmp) / 'rio'
save_to.write_bytes(response.content)
os.chmod(save_to, 0o755)
# Now replace the current executable with the new file
os.rename(save_to, sys.executable)
try:
os.remove(sys.executable)
move(save_to, sys.executable)
except OSError as e:
click.secho('{} Please consider running as a root user.'.format(Symbols.WARNING), fg=Colors.YELLOW)
raise e
except Exception as e:
raise e

0 comments on commit 8857138

Please sign in to comment.