summaryrefslogtreecommitdiffstats
path: root/makemod
blob: 27ba575ab5a6ac6cfedcc2ea3be00f36a604bc14 (about) (plain) (blame)
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
#!/bin/sh
# Create squashfs module from a directory or a Slackware package.
# Module can then be added to liveslak/addons directory.

# By default, overwrite destination module file without asking if it pre-exists.
INTERACTIVE=NO

function help() {
  cat <<EOH

-- Usage:
   $(basename $0) [-i] <packagename|directory> modulename.sxz
-- Option parameters:
   h :    This help.
   i :    Interactive mode will not overwrite destination file by default.
-- Description:
   The first parameter is either the full path to a Slackware package,
   or else a directory.
   If a packagename is supplied as first parameter, it will be installed
   into a temporary directory using Slackware's "installpkg".
   The content of the temporary directory will be squashed into a module
   by the "squashfs" program.
   If a directoryname is supplied, its content will be squashed into
   a module by the "squashfs" program.
   The second parameter is the full pathname of the output module
   which will be created.

EOH
}

# Option parsing:
while getopts "hi" Option
do
  case $Option in
    h ) help; exit
        ;;
    i ) INTERACTIVE="YES"
        ;;
    * ) help; exit
        ;;   # DEFAULT
  esac
done
shift $(($OPTIND - 1))
# End of option parsing.
#  $1 now references the first non option item supplied on the command line
# ---------------------------------------------------------------------------

# Input check:
if [ "x$1" = "x" ]; then
   help
   exit 1
elif [ "x$2" = "x" ]; then
   help
   exit 1
elif [ -f "$2" -a "$INTERACTIVE" = "YES" ]; then
  read -p "-- Destination file '$2' already exists. Overwrite Y/N (y): " ANSWER
  if [ "x$ANSWER" = "xN" -o "x$ANSWER" = "xn" ]; then
    echo "-- Aborting now."
    exit
  fi
fi

# .sxz extension uses xz compression:
COMPR="xz"

if [ -d "$1" ]; then
  echo "Creating .sxz from directory."
  PKGDIR="$1"
else
  MODEXT=$(echo "$2" |rev |cut -d'.' -f1 |rev)
  case $MODEXT in
    sxz) COMPR="xz" ;;
    sgz) COMPR="gzip" ;;
    xzm) COMPR="xz" ;;
      *) echo "-- Unsupported module extension '$MODEXT'" ; exit 1 ;;
  esac 
  echo "Creating .${MODEXT} from package."
  TMPDIR=$(mktemp -t -d makesxz.XXXXXX)
  PKGDIR="$TMPDIR"
  if [ ! -d $PKGDIR ]; then
    echo "-- Failed to create temporary directory for extraction!"
    exit 1
  fi
  # Extract the package:
  /sbin/installpkg -root $PKGDIR "$1"
  if [ $? -ne 0 ]; then
    echo "-- Error installing package!"
    exit 1
  fi
fi

mksquashfs "${PKGDIR}" "$2" -noappend -comp ${COMPR} -b 256K $3 $4 $5 $6 $7 $8 $9
if [ $? -ne 0 ]; then
  echo "-- Error creating squashfs compressed module"
  exit 1
fi

# If we extracted a package, clean up now:
[ ! -z "$TMPDIR" ] && rm -rf $TMPDIR