File: jadmaker

package info (click to toggle)
gammu 1.42.0-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,340 kB
  • sloc: ansic: 107,388; pascal: 7,209; cpp: 3,976; php: 1,622; python: 1,559; sh: 1,208; sql: 601; perl: 240; makefile: 162; asm: 31; cs: 4
file content (85 lines) | stat: -rwxr-xr-x 1,534 bytes parent folder | download | duplicates (7)
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
#!/bin/bash
# JAD file generator
# Copyright © 2008 - 2009 Michal Čihař <michal@cihar.com>
# vim: expandtab sw=4 ts=4 sts=4:

# Defaults
DEFURL=http://www.gammu.org/

# Parameters
FORCE=0
URL="$DEFURL"

usage() {
    echo "Usage: jadmaker [-f] <filename.jar>..."
}


help() {
    usage
    echo
    echo "-h / --help	    Show this help"
    echo "-f / --force	    Force rewriting JAD file"
    echo "-u / --url URL    URL to include in JAR (default=$DEFULR)"
    echo
}

makejad() {
    if [ ! -f "$1" ] ; then
	echo "File $1 does not exist!"
	exit 1
    fi
    JAD="${1%.*}.jad"
    if [ "$FORCE" -eq 0 -a -f "$JAD" ] ; then
	read -p "File $JAD already exists, overwrite? (y/N)" res
	case "$res" in
	    y|Y|yes|YES)
		rm -f "$JAD"
		;;
	    *)
		echo "Not overwriting $JAD"
		exit
		;;
	esac
    fi

    # Extract manifest as text file (convert end of lines) and delete empty lines
    unzip -aa -p "$1" "META-INF/MANIFEST.MF" \
	| sed '/^[[:space:]]*$/d' \
	> "$JAD"

    # Some needed variables
    echo "MIDlet-Jar-Size: $(stat -c%s "$1")" >> "$JAD"
    echo "MIDlet-Jar-URL: $(basename "$1")" >> "$JAD"
    echo "MIDlet-Info-URL: $URL" >> "$JAD"

    echo "File $JAD created"
}


while [ "$#" -gt 0 ] ; do
    case "$1" in 
	-?|-h|--help)
	    help
	    exit
	    ;;
	-f|--force)
	    FORCE=1
	    ;;
	-u|--url)
	    if [ $# -lt 2 ] ; then
		echo "Missing parameter for URL!"
		exit 1
	    fi
	    shift
	    URL="$1"
	    ;;
	*)
	    makejad "$1"
	    if [ $? -ne 0 ] ; then
		exit 1
	    fi
	    ;;
    esac
    shift
done