diff --git a/delete_mass_primtux_users.sh b/delete_mass_primtux_users.sh new file mode 100755 index 0000000000000000000000000000000000000000..f09b5ecaaf2d92775bda21bd9ddc4917191b6e50 --- /dev/null +++ b/delete_mass_primtux_users.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# Copyright (C) 2018 Tetras Libre <Contact@Tetras-Libre.fr> +# Author: Beniamine, David <David.Beniamine@Tetras-Libre.fr> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +usage(){ + echo "Usage $0 [uids.txt]" + echo "Reads a list of name corresponding to some ldap users" + echo "and remove each of them" + echo "If the list is not specified, prompt for removing all Primtux users" +} + +if [ -z "$1" ] +then + read -p "Do you actually want to remove all Primtux users [yes/No] ?" ans + if [ "$ans" != "yes" ] + then + echo "Aborting on user request" + usage + exit 1 + fi + set -x + file="$$-uids.txt" + ldapsearch -x cn=Primtux | awk '/^memberUid/{print $2}' > $file +else + + if [ ! -f "$1" ] + then + echo "$1 is not a file" + usage + exit 1 + fi + file="$1" +fi + +rm -f uids.txt +scriptbinpath="/usr/share/lcs/sbin" + +if [ ! -x $scriptbinpath/userDel.pl ] +then + echo "Critical error : $scriptbinpath/userDel.pl does not exist or is not executable" + exit 1 +fi + +while read uid +do + echo "Deleting user $uid" + $scriptbinpath/userDel.pl $uid +done < $file +#rm -f $$-uids.txt