Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add, remove "alignak" user script? #5

Closed
spea1 opened this issue Jan 10, 2017 · 2 comments
Closed

add, remove "alignak" user script? #5

spea1 opened this issue Jan 10, 2017 · 2 comments

Comments

@spea1
Copy link

spea1 commented Jan 10, 2017

Add user "alignak"

#!/bin/sh
user_alignak=alignak
home_dir_alignak=/home/$user_alignak

HOME_SEARCH=`grep ^$user_alignak: /etc/passwd | cut -d: -f 6`
if [[ ! "$HOME_SEARCH" ]]
 then
  if [ ! -d "$home_dir_alignak" ]; then
    sudo useradd -m -p $user_alignak $user_alignak
    sudo adduser $user_alignak sudo
    id $user_alignak
    echo "Info: Create "$user_alignak" user account with the same password."
    echo "Info: Please change the password for this account NOW!!!"
    passwd $user_alignak
   else
    echo "Info:  "$home_dir_alignak" exist."
  fi
 else
  echo "Info:  Alignak-User "$user_alignak" exist."
fi

Remove user "alignak"

#!/bin/sh
user_alignak=alignak
home_dir_alignak=/home/$user_alignak

HOME_SEARCH=`grep ^$user_alignak: /etc/passwd | cut -d: -f 6`
if [[ "$HOME_SEARCH" ]]
 then
  if [ -d "$home_dir_alignak" ]; then
    sudo deluser --remove-home $user_alignak
    id $user_alignak
    echo "Info: Delete "$user_alignak" user account and files."
  fi
 else
  echo "Info:  User "$user_alignak" not exist."
fi
@mohierf
Copy link
Contributor

mohierf commented Jan 11, 2017

the user alignak is created thanks to the set_permissions.sh script that will be available as soon as this PR Alignak-monitoring/alignak#667 will be merged.

But I find interesting to add those proposed scripts anyway 😉 but you should make some modifications to adapt them. Here is what is done in the set_permissions.sh script:

## Create user and group
echo "Checking / creating 'alignak' user and users group"
# Note: if the user exists, it's properties won't be changed (gid, home, shell)
adduser  --quiet --system --home /var/lib/alignak --no-create-home --group alignak || true

## Create nagios group
echo "Checking / creating 'nagios' users group"
addgroup --system nagios || true

## Add alignak to nagios group
id -Gn alignak |grep -E '(^|[[:blank:]])nagios($|[[:blank:]])' >/dev/null ||
    echo "Adding user 'alignak' to the nagios users group"
    adduser alignak nagios

## Create directories with proper permissions
for i in /usr/local/etc/alignak /usr/local/var/run/alignak /usr/local/var/log/alignak /usr/local/var/lib/alignak /usr/local/var/libexec/alignak
do
    mkdir -p $i
    echo "Setting 'alignak' ownership on: $i"
    chown -R alignak:alignak $i
done

echo "Setting file permissions on: /usr/local/etc/alignak"
find /usr/local/etc/alignak -type f -exec chmod 664 {} +
find /usr/local/etc/alignak -type d -exec chmod 775 {} +

echo "Terminated"

@spea1
Copy link
Author

spea1 commented Jan 11, 2017

Nice to see how it should be correct ;)

@spea1 spea1 closed this as completed Jan 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants