File: pam_snapper_userdel.sh

package info (click to toggle)
snapper 0.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,576 kB
  • ctags: 2,049
  • sloc: cpp: 15,605; sh: 11,424; ansic: 1,401; makefile: 287; python: 159
file content (53 lines) | stat: -rwxr-xr-x 1,178 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
#
# Copyright (c) 2013 SUSE
#
# Written by Matthias G. Eckermann <mge@suse.com>
#
# Run this shell script to delete a USER and all data in $HOME
#
# GLOBAL Settings
#

CMD_BTRFS="/sbin/btrfs"
CMD_SNAPPER="/usr/bin/snapper"
CMD_EGREP="grep -E"
CMD_PAM_CONFIG="/usr/sbin/pam-config"
CMD_SED="sed"
CMD_USERADD="useradd -m"
CMD_USERDEL="userdel -r"
CMD_CHOWN="chown"
#
SNAPPERCFGDIR="/etc/snapper/configs"
HOMEHOME=/home
DRYRUN=1
MYUSER=$1

# Usage
if [ "0$MYUSER" == "0" ]; then
	echo "USAGE: $0 <username>"
	exit 1
fi

# Sanity-Check: ist $HOMEHOME a btrfs filesystem
${CMD_BTRFS} filesystem df ${HOMEHOME} 2>&1 > /dev/null
RETVAL=$?
if [ ${RETVAL} != 0 ]; then
	echo "ERROR $0: ${HOMEHOME} is not on btrfs. Exiting ..."
	exit 2
fi

if [ ${DRYRUN} == 0 ] ; then
	# Delete the snapper configuration
	# This deletes $SNAPPERCFGDIR/home_${MYUSER}
	# removes "home_${MYUSER}" from /etc/sysconfig/snapper
	# and deletes all snapshots
	${CMD_SNAPPER} -c home_${MYUSER} delete-config
	# Delete the USER's home subvolume
	${CMD_BTRFS} subvol delete /${HOMEHOME}/${MYUSER}
	# Delete the USER
	${CMD_USERDEL} ${MYUSER}
else
	echo -e "#"
	echo "DRYRUN - no changes submitted"
fi