commit d1d249f
hovercats
·
2025-06-05 09:47:24 +0000 UTC
parent 83d251f
create new functions for error messages and regular messages. this also subsequently gets rid of usage of echo, which is what I wanted
1 files changed,
+23,
-16
M
rcpm
M
rcpm
+23,
-16
1@@ -6,13 +6,21 @@ flag e +
2 if (test ! -f /etc/rcpm.conf) . ./rcpm.conf
3 if not . /etc/rcpm.conf
4
5-if (~ $#RCPM_PATH 0) {
6- printf 'RCPM_PATH is not set\n'
7+fn log {
8+ printf '%s\n' $"*
9+}
10+
11+fn die {
12+ log ERROR: $"*
13 exit 1
14 }
15
16+if (~ $#RCPM_PATH 0) {
17+ die 'RCPM_PATH is not set'
18+}
19+
20 fn rcpm_help {
21- printf 'Usage: rcpm b|c|d||h|i|l|m|s\n'
22+ log 'Usage: rcpm b|c|d||h|i|l|m|s'
23 }
24
25 fn dl_pkg {
26@@ -20,16 +28,15 @@ fn dl_pkg {
27 if (test -f url) {
28 if (test -f sha256) {
29 if (test ! -f `{awk '{print $2}' sha256}) curl -LK url -O
30- if not printf 'File already downloaded.\n'
31+ if not log 'File already downloaded'
32 }
33 if not {
34- printf 'sha256 file not found, downloading anyway...\n'
35+ log 'sha256 file not found, downloading anyway...'
36 curl -LK url -O
37 }
38 }
39 if not {
40- printf 'url file not found!\n'
41- exit 1
42+ die 'Url file not found!'
43 }
44 }
45
46@@ -38,8 +45,7 @@ fn chksum_pkg {
47 dl_pkg
48 if (test -f sha256) sha256sum -c sha256
49 if not {
50- printf 'sha256 file not found, cannot verify sha256sum!\n'
51- exit 1
52+ die 'sha256 file not found, cannot verify sha256sum!'
53 }
54 }
55
56@@ -68,7 +74,7 @@ fn get_ver {
57 fn packup_pkg {
58 mkdir -p ./$RCPM_DB/$pkg
59 get_ver
60- printf '%s' $"version >./$RCPM_DB/$pkg/ver
61+ printf $"version >./$RCPM_DB/$pkg/ver
62 gen_manifest
63 test -d $RCPM_CACHE || mkdir -p $RCPM_CACHE
64 pax -w . | gzip > $RCPM_CACHE/$pkg@$ver-$rev.tar.gz
65@@ -76,7 +82,7 @@ fn packup_pkg {
66
67 fn check_prebuilt {
68 if (test ! -f $RCPM_CACHE/$pkg@$ver-$rev.tar.gz) {
69- echo $pkg is not built
70+ log $pkg is not built
71 }
72 }
73
74@@ -91,7 +97,7 @@ fn install_pkg {
75 cd $RCPM_ROOT
76 get_ver
77 check_prebuilt || gzip -dc $RCPM_CACHE/$pkg@$ver-$rev.tar.gz | pax -r
78- echo $pkg installed successfully
79+ log $pkg installed successfully
80 }
81
82 fn build_pkg {
83@@ -125,7 +131,7 @@ fn get_local_ver {
84
85 fn list_pkg {
86 get_local_ver
87- echo $pkg $_ver-$_rev
88+ log $pkg $_ver-$_rev
89 }
90
91 fn rm_pkg {
92@@ -139,7 +145,7 @@ fn update_pkg {
93 for (file in $RCPM_ROOT/$RCPM_DB/*) {
94 pkg=`{basename $file}
95 if (cmp -s $RCPM_ROOT/$RCPM_DB/$pkg/ver $RCPM_PATH/$pkg/ver) {
96- echo $pkg is up to date
97+ log $pkg is up to date
98 }
99 if not {
100 get_ver
101@@ -171,7 +177,7 @@ switch($1) {
102 for (file in $RCPM_ROOT/$RCPM_DB/*) {
103 pkg=`{basename $file}
104 get_local_ver
105- echo $pkg $_ver-$_rev
106+ log $pkg $_ver-$_rev
107 }
108 case *
109 for (pkg) list_pkg $pkg
110@@ -187,6 +193,7 @@ switch($1) {
111 case u
112 update_pkg
113 case *
114- printf 'Error!\n'
115+ log 'Error: Invalid arguement!'
116+ rcpm_help
117 exit 1
118 }