-
Notifications
You must be signed in to change notification settings - Fork 0
/
template
175 lines (146 loc) · 4.5 KB
/
template
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#! /bin/sh
set -e
version_message="\
Install __METAPACKAGE_SHORT_DESCRIPTION__ Metapackage v__YYYY_MM_DD__
Copyright © __PUBLISH_YEAR__ __PUBLISHER_NAME__
__LICENSE__
Based on: [HFL Custom APT Metapackage Installer 1.0.0 by Henrik Franciscus
Leppä](https://github.com/henrik-leppa/hfl-custom-apt-metapackage-installer)
"
help_message="\
Installs my custom metapackage for __PURPOSE__.
Usage: install-__METAPACKAGE_NAME__-metapackage
or: install-__METAPACKAGE_NAME__-metapackage (--help | -H | -h | -?)
or: install-__METAPACKAGE_NAME__-metapackage (--version | -V | -v)
Options:
--help, -H, -h, -?
Print this help message.
--version, -V, -v
Print version and copyright information.
Notes:
- Requires \`apt-get\`, \`add-apt-repository\`, \`equivs-build\`, and \`gdebi\`
commands; the last three will be installed if not found.
- In addition to installing packages, this script also adds PPAs. Unlike
packages, PPAs removed from this script are not \"orphaned\", and therefore
must be purged manually using \`ppa-purge\`.
- If a package fails to install, try to install it with:
\`sudo apt-get install PACKAGE_NAME\`, to find out more on why it failed.
- To view and edit the list of packages and PPAs, open this script with a text
editor.
- When removing packages from the list, run \`sudo apt-get autoremove\`
afterwards to clean out orphaned packages.
"
# [See sysexits.h](https://www.freebsd.org/cgi/man.cgi?query=sysexits&sektion=3)
ex_usage=64
ex_oserr=71
ex_noperm=77
ppas_added=0
random() {
od -N4 -tu /dev/random | awk 'NR==1 {print $2} {}'
}
ensure_ppa() {
ppa="$1"
if ! grep -q "^deb .*$ppa" /etc/apt/sources.list /etc/apt/sources.list.d/*
then
add-apt-repository --yes ppa:"$ppa"
ppas_added=$((ppas_added+1))
fi
}
ensure_up_to_date_package_list() {
if [ "$ppas_added" -ne 0 ]; then
apt-get update
fi
}
if [ $# -ne 0 ]; then
case $1 in
(--version | -V | -v) printf '%s\n' "$version_message" ; exit ;;
(--help | -H | -h | -\?) printf '%s\n' "$help_message" ; exit ;;
(*)
printf '%s\n\n' "Invalid argument: \`$1\`" >& 2
printf '%s\n\n' "Use \`--help\` option to see all valid arguments." >& 2
exit $ex_usage
;;
esac
fi
if [ ! "$(command -v apt-get)" ]; then
message="Command 'apt-get' was not found. Install it and try again."
printf '%s\n' "$message" >& 2
exit $ex_oserr
fi
if [ "$(id -u)" != 0 ]; then
if [ "$(command -v sudo)" ]; then
sudo "$0" "$@"
exit
else
printf '%s\n' "This script requires root permissions."
exit $ex_noperm
fi
fi
if [ ! "$(command -v add-apt-repository)" ]; then
apt-get install software-properties-common ||
apt-get install python-software-properties ||
apt-get install python3-software-properties
fi
if [ ! "$(command -v gdebi)" ]; then
apt-get install gdebi
fi
if [ ! "$(command -v equivs-build)" ]; then
apt-get install equivs
fi
# See note in the help message.
ensure_ppa __SOME_PPA_1__
ensure_ppa __SOME_PPA_2__
ensure_ppa __SOME_PPA_3__
ensure_up_to_date_package_list
while true; do
temporary_directory="${TMPDIR:-/tmp}/$(random)"
if [ ! -e "$temporary_directory" ]; then
break
fi
done
exit=0; hangup=1; interrupt=2; quit=3; termination=15
trap 'rm -f -r "$temporary_directory"' \
"$exit" "$hangup" "$interrupt" "$quit" "$termination"
metapackage_name="__METAPACKAGE_NAME__"
metapackage_directory="$temporary_directory/$metapackage_name"
metapackage_version="$(date -u '+%Y.%m.%d.%H.%M.%S')"
metapackage_dependencies="\
# __SOME_COMMENT__
__SOME_PACKAGE_1__,
__SOME_PACKAGE_2__,
__SOME_PACKAGE_3__,
"
metapackage_short_description="__METAPACKAGE_SHORT_DESCRIPTION__"
metapackage_dependencies_indented=$(
printf '%s\n' "$metapackage_dependencies" | sed 's/^/ /g'
)
metapackage_long_description="\
My custom metapackage for __PURPOSE__
.
Dependecy list:
$metapackage_dependencies_indented
.
(Dependencies of the installation script (not in a metapackage)):
apt,
equivs,
gdebi,
software-properties-common
| python-software-properties
| python3-software-properties,
"
metapackage_ns_control_text="\
Section: misc
Priority: optional
Standards-Version: 3.9.2
Package: $metapackage_name
Version: $metapackage_version
Description: $metapackage_short_description
$metapackage_long_description
Depends:
$metapackage_dependencies
"
mkdir -p "$metapackage_directory"
cd "$metapackage_directory"
printf '%s' "$metapackage_ns_control_text" > ./ns-control
equivs-build ./ns-control
gdebi --non-interactive ./"$metapackage_name"_"$metapackage_version"_all.deb