-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-installed
More file actions
executable file
·63 lines (53 loc) · 1.28 KB
/
get-installed
File metadata and controls
executable file
·63 lines (53 loc) · 1.28 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
# send lists of installed programs to dir specified by date
set -e
if (("$(id -u)" == 0)); then
user_home="$(getent passwd "${SUDO_USER}" | cut -d':' -f6)"
user="${user_home:6}"
else
user_home="${HOME}"
user="${USER}"
fi
base_dir="${user_home}/documents/misc/installed"
current_date="$(date "+%Y%m%d")"
new_dir="${base_dir}/${current_date}"
get_installed() {
if [[ -n "${with_git}" ]]; then
if [[ ! -d "${base_dir}/.git" ]]; then
git init "${base_dir}"
fi
fi
if [[ -d "${new_dir}" ]]; then
new_dir="${base_dir}/${current_date}-$(date '+%H:%M:%S')"
fi
mkdir "${new_dir}" &&
pacman -Q >"${new_dir}/all"
cut -d' ' -f1 "${new_dir}/all" >"${new_dir}/no_version"
pacman -Qm | cut -d' ' -f1 >"${new_dir}/aur"
diff -y "${new_dir}/no_version" "${new_dir}/aur" |
awk '{print $2}' |
sed '/</d' >"${new_dir}/no_aur"
if [[ -n "${with_git}" ]]; then
(cd "${base_dir}" && git add . && git commit -m "${user} $(date '+%c')")
fi
printf -- '%s %s\n' "Installed programs backed up to" "${new_dir}"
}
case "$1" in
-g | --git)
with_git="ON"
get_installed
;;
-h | --help)
cat <<-EOF
Usage:
getInstalled [options] [dir]
OPTIONS
-g, --git Use git for storing history
EOF
exit 0
;;
*)
get_installed
;;
esac
exit 0