4 #---------------------------------------------------------------------
5 ## Replaces sorcerys default_build with a custom version using
6 ## the invoke_gcc function from libgcc
7 #---------------------------------------------------------------------
8 function default_build () {
13 #---------------------------------------------------------------------
14 ## @return 0 if glibc was compiled with NPTL
15 ## @return 1 otherwise
17 ## Detects if the current glibc includes NPTL support.
19 #---------------------------------------------------------------------
20 function glibc_is_nptl ()
22 if getconf GNU_LIBPTHREAD_VERSION | grep -q NPTL; then
28 #---------------------------------------------------------------------
29 # Runs update-desktop-database if it is installed
30 #---------------------------------------------------------------------
31 function update_desktop_database ()
33 if test -x /usr/bin/update-desktop-database; then
34 message "${MESSAGE_COLOR}Updating application mime type database.${DEFAULT_COLOR}"
35 /usr/bin/update-desktop-database
39 #---------------------------------------------------------------------
40 ## this function installs the *.desktop, start* files and qingy links
41 ## this function is intended to be used by spells for windowmanagers
42 #---------------------------------------------------------------------
43 function install_wmfiles ()
45 local wm_desktopfile_dir="${INSTALL_ROOT}/usr/share/xsessions"
46 local wm_startwm_dir="${INSTALL_ROOT}/usr/bin"
48 # install the start* file for the windowmanager if it's not
50 if [ -f ${SCRIPT_DIRECTORY}/start${SPELL} ] ; then
51 if ! [ -e ${wm_startwm}/start${SPELL} ] ; then
52 install -m 755 ${SCRIPT_DIRECTORY}/start${SPELL} \
57 # making sure the destination directory exists
58 if ! [ -d ${wm_desktopfile_dir} ] ; then
59 mkdir ${wm_desktopfile_dir}
62 # install the windowmanagers desktop file
63 if [ -f ${SCRIPT_DIRECTORY}/${SPELL}.desktop ] ; then
64 if ! [ -e ${wm_desktopfile_dir}/${SPELL}.desktop ]; then
65 install -m 755 ${SCRIPT_DIRECTORY}/${SPELL}.desktop \
70 if ( spell_ok qingy ); then
71 if [ -x ${wm_startwm_dir}/start${SPELL} ] ; then
72 if [ ! -d ${INSTALL_ROOT}/etc/qingy/xsessions ]; then
73 install -d -m 755 ${INSTALL_ROOT}/etc/qingy/xsessions
75 ln -s ${wm_startwm_dir}/start${SPELL} \
76 ${INSTALL_ROOT}/etc/qingy/xsessions/${SPELL}
81 #---------------------------------------------------------------------
82 ## Sets the current script to run only one make job
83 #---------------------------------------------------------------------
85 function make_single ()
91 #---------------------------------------------------------------------
92 ## Re-enables the normal Sorcery make (cancels single_make)
93 #---------------------------------------------------------------------
95 function make_normal ()
97 source $COMPILE_CONFIG
100 #---------------------------------------------------------------------
102 ## @param full path to shell
104 ## Adds a shell to /etc/shells and optionally to qingy's sessions
105 #---------------------------------------------------------------------
106 function install_shell ()
108 local qingy_session_dir="${INSTALL_ROOT}/etc/qingy/sessions"
110 if [ -z "$1" ] ; then
111 message "${PROBLEM_COLOR}no shell name specified, aborting${DEFAULT_COLOR}"
114 if [ ! -e "$2" ] ; then
115 message "${PROBLEM_COLOR} $2 isn't executable, no use adding it as a shell${DEFAULT_COLOR}"
119 #installing shell into /etc/shells
120 message "installing $1 into /etc/shells"
121 if ! ( grep -q "^${2}$" ${INSTALL_ROOT}/etc/shells ) ; then
122 echo "$2" >> ${INSTALL_ROOT}/etc/shells
125 #installing shell into qingy's session dir if it's installed
126 if ( spell_ok qingy ) && ! [ -f ${qingy_session_dir}/$1 ] ; then
127 message "installing $1 into $qingy_session_dir"
128 echo "$2" > ${qingy_session_dir}/$1 &&
129 chmod 0755 ${qingy_session_dir}/$1
133 #---------------------------------------------------------------------
135 ## @param full path to shell
137 ## Removes a shell from /etc/shells and optionally from qingy's sessions
138 #---------------------------------------------------------------------
139 function remove_shell ()
141 local qingy_session_dir="${INSTALL_ROOT}/etc/qingy/sessions"
143 if [ -z "$1" ] ; then
144 message "${PROBLEM_COLOR}no shell name specified, aborting${DEFAULT_COLOR}"
147 if [ -z "$2" ] ; then
148 message "${PROBLEM_COLOR}no shell path specified, aborting${DEFAULT_COLOR}"
152 #removing shell from /etc/shells
153 if [ -f /etc/shells ] ; then
154 sedit "\:^$2$:d" /etc/shells
157 # and optionally from qingy's session dir
158 if [ -f ${qingy_session_dir}/$1 ] ; then
159 message "removing $1 from $qingy_session_dir"
160 rm -f ${qingy_session_dir}/$1
165 #---------------------------------------------------------------------
166 ## replacement for config_query_string to work around a short timeout
167 ## when entering long strings (hostnames, organisation names)
168 #---------------------------------------------------------------------
169 function config_query_long_string() {
172 if config_get_option "$1" ANSWER; then
173 # option allready answered in config
174 echo -e "[[ ${QUERY_COLOR}$2${DEFAULT} -> '${QUERY_COLOR}$ANSWER${DEFAULT}' ]]"
176 query_string ANSWER "$2" "$3"
177 read -t $DELAY -n 1 ANSWER_first
178 if [[ $ANSWER_first ]] ; then
181 ANSWER="${ANSWER_first}${ANSWER_rest}"
182 config_set_option "$1" "$ANSWER"
187 #---------------------------------------------------------------------
188 ## @param Directory with files we might want to install
189 ## @param Destination directory (optional)
191 ## Installs files to WWW_DEST ($INSTALL_ROOT/usr/share/www/$SPELL) and
192 ## sets up proper www-data permissions
193 ## Optionally the second parameter will override WWW_DATA (and make
194 ## sure INSTALL_ROOT exists only once in the WWW_DATA)
195 #---------------------------------------------------------------------
196 function install_www_files ()
200 # Just in case the destination already includes INSTALL_ROOT, remove it
202 local WWW_DEST="$INSTALL_ROOT/${2/\$INSTALL_ROOT/}"
204 local WWW_DEST="$INSTALL_ROOT/usr/share/www/$SPELL"
208 # Make sure WWW_DEST exists
210 if [ ! -d "$WWW_DEST" ]; then
211 if [ ! -d "${WWW_DEST/\/$SPELL/}" ]; then
212 mkdir -p "${WWW_DEST/\/$SPELL/}" &&
213 chmod 0755 "${WWW_DEST/\/$SPELL/}" &&
214 chown www-data:www-data "${WWW_DEST/\/$SPELL/}"
217 mkdir -p "$WWW_DEST" &&
218 chmod 0755 "$WWW_DEST" &&
219 chown www-data:www-data "$WWW_DEST"
222 # find $@ | while read file; do install ... $file ...; done
223 # find $1 -type -f | while read file; do
224 for www_file in `find $1 -type f`; do
225 if install_config_file "$www_file" "$WWW_DEST/$www_file"; then
226 chmod 0644 "$WWW_DEST/$www_file" &&
227 chown www-data:www-data "$WWW_DEST/$www_file"
231 # Warning message about new location for www files
232 # Remove around 2005-08-02 (one month in test, another in stable, supposedly)
234 message "${MESSAGE_COLOR}Your web files have been moved out of the" \
235 "APACHE specific locations (apache2/htdocs, httpd/htdocs, etc.)" \
236 "and into a shared, non-DocumentRoot $INSTALL_ROOT/usr/share/www" \
237 "directory. You can modify your web server to point there for" \
238 "these files now.${DEFAULT_COLOR}"
241 #---------------------------------------------------------------------
242 ## Removes traces of NSPR and NSS from Mozilla-based software
243 ## TODO move patch to a central place
244 #---------------------------------------------------------------------
245 function mozilla_remove_nspr_nss() {
246 message 'Checking Mozilla source code...' &&
247 [[ "$(basename $(pwd))" == mozilla ]] &&
248 message 'Checking the spell...' &&
249 [[ -f $SCRIPT_DIRECTORY/security_manager_makefile.diff ]] &&
250 patch -p1 < $SCRIPT_DIRECTORY/security_manager_makefile.diff &&
251 rm -fr dbm nsprpub security/nss &&
252 # exclude DBM for top-level modules and don't build it
253 sedit 's@\<dbm\>@@g' Makefile.in &&
254 sedit 's@\<dbm\>@@g' build/unix/modules.mk &&
255 # don't define NSS libraries as dependencies and don't look for them in the tree
256 sedit 's@$(DIST)/lib/$(LIB_PREFIX)\(crmf\|dbm\|nss3\|softokn3\|smime3\|ssl3\)\.$(LIB_SUFFIX)@-l\1@g' config/config.mk &&
257 sedit 's@NSS_DEP_LIBS\s*=@__undefine_\0@g' config/config.mk &&
258 # align the makefile-s
259 find -name Makefile.in | while read __MAKEFILE; do
260 # use system NSPR's and NSS's headers
261 # option `--with-system-nspr' doesn't do it everywhere
262 sedit 's@-I\S*\(nss\|nspr\)\>@-I/usr/include/\1@g' $__MAKEFILE
266 #-------------------------------------------------------------------------
267 ## Returns the kernel version checks linux then linux-new (for now) and
268 ## then uname for the kernel version
269 #-------------------------------------------------------------------------
270 function get_kernel_version()
272 local KVER=$(installed_version linux)
273 if [[ $KVER ]] ; then
276 KVER=$(installed_version linux-new)
277 if [[ $KVER ]] ; then
286 #---------------------------------------------------------------------------
287 ## Invokes the unamechange spell any spell that uses this should depend on
288 ## unamechange otherwise this function does nothing.
289 ## to use this function simply call then change the variables listed ro have
290 ## any call to uname return that value
291 #--------------------------------------------------------------------------
292 function invoke_uname_change()
294 if [[ $(installed_version unamechange) ]] ; then
295 export UNAME_CHANGE_SYSNAME=$(uname -s)
296 export UNAME_CHANGE_NODENAME=$(uname -n)
297 export UNAME_CHANGE_RELEASE=$(uname -r)
298 export UNAME_CHANGE_VERSION=$(uname -v)
299 export UNAME_CHANGE_MACHINE=$(uname -m)
300 export UNAME_CHANGE_DOMAINNAME=$(uname -o)
302 export LD_PRELOAD="${LD_PRELOAD} /usr/lib/unamechange.so"
306 #-------------------------------------------------------------------------
307 ## Returns the state of the system back to normal after calling
308 ## invoke_uname_change unset's all environmental vars and returns
309 ## LD_PRELOAD back to normal
310 #-------------------------------------------------------------------------
311 function devoke_uname_change()
313 if [[ $(installed_version unamechange) ]] ; then
314 unset UNAME_CHANGE_SYSNAME
315 unset UNAME_CHANGE_NODENAME
316 unset UNAME_CHANGE_RELEASE
317 unset UNAME_CHANGE_VERSION
318 unset UNAME_CHANGE_MACHINE
319 unset UNAME_CHANGE_DOMAINNAME
321 export LD_PRELOAD="${LD_PRELOAD/\/usr\/lib\/unamechange.so/}"
325 #-----------------------------------------------------------------------
326 ## Get the running kernel config status of a some part of the kernel
327 ## given by $1. Used for spells that don't have linux triggers
329 ## $1 string Config variable to look for
330 #-----------------------------------------------------------------------
331 function get_running_kernel_config()
334 # use proc interface because even inside a uname change invoke this
335 # still returns the version of the running kernel
336 if [ -f /proc/sys/kernel/osrelease ] ; then
337 KVER=$(cat /proc/sys/kernel/osrelease)
339 # apparently you don't have proc mount
342 if [ -f /proc/config.gz ] ; then
343 echo $(zgrep "^$1=" /proc/config.gz | awk -F= '{ print $2 }')
344 elif [ -f /boot/config-$KVER ] ; then
345 echo $(grep "^$1=" /boot/config-$KVER | awk -F= '{ print $2 }')
346 elif [ -f /usr/src/linux-$KVER/.config ] ; then
347 echo $(grep "^$1=" /usr/src/linux-$KVER/.config | awk -F= '{ print $2 }')
353 #-------------------------------------------------------------------------
354 ## Get the config status of some part of the kernel sorcery says is
355 ## installed. Used by spells that have linux triggers.
357 ## $1 string Config var to look for
358 #-------------------------------------------------------------------------
359 function get_sorcery_kernel_config()
361 local KVER=$(get_kernel_version)
362 if [ -f /boot/config-$KVER ] ; then
363 echo $(grep "^$1=" /boot/config-$KVER | awk -F= '{ print $2 }')
364 elif [ -f /usr/src/linux-$KVER/.config ] ; then
365 echo $(grep "^$1=" /usr/src/linux-$KVER/.config | awk -F= '{ print $2 }')
372 #-------------------------------------------------------------------------
373 ## Compatibility code for gracefully failing if the user uses an older
374 ## version of sorcery with a spell that calls unpack_file.
375 #-------------------------------------------------------------------------
376 declare -f unpack_file &> /dev/null ||
377 function unpack_file() {
378 message "This spell uses a function only available in sorcery 1.12.2 or newer, please update."
382 #-------------------------------------------------------------------------
383 ## Default build for Python spell.
384 #-------------------------------------------------------------------------
385 function default_build_python() {
386 python setup.py build
389 #-------------------------------------------------------------------------
390 ## Default install for Python spell.
391 ## INSTALL_ROOT is used here only if not empty, because some spells can't
392 ## install with "--root '/'" option.
393 #-------------------------------------------------------------------------
394 function default_install_python() {
395 python setup.py install ${INSTALL_ROOT:+--root "$INSTALL_ROOT/"}