Package: grantme
轻量级权限管理工具：grantme || Lightweight access management tool: grantmegrantme是一个用python写的轻量级机器访问管理命令行工具。它可以授权用户一定时限内的共享访问权限（如，用于debug）和独占访问权限（如，用于性能测试），从而共享同一台机器的用户可以协调机器使用。它是非强制、纯建议性的因为它不能放置恶意用户无视访问权限授权地使用机器。grantmeis a lightweight machine access management CLI tool written in Python.
It can grant timedshared access(e.g., for debugging) andexclusive access(e.g., for performance evaluation) to individual users so that when users of shared machines can coordinate their usage.
It is noncompulsory and purely advisory because it cannot prevent malicious users from ignoring the access granted.使用方式 || Usage规则 || Rules返回值 || Return values依赖 || Requirements安装与卸载 || Installation and uninstallation参与开发 || Contribute测试 || Testing使用方式 || Usage规则 || Rules当未授权任何访问权限时，用户可任意获取共享或独占全县。When no access is granted, users can require either shared or exclusive access.当已授予共享访问时，未授权用户可获取共享权限。若仅一位用户被授予共享权限，该用户可升级其为独占权限。When some shared access is granted, other users can require additional shared access.
When there is only one user granted with shared access, that user can upgrade his/her access to be exclusive.当已授予独占访问时，未授权用户不可获取任何权限。When exclusive access is granted, other users cannot require any access.权限在过期后自动失效。已授予权限的用户可提前放弃或延长所持有权限。Grated access expires after given duration.
Users with granted access can early revoke or prolong their access.返回值 || Return valuesgrantme根据操作结果返回相应值。grantmereturns values according to operation results.0：成功 || Success6：升级权限失败 || Failed to upgrade access7：获取权限失败 || Failed to obtain access255：其他错误 || Other errors这些返回值可于集成grantme于其他脚本（如，自动化测试）。These return values can be used for integratinggrantmeinto other scripts (e.g., automatic testing).#!/bin/bash./grantme--modeexclusive--duration1hif[$?-ne0]thenecho"I can't get the lock, cry cry."exit1fi# do work./grantme--revoke依赖 || Requirementsgrantme要求Python 3.7级以上版本。用户登陆是自动打印授权状态功能需要Ubuntu Linux发行版。grantmerequires Python 3.7+.
Automatically printing access status upon user login requires Ubuntu Linux distribution.安装与卸载 || Installation and uninstallation安装并初始化：To install and initialize:pip3installgrantme
grantme--init# 可能需要sudo权限 || potentially requires sudo privilegegrantme --init会创建/var/lib/grantme目录，并在Ubuntu Linux发行版下在/etc/update-motd.d生成<NN>-grantme-status（<NN>数字，具体值由机器状态决定）脚本文件用于用户登录时打印授权状态。卸载时需手动删除：grantme --initcreates/var/lib/grantmedirectory，and under Ubuntu Linux distribution it creates<NN>-grantme-status(<NN>are numbers, whose exact values depend on the machines) script file under/etc/update-motd.ddirectory for automatically printing access status upon user login.
To uninstall, you need to manually remove them:# 可能需要sudo权限 || potentially requires sudo privilegerm-r/var/lib/grantme
rm/etc/update-motd.d/<NN>-grantme-status# 将<NN>替换为具体数值 || replace <NN> with the actual numbers参与开发 || Contribute目前，grantme由个人维护。欢迎用户提交缺陷报告和Pull Request。Currently,grantmeis maintained by an individual.
Bug reports and pull requests are welcomed.测试 || Testing在项目根目录下执行以下命令以运行测试。Execute the following command in the project's root directory to run tests.python-munittestdiscover增加新功能、修补漏洞后请在tests目录下增加或修改相应测试。在所有测试通过后提交Pull Request。Please add or modify test cases under thetestsdirectory when adding new features or fixing bugs.
Make sure all tests have passed before submitting pull requests.