/
uli-gen
executable file
·134 lines (118 loc) · 3.1 KB
/
uli-gen
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/sh
help () {
echo " Help for uli-gen"
echo " "
echo " uli-gen helps generate universal linux installers"
echo " uli-gen can be used in following modes"
echo " -i : Initialise a uli package, with a uli.cfg file"
echo " -c : Create a .uli package"
echo " -h : Show this help text"
echo " "
echo " "
echo " Usage: uli-gen -i [dir]"
echo " "
echo " dir = Directory to create. (Optional, creates in current directory if not provided"
echo " "
echo " "
echo " Usage: uli-gen -c dir [uli]"
echo " "
echo " dir = directory which completely contains all files required to distribute"
echo " uli = output .uli file. (Optional, saved to dir/appname.uli) otherwise"
echo " "
echo " NOTE: The dir must conatin a uli.cfg file"
exit 1
}
install_template_start() {
#!/bin/bash
if [ "$USER" != "root" ]; then
echo ""
echo " Must perform installation as root"
echo " Aborting"
exit 1
fi
export TMPDIR=`mktemp -d /tmp/uli.XXXXXX`
echo " Temporarily extracting to ${TMPDIR}"
ARCHIVE=`awk '/^__ARCHIVE_STARTS__/ {print NR + 1; exit 0; }' $0`
tail -n+$ARCHIVE $0 | tar xv -C $TMPDIR
source $TMPDIR/uli.cfg
if [ -n "$preinstall" ]; then
echo " Running preinstall scripts"
cd $TMPDIR
( exec "./${preinstall}" )
fi
export INSTALLDIR="${install_dir}/${applabel}"
echo " Installing into $INSTALLDIR"
cp -rf $TMPDIR $INSTALLDIR
if [ -n "$postinstall" ]; then
echo " Running postinstall scripts"
cd $INSTALLDIR
( exec "./${postinstall}" )
fi
echo " Creating symlink in /usr/bin"
ln -s "${INSTALLDIR}/${main_exec}" /usr/bin/${main_exec_cmd}
read -p " Would you like an application shortcut created ? (Y/n) " app_shortcut
if [ "$app_shortcut" != 'n' ] && [ "$app_shortcut" != 'N' ]; then
echo " Creating app shortcut"
touch /usr/share/applications/${applabel}.desktop
fi
exit 0
#install_template_end
}
ulicfg_template_start() {
appname="Example ULI App"
version=0.1.0
applabel="example-uli-app"
executables="example-uli-app.bin"
apt_deps="bash dash tar"
pacman_deps="bash dash tar"
yum_deps="bash dash tar"
# Modern Linux distros prefer /usr/share over /opt, but it's upto you
#install_dir="/opt"
install_dir="/usr/share"
#ulicfg_template_end
}
uli_init () {
DIR=$1
echo " Distribution directory is : ${1}"
if [ -e ${1}/uli.cfg ]; then
echo " ULI already configured in this directory"
exit 1
fi
touch ${1}/uli.cfg
sed -e '1,/ulicfg_template_start/d' -e '/ulicfg_template_end/,$d' $0 >> ${1}/uli.cfg
exit 0
}
uli_create () {
DIR=$1
ULI=$2
echo " Distribution directory is : ${1}"
echo " ULI file will be at ${2}"
rm -rf ${2}
touch ${2}
sed -e '1,/install_template_start/d' -e '/install_template_end/,$d' $0 >> ${2}
echo "__ARCHIVE_STARTS__" >> ${2}
tar -c -C ${1} . >> ${2}
chmod a+x ${2}
exit 0
}
while getopts “hi:c:” OPTION
do
case $OPTION in
h)
help
;;
i)
shift $(( OPTIND - 2 ))
uli_init $@
;;
c)
shift $(( OPTIND - 2 ))
uli_create $@
;;
?)
echo " Wrong argument passed !"
help
;;
esac
done
exit 0;