minor fixups
[grimoire-planeshift.git] / FUNCTIONS
blobd2e45a44bab835a5cf5741cf07b38da2db0f990f
1 . $GRIMOIRE/libaccount
2 . $GRIMOIRE/libgcc
4 #---------------------------------------------------------------------
5 ## Replaces sorcerys default_pre_build with a custom version using
6 ## the invoke_gcc function from libgcc
7 #---------------------------------------------------------------------
8 function default_pre_build () {
9   invoke_gcc  &&
10   real_default_pre_build
13 #---------------------------------------------------------------------
14 # Runs update-desktop-database if it is installed
15 #---------------------------------------------------------------------
16 function update_desktop_database ()
18   if test -x /usr/bin/update-desktop-database; then
19     message "${MESSAGE_COLOR}Updating application mime type database.${DEFAULT_COLOR}"
20     /usr/bin/update-desktop-database
21   fi
24 #---------------------------------------------------------------------
25 ## Sets the current script to run only one make job
26 #---------------------------------------------------------------------
28 function make_single ()
30   JOBS_PER_HOST=0  &&
31      MAKE_NJOBS=1
34 #---------------------------------------------------------------------
35 ## Re-enables the normal Sorcery make (cancels single_make)
36 #---------------------------------------------------------------------
38 function make_normal ()
40   source $COMPILE_CONFIG
43 #---------------------------------------------------------------------
44 ## replacement for config_query_string to work around a short timeout
45 ## when entering long strings (hostnames, organisation names)
46 #---------------------------------------------------------------------
47 function config_query_long_string() {
48     local ANSWER
49     local DELAY=5 
50     if config_get_option "$1" ANSWER; then
51         # option allready answered in config
52         echo -e "[[ ${QUERY_COLOR}$2${DEFAULT} -> '${QUERY_COLOR}$ANSWER${DEFAULT}' ]]"
53     else
54         query_string ANSWER "$2" "$3"
55         read -t $DELAY -n 1 ANSWER_first
56         if [[ $ANSWER_first ]] ; then 
57           read ANSWER_rest
58         fi
59         ANSWER="${ANSWER_first}${ANSWER_rest}"
60         config_set_option "$1" "$ANSWER"
61     fi
62     return 0
65 #---
66 ## @Synopsis default_games_build function to replace
67 ## @Synopsis all the duplication of the same stuff in games-grimoire
68 #---
70 function default_games_build() {
71   OPTS="$OPTS --bindir=${INSTALL_ROOT}/usr/games \
72   --datadir=${INSTALL_ROOT}/usr/share/games \
73   --localstatedir=${INSTALL_ROOT}/var/games"  &&
74   default_build
78 #---
79 ## @Synopsis profile_install function to make installing
80 ## @Synopsis of /etc/profile.d/$spell.sh easier...
81 #---
83 function profile_install() {
84   if [ -f ${SCRIPT_DIRECTORY}/profile/${SPELL}.sh ] ; then
85     if ! [ -e ${INSTALL_ROOT}/etc/profile.d/${SPELL}.sh ] ; then
86       install  -m  755  ${SCRIPT_DIRECTORY}/profile/${SPELL}.sh \
87                         ${INSTALL_ROOT}/etc/profile.d/${SPELL}.sh
88     fi
89   fi
90    
94 #-------------------------------------------------------------------------
95 ## Compatibility code for gracefully failing if the user uses an older
96 ## version of sorcery with a spell that calls unpack_file.
97 #-------------------------------------------------------------------------
98 declare -f unpack_file &> /dev/null ||
99 function unpack_file() {
100   message "This spell uses a function only available in sorcery 1.12.2 or newer, please update."
101   return 1
104 #---
105 ## @Synopsis A function to find all dirs and files and set them to
106 ## @Synopsis proper permissions.
107 #---
109 function find_and_scam() {
110   find ./ -type d -print0 | xargs -r -0 -n 1 chmod 0750
111   find ./ -type d -print0 | xargs -r -0 -n 1 chown root:games
112   find ./ -type f -print0 | xargs -r -0 -n 1 chmod 0640
113   find ./ -type f -print0 | xargs -r -0 -n 1 chown root:games
116 #---
117 ## @Synopsis games_create_base_dirs function to replace
118 ## @Synopsis all the duplication of the same stuff in games-grimoire
119 ## @Synopsis and to provide some basics for all spells
120 #---
122 function games_create_base_dirs() {
123   mkdir -vp ${INSTALL_ROOT}/usr/share/games/${SPELL}
124   mkdir -vp ${INSTALL_ROOT}/usr/games
125   mkdir -vp ${INSTALL_ROOT}/var/games
128 #---
129 ## @Synopsis games_make_proper_binary function to make all
130 ## @Synopsis binaries in /usr/games chown root.games and
131 ## @Synopsis chmod 0750.
132 #---
134 function games_make_proper_binary() {
135 if grep -q "usr/games/" $IW_LOG > /dev/null 2>&1
136 then
137   grimoire_parse_iw $IW_LOG | grimoire_exists | sort | grep "usr/games/" | xargs -r -n 1 chmod -f 0750
138   grimoire_parse_iw $IW_LOG | grimoire_exists | sort | grep "usr/games/" | xargs -r -n 1 chown -f root:games
139 elif [[ $STAGED_INSTALL == on ]]
140 then
141   echo "doing the stage root thing"
142   find $STAGE_DIRECTORY/TRANSL/ | sed "s#$STAGE_DIRECTORY/##" | grep '^TRANSL/usr/games' | xargs -r -n 1 chmod -f 0750
143   find $STAGE_DIRECTORY/TRANSL/ | sed "s#$STAGE_DIRECTORY/##" | grep '^TRANSL/usr/games' | xargs -r -n 1 chown -f root:games
144 else
145 message "${QUERY_COLOR}If you see this message and you're not \n \
146 installing a data spell then report this at the following url: \n \
147 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=${SPELL}%20not%20installing%20binaries%20properly&comment=&dependson=&blocked=9312&maketemplate=Remember%20values%20as%20bookmarkable%20template&form_name=enter_bug \
148 ${DEFAULT_COLOR}"
152 #---
153 ## @Synopsis default_post_install function to
154 ## @Synopsis clean out any empty share/games/SPELL dirs
155 ## @Synopsis clean out any empty gather docs dirs
156 ## @Synopsis and run the real_default_post_install afterwards
157 #---
159 ## @Synopsis default_pre_install function to
160 ## @Synopsis create some base dirs for spells
161 ## @Synopsis after running real_default_pre_install
162 #---
165 #---
166 ## @Synopsis a parse_iw clone function
167 #---
169 function grimoire_parse_iw()  {
170   local INPUT=$1
171   
172   # it is EXTREMELY IMPORTANT that this variable contains an actual
173   # tab character and not some number of spaces. Otherwise BAD THINGS
174   # will happen.
175   local TAB="   "
176   OMIT_IN="${TAB}rename\|${TAB}symlink\|${TAB}unlink"
177   
178   grep -v "$OMIT_IN" $INPUT | cut -f3 | grep "^/"
179   cat                $INPUT | cut -f4 | grep "^/"
182 #---
183 ## @Synopsis an exists clone function
184 #---
185 function grimoire_exists()  {
186   while  read  ITEM;  do  [  -e  "$ITEM"  ]  &&  echo  "$ITEM";  done;
189 #---
190 ## @Synopsis verify_file function until it's in stable sorcery
191 #---
192 declare -f verify_file &>/dev/null ||
193 function verify_file() {
194   local SVAR="SOURCE${FILENUM}"
195   local AVAR="SOURCE${FILENUM}_HASH"
196   unpack_hash ${!SVAR} ${!AVAR}
200 #---
201 ## disable_pic
202 ## A function to smartly disable -DPIC and -fPIC flags
203 ## has one optional parameter: force which forces disable
204 #---
205 disable_pic() {
206   if [[ "${SMGL_COMPAT_ARCHS[1]}" != "x86_64" ]] &&
207      [[ "${SMGL_COMPAT_ARCHS[1]}" != "alpha"  ]] ||
208      [[ "$1" == "force" ]]
209   then
210     CFLAGS=${CFLAGS/-fPIC}                    &&
211     CFLAGS=${CFLAGS/-DPIC}                    &&
212     CXXFLAGS=${CXXFLAGS/-fPIC}                &&
213     CXXFLAGS=${CXXFLAGS/-DPIC}
214   fi
218 ## Function to check if we're using xorg-modular libs or not
220 function check_if_xorg_modular_libs()
222   if  [[  "$(get_spell_provider  ${1:-$SPELL}  X11-LIBS)"  ==  "xorg-server"  ]] ||
223       [[  "$(get_spell_provider  ${1:-$SPELL}  X11-LIBS)"  ==  "xorg-libs"  ]]     
224   then
225      return 0
226   fi
227   return 1
231 ## Function to check if we're using xorg-modular server or not
234 function check_if_xorg_modular_server()
236    if  [[  "$(get_spell_provider  ${1:-$SPELL}  X11-SERVER)"  ==  "xorg-server"  ]]
237    then
238       return 0
239    fi
240    return 1