-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclone-delete.sh
More file actions
executable file
·47 lines (40 loc) · 1.44 KB
/
clone-delete.sh
File metadata and controls
executable file
·47 lines (40 loc) · 1.44 KB
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
#!/bin/bash
set -euo pipefail
if [[ "$(id -u)" -ne 0 ]]; then
echo "You need to be root."
exit 1
fi
usage() { echo "Usage: $0 ROOT_FS_PATH" 1>&2; exit 1; }
[[ $# -eq 1 ]] || usage
root_fs_path="$(realpath -s "$1")"
target="$(findmnt --all --first --noheadings --list --output TARGET --notruncate --target "$root_fs_path")"
if [[ $target =~ ^/[^/]+ ]]; then
source="$(findmnt --all --first --noheadings --list --output SOURCE --notruncate --target "$root_fs_path")"
if [ ! -d "$root_fs_path/var" ]; then
echo "Not a directory: $root_fs_path/var"
exit 1
fi
else
echo "Refusing to operate on target: $target"
exit 1
fi
# note the wildcard expansion in /var/lib/bluetooth needs root permissions
to_delete_files=(
"$root_fs_path"/var/lib/bluetooth/[0-9A-Fa-f]*
"$root_fs_path"/var/log/*
"$root_fs_path"/var/cache/*
"$root_fs_path"/var/lib/systemd/random-seed
)
echo -e "\nv WARNING v WARNING v WARNING v WARNING v WARNING v WARNING v WARNING v\n"
echo "You are about to delete the following files"
echo -n "from $source"
echo -e " WITH ROOT PERMISSIONS.\n\nTo be deleted:"
for elem in "${to_delete_files[@]}"; do echo "$elem"; done
echo -e "\n^ WARNING ^ WARNING ^ WARNING ^ WARNING ^ WARNING ^ WARNING ^ WARNING ^\n"
read -n 1 -r -p "ARE YOU SURE? [yN] " REPLY
echo -e "\n"
if [[ $REPLY =~ ^[Yy]$ ]]
then
for elem in "${to_delete_files[@]}"; do rm -rvf "$elem"; done
fi
# spell: ignore noheadings notruncate