grimoire support files
[grimoire-arcane.git] / arcane-games / FUNCTIONS
blob61e2c6869d69d7b0542f3dac23aecec90a60a0ff
1 . $GRIMOIRE/libaccount
2 . $GRIMOIRE/libgcc
4 #---------------------------------------------------------------------
5 ## @return 0 if glibc was compiled with NPTL
6 ## @return 1 otherwise
7 ##
8 ## Detects if the current glibc includes NPTL support.
9 ##
10 #---------------------------------------------------------------------
11 function glibc_is_nptl ()
13   if /lib/libc.so.6 | grep -q NPTL; then
14     return 0
15   fi
16   if /lib/libc.so.6 | grep -q "Native POSIX Threads Library"; then
17     return 0
18   fi
19   return 1
22 #---------------------------------------------------------------------
23 # Runs update-desktop-database if it is installed
24 #---------------------------------------------------------------------
25 function update_desktop_database ()
27   if test -x /usr/bin/update-desktop-database; then
28     message "${MESSAGE_COLOR}Updating application mime type database.${DEFAULT_COLOR}"
29     /usr/bin/update-desktop-database
30   fi
33 #---------------------------------------------------------------------
34 ## this function installs the *.desktop, start* files and qingy links
35 ## this function is intended to be used by spells for windowmanagers
36 #---------------------------------------------------------------------
37 function install_wmfiles ()
39   local wm_desktopfile_dir="${INSTALL_ROOT}/usr/share/xsessions"
40   local wm_startwm_dir="${INSTALL_ROOT}/usr/bin"
42   # install the start* file for the windowmanager if it's not
43   # installed already
44   if [ -f ${SCRIPT_DIRECTORY}/start${SPELL} ] ; then
45     if ! [ -e ${wm_startwm}/start${SPELL} ] ; then
46       install  -m  755  ${SCRIPT_DIRECTORY}/start${SPELL}     \
47                         ${wm_startwm_dir}
48     fi
49   fi
51   # making sure the destination directory exists
52   if ! [ -d  ${wm_desktopfile_dir} ] ; then
53       mkdir  ${wm_desktopfile_dir}
54   fi                                                        &&
56   # install the windowmanagers desktop file
57   if [ -f ${SCRIPT_DIRECTORY}/${SPELL}.desktop ] ; then
58     if ! [ -e ${wm_desktopfile_dir}/${SPELL}.desktop ]; then
59       install  -m  755  ${SCRIPT_DIRECTORY}/${SPELL}.desktop   \
60                         ${wm_desktopfile_dir}
61     fi
62   fi
64   if ( spell_ok qingy ); then
65     if [ -x ${wm_startwm_dir}/start${SPELL} ] ; then
66       if  [  !  -d  ${INSTALL_ROOT}/etc/qingy/xsessions  ];  then
67         install  -d  -m  755  ${INSTALL_ROOT}/etc/qingy/xsessions
68       fi                                                 &&
69       ln -s ${wm_startwm_dir}/start${SPELL}              \
70             ${INSTALL_ROOT}/etc/qingy/xsessions/${SPELL}
71     fi
72   fi
75 #---------------------------------------------------------------------
76 ## Sets the current script to run only one make job
77 #---------------------------------------------------------------------
79 function make_single ()
81   JOBS_PER_HOST=0  &&
82      MAKE_NJOBS=1
85 #---------------------------------------------------------------------
86 ## Re-enables the normal Sorcery make (cancels single_make)
87 #---------------------------------------------------------------------
89 function make_normal ()
91   source $COMPILE_CONFIG
94 #---------------------------------------------------------------------
95 ## @param shellname
96 ## @param full path to shell
98 ## Adds a shell to /etc/shells and optionally to qingy's sessions
99 #---------------------------------------------------------------------
100 function install_shell ()
102   local qingy_session_dir="${INSTALL_ROOT}/etc/qingy/sessions"
104   if [ -z "$1" ] ; then
105     message "${PROBLEM_COLOR}no shell name specified, aborting${DEFAULT_COLOR}"
106     return 1
107   fi &&
108   if [ ! -e "$2" ] ; then
109     message "${PROBLEM_COLOR} $2 isn't executable, no use adding it as a shell${DEFAULT_COLOR}"
110     return 1
111   fi &&
113   #installing shell into /etc/shells
114   message "installing $1 into /etc/shells"
115   if ! ( grep -q "${2}" ${INSTALL_ROOT}/etc/shells ) ; then
116     echo "$2" >> ${INSTALL_ROOT}/etc/shells
117   fi || return 1
119   #installing shell into qingy's session dir if it's installed
120   if ( spell_ok qingy ) && ! [ -f ${qingy_session_dir}/$1 ] ; then
121     message "installing $1 into $qingy_session_dir"
122     echo "$2" > ${qingy_session_dir}/$1 &&
123     chmod 0755 ${qingy_session_dir}/$1
124   fi
127 #---------------------------------------------------------------------
128 ## @param shellname
129 ## @param full path to shell
131 ## Removes a shell from /etc/shells and optionally from qingy's sessions
132 #---------------------------------------------------------------------
133 function remove_shell ()
135   local qingy_session_dir="${INSTALL_ROOT}/etc/qingy/sessions"
137   if [ -z "$1" ] ; then
138     message "${PROBLEM_COLOR}no shell name specified, aborting${DEFAULT_COLOR}"
139     return 1
140   fi &&
141   if [ -z "$2" ] ; then
142     message "${PROBLEM_COLOR}no shell path specified, aborting${DEFAULT_COLOR}"
143     return 1
144   fi &&
146   #removing shell from /etc/shells
147   if  [  -f  /etc/shells  ]  ;  then
148     cat /etc/shells|grep -v "$2" > /etc/shells.tmp &&
149     mv /etc/shells.tmp /etc/shells
150   fi
152   # and optionally from qingy's session dir
153   if [ -f ${qingy_session_dir}/$1 ] ; then
154     message "removing $1 from $qingy_session_dir"
155     rm -f ${qingy_session_dir}/$1
156   fi
160 #---------------------------------------------------------------------
161 ## replacement for config_query_string to work around a short timeout
162 ## when entering long strings (hostnames, organisation names)
163 #---------------------------------------------------------------------
164 function config_query_long_string() {
165     local ANSWER
166     local DELAY=5 
167     if config_get_option "$1" ANSWER; then
168         # option allready answered in config
169         echo -e "[[ ${QUERY_COLOR}$2${DEFAULT} -> '${QUERY_COLOR}$ANSWER${DEFAULT}' ]]"
170     else
171         query_string ANSWER "$2" "$3"
172         read -t $DELAY -n 1 ANSWER_first
173         if [[ $ANSWER_first ]] ; then 
174           read ANSWER_rest
175         fi
176         ANSWER="${ANSWER_first}${ANSWER_rest}"
177         config_set_option "$1" "$ANSWER"
178     fi
179     return 0
182 #---
183 ## @Synopsis default_games_build function to replace
184 ## @Synopsis all the duplication of the same stuff in games-grimoire
185 #---
187 function default_games_build() {
188   OPTS="$OPTS --bindir=${INSTALL_ROOT}/usr/games \
189   --datadir=${INSTALL_ROOT}/usr/share/games \
190   --localstatedir=${INSTALL_ROOT}/var/games"  &&
191   default_build
195 #---
196 ## @Synopsis profile_install function to make installing
197 ## @Synopsis of /etc/profile.d/$spell.sh easier...
198 #---
200 function profile_install() {
201   if [ -f ${SCRIPT_DIRECTORY}/profile/${SPELL}.sh ] ; then
202     if ! [ -e ${INSTALL_ROOT}/etc/profile.d/${SPELL}.sh ] ; then
203       install  -m  755  ${SCRIPT_DIRECTORY}/profile/${SPELL}.sh \
204                         ${INSTALL_ROOT}/etc/profile.d/${SPELL}.sh
205     fi
206   fi
207    
211 #-------------------------------------------------------------------------
212 ## Compatibility code for gracefully failing if the user uses an older
213 ## version of sorcery with a spell that calls unpack_file.
214 #-------------------------------------------------------------------------
215 declare -f unpack_file &> /dev/null ||
216 function unpack_file() {
217   message "This spell uses a function only available in sorcery 1.12.2 or newer, please update."
218   return 1
221 #---
222 ## @Synopsis A function to find all dirs and files and set them to
223 ## @Synopsis proper permissions.
224 #---
226 function find_and_scam() {
227   find ./ -type d -print0 | xargs -0 -n 1 chmod 0750
228   find ./ -type d -print0 | xargs -0 -n 1 chown root.games
229   find ./ -type f -print0 | xargs -0 -n 1 chmod 0640
230   find ./ -type f -print0 | xargs -0 -n 1 chown root.games
233 #---
234 ## @Synopsis games_create_base_dirs function to replace
235 ## @Synopsis all the duplication of the same stuff in games-grimoire
236 ## @Synopsis and to provide some basics for all spells
237 #---
239 function games_create_base_dirs() {
240   mkdir -vp ${INSTALL_ROOT}/usr/share/games/${SPELL}
241   mkdir -vp ${INSTALL_ROOT}/usr/games
242   mkdir -vp ${INSTALL_ROOT}/var/games
245 #---
246 ## @Synopsis games_make_proper_binary function to make all
247 ## @Synopsis binaries in /usr/games chown root.games and
248 ## @Synopsis chmod 0750.
249 #---
251 function games_make_proper_binary() {
252 if ( grep -q "usr/games/" $IW_LOG )
253 then
254   cat $IW_LOG | cut -f 3 | sort | grep "usr/games/" | xargs -n 1 chmod 0750
255   cat $IW_LOG | cut -f 3 | sort | grep "usr/games/" | xargs -n 1 chown root.games
256 else
257   message "${QUERY_COLOR}If you see this message and you're not \n \
258 installing a data spell then report this at the following url: \n \
259 http://bugs.sourcemage.org/enter_bug.cgi?product=Codex&bug_status=NEW&version=games%20grimoire&component=games%20grimoire&rep_platform=Other&op_sys=other&priority=P2&bug_severity=minor&assigned_to=games%40sourcemage.org&cc=&bug_file_loc=http%3A%2F%2F&short_desc=%24SPELL%20not%20installing%20binaries%20properly&comment=&dependson=&blocked=9312&maketemplate=Remember%20values%20as%20bookmarkable%20template&form_name=enter_bug \
260 ${DEFAULT_COLOR}"
264 #---
265 ## @Synopsis default_post_install function to
266 ## @Synopsis clean out any empty share/games/SPELL dirs
267 ## @Synopsis and run the real_default_post_install afterwards
268 #---
270 function default_post_install() {
271   games_make_proper_binary &&
272   rmdir --ignore-fail-on-non-empty ${INSTALL_ROOT}/usr/share/games/${SPELL} &&
273   real_default_post_install
276 #---
277 ## @Synopsis default_pre_install function to
278 ## @Synopsis create some base dirs for spells
279 ## @Synopsis after running real_default_pre_install
280 #---
282 function default_pre_install() {
283   create_group games &&
284   real_default_pre_install &&
285   games_create_base_dirs