-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathppmpss.sh
189 lines (166 loc) · 3.12 KB
/
ppmpss.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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/sh
# vim: ts=8 sw=8 noet cc=80
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Portable package manager made in POSIX shell script
# Copyright (C) 2023 astral
#
# This file is part of ppmpss.
#
# ppmpss is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# ppmpss is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# ppmpss. If not, see <https://www.gnu.org/licenses/>.
# Store name of program as script will shift and $0 can't be relied on
PROG=$(basename "$0")
# Exit codes
{
EXIT_USAGE=1
}
# Colors
#
# Non-used colors is okay
# shellcheck disable=SC2034
{
BLACK=30
RED=31
GREEN=32
YELLOW=33
BLUE=34
PURPLE=35
CYAN=36
WHITE=37
}
# Print a message from ppmpss
#
# usage:
# msgf <COLOR> [fmt]
#
# example:
# msgf $BLUE "Hello, world\n"
# msgf >&2 $RED "Error\n"
#
# Expansion of variables inside printf is desired
# shellcheck disable=SC2059
msgf() {
printf "\033[1m=>\033[%smppmpss\033[0m: " "$1"
shift
printf "$@"
}
# Function to run when INT signal is received
#
# interrupt is never called except for SIGINT trap
# shellcheck disable=SC2317,SC2086
interrupt() {
echo
msgf >&2 $RED "SIGINT received...\n"
kill -9 $$
}
trap 'interrupt' INT
# Check if no command is specified
if [ $# -eq 0 ]
then
msgf >&2 $RED "usage: %s <command> ...\n" "$PROG"
exit $EXIT_USAGE
fi
# Process different commands
case $1 in
pkg)
shift
output=
template=
while getopts o:c: name
do
case $name in
o)
output=$OPTARG
;;
c)
template=$OPTARG
;;
?)
msgf >&2 $RED "usage: %s [-o <OUTPUT>] [-c <TEMPLATE>] [pkg]...\n" "$PROG"
exit $EXIT_USAGE
;;
esac
done
shift $((OPTIND-1))
if [ "$output" ]
then
msgf $BLUE "specified output: %s\n" "$output"
fi
if [ "$template" ]
then
msgf $BLUE "specified template: %s\n" "$template"
fi
msgf $PURPLE "specified packages: %s\n" "$*"
;;
em)
shift
sflag=
uflag=
repo=
while getopts suR: name
do
case $name in
s)
sflag=1
;;
u)
uflag=1
;;
R)
repo=$OPTARG
;;
?)
msgf >&2 $RED "usage: %s [-s] [-u] [-R <repo>] [pkg]...\n" "$PROG"
exit $EXIT_USAGE
;;
esac
done
shift $((OPTIND-1))
if [ "$sflag" ]
then
msgf $BLUE "sync flag specified\n"
fi
if [ "$uflag" ]
then
if [ $# -eq 0 ]
then
msgf $BLUE "system update specified\n"
fi
msgf $BLUE "update flag specified\n"
fi
if [ "$repo" ]
then
msgf $BLUE "specified repo: %s\n" "$repo"
fi
msgf $PURPLE "specified packages: %s\n" "$*"
;;
rm)
shift
msgf $PURPLE "specified packages: %s\n" "$*"
;;
chroot)
shift
if [ $# -ne 1 ]
then
msgf >&2 $RED "usage: %s chroot <dir>\n" "$PROG"
exit $EXIT_USAGE
fi
msgf $PURPLE "specified chroot: %s\n" "$1"
;;
*)
msgf >&2 $RED "unknown command: %s\n" "$1"
exit $EXIT_USAGE
;;
esac
exit 0