func (u *SessionUtil) createSudoersFileIfNotPresent(log log.T) error {

	// Return if the file exists
	if _, err := os.Stat(sudoersFile); err == nil {
		log.Infof("File %s already exists", sudoersFile)
		u.changeModeOfSudoersFile(log)
		return err
	}

	// Create a sudoers file for ssm-user
	file, err := os.Create(sudoersFile)
	if err != nil {
		log.Errorf("Failed to add %s to sudoers file: %v", appconfig.DefaultRunAsUserName, err)
		return err
	}
	defer file.Close()

	file.WriteString(fmt.Sprintf("# User rules for %s\n", appconfig.DefaultRunAsUserName))
	file.WriteString(fmt.Sprintf("%s ALL=(ALL) NOPASSWD:ALL\n", appconfig.DefaultRunAsUserName))
	log.Infof("Successfully created file %s", sudoersFile)
	u.changeModeOfSudoersFile(log)
	return nil
}
// createSudoersFileIfNotPresent will create the sudoers file if not present.
createSudoersFileIfNotPresent will create the sudoers file if not present.
// createSudoersFileIfNotPresent will create the sudoers file if not present .
func (u *SessionUtil) createSudoersFileIfNotPresent(log log.T) error {
	if _, err := os.Stat(sudoersFile); err == nil {
		log.Infof("File %s already exists", sudoersFile)
		u.changeModeOfSudoersFile(log)
		return err
	}
	file, err := os.Create(sudoersFile)
	if err != nil {
		log.Errorf("Failed to add %s to sudoers file: %v", appconfig.DefaultRunAsUserName, err)
		return err
	}
	defer file.Close()
	file.WriteString(fmt.Sprintf("# User rules for %s\n", appconfig.DefaultRunAsUserName))
	file.WriteString(fmt.Sprintf("%s ALL=(ALL) NOPASSWD:ALL\n", appconfig.DefaultRunAsUserName))
	log.Infof("Successfully created file %s", sudoersFile)
	u.changeModeOfSudoersFile(log)
	return nil
}
func ( u * SessionUtil ) createSudoersFileIfNotPresent ( log log . T ) error { if _ , err := os . Stat ( sudoersFile ) ; err == nil { log . Infof ( " " , sudoersFile ) u . changeModeOfSudoersFile ( log ) return err } file , err := os . Create ( sudoersFile ) if err != nil { log . Errorf ( " " , appconfig . DefaultRunAsUserName , err ) return err } defer file . Close ( ) file . WriteString ( fmt . Sprintf ( " \n " , appconfig . DefaultRunAsUserName ) ) file . WriteString ( fmt . Sprintf ( " \n " , appconfig . DefaultRunAsUserName ) ) log . Infof ( " " , sudoersFile ) u . changeModeOfSudoersFile ( log ) return nil }
createSudoersFileIfNotPresent will create the sudoers file if not present.
createSudoersFileIfNotPresent will create the sudoers file if not present .
// Return if the file exists // Create a sudoers file for ssm-user