-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup_packages
More file actions
executable file
·109 lines (94 loc) · 2.08 KB
/
backup_packages
File metadata and controls
executable file
·109 lines (94 loc) · 2.08 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
#
# Backup the names of installed packages.
#
# Dependencies: coreutils, pacman, util-linux
set -o nounset -o pipefail
readonly DEFAULT_BACKUP_DIR="${HOME}/backup/pacman"
readonly L_OPTS="backup_dir:,help,version"
readonly OPTS="d:hVv"
readonly CMD="${0##*/}"
readonly USAGE="${CMD} [OPTION]..."
readonly USAGE_ERR_MSG=$(
cat <<END
Usage: ${USAGE}
Try '${CMD} --help' for more information.
END
)
readonly VERSION_INFO=$(
cat <<END
${CMD} (scripts) 1.0.0
This is free and unencumbered software released into the public domain.
For more information, please refer to <https://unlicense.org/>.
END
)
readonly HELP=$(
cat <<END
SYNOPSIS
${USAGE}
DESCRIPTION
Backup the names of installed packages.
OPTIONS
-d, --backup_dir DIR, --backup_dir=DIR
change the backup directory from ${DEFAULT_BACKUP_DIR} to DIR
-h, --help
display this help and exit
-V, -v, --version
display version and exit
END
)
opts=$(getopt --options=${OPTS} --longoptions=${L_OPTS} --name "${CMD}" -- "$@")
if (($? != 0)); then
echo "${USAGE_ERR_MSG}"
exit 2
fi
eval set -- "${opts}"
backup_dir="${DEFAULT_BACKUP_DIR}"
need_help=false
need_version=false
while true; do
case "$1" in
-d | --backup_dir)
backup_dir="$2"
shift 2
;;
-h | --help)
need_help=true
shift
break
;;
-V | -v | --version)
need_version=true
shift
break
;;
--)
shift
break
;;
esac
done
if [[ $need_help == true ]]; then
echo "${HELP}"
exit 0
fi
if [[ $need_version == true ]]; then
echo "${VERSION_INFO}"
exit 0
fi
if (($# != 0)); then
echo "${CMD}: expected 0 arguments; got $#"
echo "${USAGE_ERR_MSG}"
exit 2
fi
pacman --query --explicit --native --quiet \
>"${backup_dir}/explicit_native.pkg"
pacman --query --explicit --foreign --quiet \
>"${backup_dir}/explicit_foreign.pkg" \
|| true
pacman --query --deps --native --unrequired --unrequired --quiet \
>"${backup_dir}/implicit_optional_native.pkg" \
|| true
pacman --query --deps --foreign --quiet \
>"${backup_dir}/implicit_foreign.pkg" \
|| true