forked from appleboy/Shell-Script
-
Notifications
You must be signed in to change notification settings - Fork 4
/
create_pkg.sh
executable file
·87 lines (65 loc) · 1.91 KB
/
create_pkg.sh
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
#!/usr/local/bin/bash
###############################################
#
# Date: 2011.03.14
# Author: appleboy ( appleboy.tw AT gmail.com)
# Web: http://blog.wu-boy.com
# Ref: http://www.freebsd.org/doc/en/books/porters-handbook/plist-autoplist.html
#
###############################################
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
export PATH
function displayErr()
{
echo $1;
exit 1;
}
function usage()
{
echo 'Usage: '$0' Source_Dir Target_Dir'
exit 1;
}
if [ "$#" -lt "2" ]; then
usage $0
fi
#
# configure system parameters
#
HOME=$1
TARGET=$2
TMPDIR="/var/tmp"
#
# configure end
#
[ ! -d "$HOME" ] && displayErr "${HOME} is not directory"
if [ ! -d "$TARGET" ]; then
echo "$TARGET directory will be created"
mkdir -p $TARGET
fi
#
# clean ports file
cd $HOME && make clean
#
# get port name
PORTNAME=$(make -V PORTNAME)
#
# Before create port directory, please delete it.
# Next, create a temporary directory tree into which your port can be installed, and install any dependencies.
rm -rf ${TMPDIR}/${PORTNAME}
if [ ! -d "${TMPDIR}/${PORTNAME}" ]; then
echo "${TMPDIR}/${PORTNAME} will be created"
mkdir -p ${TMPDIR}/${PORTNAME}
fi
mtree -U -f $(make -V MTREE_FILE) -d -e -p ${TMPDIR}/${PORTNAME}
make depends PREFIX=${TMPDIR}/$PORTNAME
#
# Store the directory structure in a new file.
cd ${TMPDIR}/${PORTNAME} && find -d * -type d | sort > ${TARGET}/OLD-DIRS
#
# If your port honors PREFIX (which it should) you can then install the port and create the package list.
cd $HOME && make install PREFIX=${TMPDIR}/${PORTNAME}
cd ${TMPDIR}/${PORTNAME} && find -d * \! -type d | sort > ${TARGET}/pkg-plist
#
# You must also add any newly created directories to the packing list.
cd ${TMPDIR}/${PORTNAME} && find -d * -type d | sort | comm -13 ${TARGET}/OLD-DIRS - | sort -r | sed -e 's#^#@dirrm #' >> ${TARGET}/pkg-plist
echo "Please check ${TARGET}/pkg-plist file"