feat: make start script work in an unintened cli

This commit is contained in:
Nicolas Meienberger 2023-08-26 11:28:22 +02:00 committed by Nicolas Meienberger
parent 8be2856eed
commit 5f71ffcfa4
4 changed files with 34 additions and 12 deletions

View file

@ -52,9 +52,16 @@ export class SystemExecutors {
}; };
private ensureFilePermissions = async (rootFolderHost: string, logSudoRequest = true) => { private ensureFilePermissions = async (rootFolderHost: string, logSudoRequest = true) => {
if (logSudoRequest) { // if we are running as root, we don't need to change permissions
console.log('\nTipi is asking for your password\nin order to ensure permissions\non copied files and folders\n'); if (process.getuid && process.getuid() === 0) {
return;
} }
if (logSudoRequest) {
const logger = new TerminalSpinner('');
logger.log('Tipi needs to change permissions on some files and folders and will ask for your password.');
}
const filesAndFolders = [ const filesAndFolders = [
path.join(rootFolderHost, 'apps'), path.join(rootFolderHost, 'apps'),
path.join(rootFolderHost, 'logs'), path.join(rootFolderHost, 'logs'),
@ -134,10 +141,12 @@ export class SystemExecutors {
* This method will start Tipi. * This method will start Tipi.
* It will copy the system files, generate the system env file, pull the images and start the containers. * It will copy the system files, generate the system env file, pull the images and start the containers.
*/ */
public start = async () => { public start = async (permissions = true) => {
const spinner = new TerminalSpinner('Starting Tipi...'); const spinner = new TerminalSpinner('Starting Tipi...');
try { try {
await this.ensureFilePermissions(this.rootFolder); if (permissions) {
await this.ensureFilePermissions(this.rootFolder);
}
spinner.start(); spinner.start();
spinner.setMessage('Copying system files...'); spinner.setMessage('Copying system files...');
@ -145,7 +154,9 @@ export class SystemExecutors {
spinner.done('System files copied'); spinner.done('System files copied');
await this.ensureFilePermissions(this.rootFolder, false); if (permissions) {
await this.ensureFilePermissions(this.rootFolder, false);
}
spinner.setMessage('Generating system env file...'); spinner.setMessage('Generating system env file...');
spinner.start(); spinner.start();
@ -331,7 +342,7 @@ export class SystemExecutors {
// eslint-disable-next-line no-promise-executor-return // eslint-disable-next-line no-promise-executor-return
await new Promise((resolve) => setTimeout(resolve, 3000)); await new Promise((resolve) => setTimeout(resolve, 3000));
const childProcess = spawn('./runtipi-cli', [process.argv[1] as string, 'start']); const childProcess = spawn('./runtipi-cli', [process.argv[1] as string, 'start', '--no-permissions']);
childProcess.stdout.on('data', (data) => { childProcess.stdout.on('data', (data) => {
process.stdout.write(data); process.stdout.write(data);

View file

@ -20,9 +20,10 @@ const main = async () => {
program program
.command('start') .command('start')
.description('Start tipi') .description('Start tipi')
.action(async () => { .option('--no-permissions', 'Skip permissions check')
.action(async (options) => {
const systemExecutors = new SystemExecutors(); const systemExecutors = new SystemExecutors();
await systemExecutors.start(); await systemExecutors.start(options.permissions);
}); });
program program

View file

@ -52,4 +52,10 @@ export class TerminalSpinner {
logUpdate.done(); logUpdate.done();
} }
log(message: string) {
logUpdate(message);
logUpdate.done();
}
} }

View file

@ -186,10 +186,14 @@ curl --location "$URL" -o ./runtipi-cli
chmod +x ./runtipi-cli chmod +x ./runtipi-cli
# Check if user is in docker group # Check if user is in docker group
if ! groups | grep -q docker; then if [ "$(id -u)" -ne 0 ]; then
echo "User is not in docker group. Please make sure your user is allowed to run docker commands and restart the script." if ! groups | grep -q docker; then
echo "See https://docs.docker.com/engine/install/linux-postinstall/ for more information." echo ""
exit 1 echo "User is not in docker group. Please make sure your user is allowed to run docker commands and restart the script."
echo "See https://docs.docker.com/engine/install/linux-postinstall/ for more information."
echo ""
exit 1
fi
fi fi
./runtipi-cli start ./runtipi-cli start