-
Notifications
You must be signed in to change notification settings - Fork 0
/
podman_reset.sh
executable file
·86 lines (74 loc) · 1.88 KB
/
podman_reset.sh
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# Input Vars
USER_NAME=${1}
GRAPH_ROOT=${2}
F_PromptContinue () {
read -p "Are you sure [yn]? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Aborting!"
exit 1
fi
}
# Validate we are root
if [[ `id -u` -ne 0 ]]; then
echo
echo "ERROR: You must be root!"
exit 1
fi
# Validate user
if [[ ! -z ${USER_NAME} && ${USER_NAME} != '' ]]; then
id -u ${USER_NAME} >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo
echo "ERROR: User is not Valid"
exit 2
fi
else
echo
echo "ERROR: No User provided"
exit 2
fi
# Validate Path
if [[ ! -z ${GRAPH_ROOT} && ${GRAPH_ROOT} != '' && ${GRAPH_ROOT} != '/' ]]; then
if [[ ! -d ${GRAPH_ROOT} ]]; then
echo
echo "ERROR: Graphroot path does not exist"
exit 3
fi
else
echo
echo "ERROR: No Graphroot Path proviced"
exit 3
fi
USER_UID=$(id -u ${USER_NAME})
USER_GID=$(id -g ${USER_NAME})
USER_HOME=$(eval echo ~${USER_NAME})
echo
echo "Resetting ${USER_NAME}, validate details below"
echo "Username: ${USER_NAME}"
echo "UID: ${USER_UID}"
echo "GID: ${USER_GID}"
echo "User Home: ${USER_HOME}"
echo "GraphRoot: ${GRAPH_ROOT}"
echo "User Image Storage: ${GRAPH_ROOT}/${USER_NAME}"
echo
F_PromptContinue
# Reset Runroot
mkdir -p /tmp/run-${USER_UID}
chown ${USER_NAME} /tmp/run-${USER_UID}
chmod 700 /tmp/run-${USER_UID}
# Setup Podman Storage
mkdir -p ${GRAPH_ROOT}/${USER_NAME}
chown ${USER_UID}:${USER_GID} ${GRAPH_ROOT}/${USER_NAME}
chmod 750 ${GRAPH_ROOT}/${USER_NAME}
# Reset Podman config
rm -f ${USER_HOME}/.config/containers/storage.conf
su - ${USER_NAME} -c "podman info >/dev/null"
# Update User Storage path
DEFAULT_PATH=${USER_HOME}/.local/share/containers/storage
SHARED_PATH=${GRAPH_ROOT}/${USER_NAME}
sed -i "s#${DEFAULT_PATH}#${SHARED_PATH}#g" ${USER_HOME}/.config/containers/storage.conf
# Test Podman
echo
su - ${USER_NAME} -c "podman info >/dev/null && echo 'Reset OK' || echo 'Failed to Reset'"