Commit | Line | Data |
---|---|---|
71e2e780 JB |
1 | #!/bin/bash |
2 | ||
3 | # msgUsage: show a usage message and exit | |
4 | msgUsage() { | |
1615176a | 5 | echo "Usage: $(basename $0) <tmp-dir> <pkg-dir> <release-dir> <release-name>" |
71e2e780 | 6 | echo "Examples:" |
1615176a JB |
7 | echo " \$ $(basename $0) /tmp/rootfs ports/core-cross . minirootfs-XX" |
8 | echo " \$ $(basename $0) /tmp/rootfs /pub/pkg releases crux-arm-rootfs-XX" | |
71e2e780 JB |
9 | exit 0 |
10 | } | |
11 | ||
71e2e780 JB |
12 | # msgError: show a error message and exit |
13 | msgError() { | |
14 | echo "Error, $@" 2>&1 | |
15 | exit 1 | |
16 | } | |
17 | ||
18 | # checkCommands: checks for command dependencies | |
19 | checkCommands() { | |
20 | for cmd in sudo pkgmk tar md5sum; do | |
21 | if ! which $cmd 2>&1 >/dev/null; then | |
22 | msgError "'$cmd' is not in your \$PATH and you need it to execute this script" | |
23 | fi | |
24 | done | |
25 | } | |
26 | ||
27 | # checkVars: checks for user given arguments | |
28 | # | |
29 | # params: | |
1615176a JB |
30 | # $1 - TMPDIR |
31 | # $2 - PKGDIR | |
71e2e780 JB |
32 | # $3 - RELEASE_DIR |
33 | # $4 - RELEASE_NAME | |
34 | checkVars() { | |
35 | [ $# -lt 1 ] && msgUsage | |
1615176a JB |
36 | [ ! -z "$1" ] && TMPDIR="$1" |
37 | [ "$TMPDIR" = "/tmp" ] && msgError "you can't use /tmp as TMPDIR" | |
38 | [ ! -z "$2" ] && PKGDIR="$2" | |
71e2e780 JB |
39 | [ ! -z "$3" ] && RELEASE_DIR="$3" |
40 | [ ! -z "$4" ] && RELEASE_NAME="$4" | |
41 | # check for directories, if not create them | |
1615176a | 42 | for dir in $TMPDIR $RELEASE_DIR; do |
71e2e780 | 43 | if [ ! -d "$dir" ]; then |
1615176a | 44 | install -d $dir || msgError "can't create directory $dir" |
71e2e780 JB |
45 | fi |
46 | done | |
1615176a JB |
47 | TMPDIR="$(cd $TMPDIR; pwd)" |
48 | PKGDIR="$(cd $PKGDIR; pwd)" | |
71e2e780 | 49 | RELEASE_DIR="$(cd $RELEASE_DIR; pwd)" |
1615176a | 50 | [ -z "$PACKAGES" ] && PACKAGES="$(find $PKGDIR -type f -name '*#*pkg.tar.*')" |
71e2e780 JB |
51 | } |
52 | ||
53 | # global variables | |
54 | PWD_DIR="$(pwd)" | |
1615176a JB |
55 | TMPDIR="$PWD_DIR/tmp" |
56 | PKGDIR="$PWD_DIR/pkg" | |
71e2e780 JB |
57 | |
58 | checkCommands | |
59 | checkVars $@ | |
60 | ||
61 | # create the database stuff for pkgutils | |
1615176a JB |
62 | sudo install -d -m 0755 $TMPDIR/var/lib/pkg |
63 | sudo touch $TMPDIR/var/lib/pkg/db | |
64 | sudo chmod 0444 $TMPDIR/var/lib/pkg/db | |
71e2e780 JB |
65 | |
66 | # install all packages | |
67 | pkgnum=0 | |
1615176a | 68 | echo "Please wait for results..." |
71e2e780 | 69 | for pkg in $PACKAGES; do |
1615176a | 70 | sudo pkgadd -r $TMPDIR $pkg || msgError "failed to install $pkg" |
71e2e780 JB |
71 | let pkgnum=$pkgnum+1 |
72 | done | |
73 | ||
74 | # create the tarball and the md5sum | |
1615176a JB |
75 | cd $TMPDIR && sudo tar cJf $RELEASE_DIR/$RELEASE_NAME.tar.xz * && cd - |
76 | cd $RELEASE_DIR && md5sum $RELEASE_NAME.tar.xz > $RELEASE_NAME.tar.xz.md5 && cd - | |
77 | ||
78 | echo "- Installed $pkgnum packages" | |
79 | echo "- Finished $RELEASE_DIR/$RELEASE_NAME.tar.xz" | |
71e2e780 | 80 | |
1615176a | 81 | sudo rm -rf $TMPDIR |
71e2e780 JB |
82 | |
83 | # End of file |