Add pkg/*

This commit is contained in:
Taru Karttunen 2011-05-05 16:07:24 +03:00
parent a895a7593c
commit 843b25665f
6 changed files with 174 additions and 0 deletions

21
sys/src/cmd/pkg/create Executable file
View file

@ -0,0 +1,21 @@
#!/bin/rc -e
i=`{basename $1}
d=$1
echo Creating $i
C=`{pwd}
@{
rfork en
cd $d
mkdir /tmp/$i
mk
divergefs -p /tmp/$i /
mk install clean
unmount /
}
cd /tmp/$i/files
rm -r env
tar cv * | bzip2 -9 > $C/$i.tbz
cd /tmp
rm -r $i
echo Created $C/$i.tbz

12
sys/src/cmd/pkg/install Executable file
View file

@ -0,0 +1,12 @@
#!/bin/rc -e
cd /
mkdir -p /sys/lib/pkg
if (test -s /sys/lib/pkg/$1) {
echo $i already installed
exit
}
echo Installing $1
hget http://pkg.violetti.org/$cputype/$1.tbz | bunzip2 | pkg/unpkg>[2]/sys/lib/pkg/$1
echo Done

3
sys/src/cmd/pkg/list Executable file
View file

@ -0,0 +1,3 @@
#!/bin/rc
hget http://pkg.violetti.org/$cputype | htmlfmt | grep '\.tbz' | sed -e 's/\.tbz$//'

20
sys/src/cmd/pkg/mkfile Normal file
View file

@ -0,0 +1,20 @@
</$objtype/mkfile
all: $O.unpkg
echo
$O.unpkg: unpkg.c
$CC unpkg.c
$LD -o $O.unpkg unpkg.$O
install:V: $O.unpkg
mkdir -p /$objtype/bin/pkg
cp $O.unpkg /$objtype/bin/pkg/unpkg
cp create install list remove /$objtype/bin/pkg
clean:
rm -f $O.unpkg *.$O
nuke: clean
rm -f /$objtype/bin/pkg/*

18
sys/src/cmd/pkg/remove Executable file
View file

@ -0,0 +1,18 @@
#!/bin/rc -e
cd /
if(test -s /sys/lib/pkg/$1) {
fs=(`{cat /sys/lib/pkg/$1 | awk '{print $1}'})
ss=(`{cat /sys/lib/pkg/$1 | awk '{print $2}'})
for(i in `{seq $#fs}) {
s=`{sha1sum $fs($i) | awk '{print $1}' | tr a-z A-Z}
if(test $s '=' $ss($i)) {
echo D $fs($i)
rm $fs($i)
}
if not {
echo M $fs($i) NOT DELETING
}
}
rm /sys/lib/pkg/$1
}

100
sys/src/cmd/pkg/unpkg.c Normal file
View file

@ -0,0 +1,100 @@
#include <u.h>
#include <libc.h>
#include <mp.h>
#include <libsec.h>
struct th {
char *name;
ulong perm;
ulong size;
char type;
char *user, *group;
};
static char *sndup(char* s, ulong n) {
char *d, *p;
p = memchr(s, 0, n);
if(p)
n = p-s;
d = malloc(n+1);
memcpy(d,s,n);
d[n] = 0;
return d;
}
int readheader(int fd, struct th* th) {
int i;
char b[512];
if(readn(fd, b, 512) != 512) return -1;
// Check for end of archive
for(i=0; i<512; i++) {
if(b[i]!=0) goto rhok;
}
if(readn(fd, b, 512) != 512) return -1;
for(i=0; i<512; i++) {
if(b[i]!=0) return -1;
}
return 0;
rhok:
th->name = sndup(b, 100);
th->perm = strtoul(b+100, nil, 8);
th->size = strtoul(b+124, nil, 8);
th->type = b[156];
th->user = sndup(b+265, 32);
th->group= sndup(b+297, 32);
return 1;
}
int main(void) {
while(1) {
struct th th;
ulong off;
uchar b[512];
DigestState *s;
int wfd;
int r = readheader(0, &th);
if(r <= 0) return r;
switch(th.type) {
case '5':
create(th.name, OREAD, DMDIR|th.perm);
break;
case '0': case 0:
print("A %s\n", th.name);
r = access(th.name, 0);
if(r == 0) {
print("File already exists: %s\n", th.name);
return -1;
}
if((wfd = create(th.name, OWRITE, th.perm)) < 0) {
print("Create failed: %s\n", th.name);
return -1;
}
s = nil;
for(off=0; off<th.size; off+=512) {
int n = th.size-off;
n = n<512 ? n : 512;
if(readn(0, b, 512) != 512) return -1;
if(write(wfd, b, n) != n) return -1;
s = sha1(b, n, nil, s);
}
uchar digest[20], hdigest[41];
sha1(nil, 0, digest, s);
enc16((char*)hdigest, 41, digest, 20);
fprint(2, "%s\t%s\n", th.name, hdigest);
close(wfd);
break;
default:
print("Unknown file type '%c'\n", th.type);
return -1;
}
free(th.name);
free(th.user);
free(th.group);
}
}