LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   how to create a directory in RPM SPEC file? (https://www.linuxquestions.org/questions/linux-software-2/how-to-create-a-directory-in-rpm-spec-file-687528/)

anadem 12-01-2008 02:12 PM

how to create a directory in RPM SPEC file?
 
To create the directory for our linux driver, the spec file has:
install --directory %{installdir}/linux_driver
which works fine and RPM makes the directory <whatever>/linux_driver

I also need to create the directory /var/mystuff but I can't figure out how to do that.
I tried:
install --directory /var
install --directory /var/mystuff

but (on our build machine, not my development machine) that gets rejected with the message:
+ install --directory /var
install: cannot change permissions of `/var': Operation not permitted


I also tried without making /var first, with just the second line alone, like this:
install --directory /var/mystuff
but that is also rejected. Maybe our build machine doesn't have a /var directory, or maybe it's restricted in some way -- it's not accessible to me, I only get the logs of the build.

So how can the spec file tell RPM to make a directory /var/mystuff?

Thanks for any clues

unSpawn 12-01-2008 03:50 PM

When you're building packages you should be (building as unprivileged user and) confining your work to ${RPM_BUILD_ROOT} and create and place everything there. Next to that most phases accept shell scripting so in the %install phase using 'mkdir ${RPM_BUILD_ROOT}/var' should work too. Make sure you list "/var/mystuff" in %files with the right %attr. If that's not it, please post more details.

anadem 12-01-2008 04:41 PM

Quote:

Originally Posted by unSpawn (Post 3360966)
When you're building packages you should be (building as unprivileged user and) confining your work to ${RPM_BUILD_ROOT} and create and place everything there. Next to that most phases accept shell scripting so in the %install phase using 'mkdir ${RPM_BUILD_ROOT}/var' should work too. Make sure you list "/var/mystuff" in %files with the right %attr. If that's not it, please post more details.

Thanks loads!

In this realm I'm so ignorant that I need to ask:
> Make sure you list "/var/mystuff" in %files with the right %attr.
Given that mystuff needs to be a directory (it might already exist, but if not it must be created) what would be the right %attr ?

Also, will the install fail if mkdir fails due to the directory already being present? That is, is a test required?

thanks again

unSpawn 12-01-2008 04:50 PM

Quote:

Originally Posted by anadem (Post 3361014)
Given that mystuff needs to be a directory (it might already exist, but if not it must be created) what would be the right %attr?

Depends, but since it's a directory that'll be something like octal mode 750 (and the user and group you allow access, if any particular one).


Quote:

Originally Posted by anadem (Post 3361014)
will the install fail if mkdir fails due to the directory already being present? That is, is a test required?

Indeed it is better to test than to assume but the %install phase really drives package creation (and in a temp dir for that matter). Listing the directoryname under %files makes RPM aware it needs to exist for this package and have certain attributes.

anadem 12-01-2008 06:03 PM

Many thanks!

My TODO today: Maximum RPM for bedtime reading.

unSpawn 12-01-2008 06:15 PM

NP. Maybe post the .spec file you're working on here? Could be interesting.

anadem 12-02-2008 12:13 PM

Quote:

Originally Posted by unSpawn (Post 3361092)
NP. Maybe post the .spec file you're working on here? Could be interesting.

Here it is then. The majority is someone else's work, believed to be solid. I'm just trying to tweak it to do a few new things, which is where the problems come up due to my general Linux and specific rpm ignorance. Hints and comments will be most appreciated! (PS I haven't yet added the %attr for the new /var/ads directory.)

Code:

Summary: litarbo
Name: litarbo
Version: %{litarboversion}
Release: %{litarborelease}
License: litarbo
Group: litarbo
URL: www.litarbo.com
Source0: %{name}-%{litarboversion}.tar.bz2
BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot

Provides: perl(fui-lib.pl)
Provides: perl(litarbo_constants)
Provides: perl(litarbo_rpc)

Requires: perl
Requires: litarbo_initscripts >= 1.3-5
Requires: net-snmp >= 5.1.2-6

BuildPreReq: perl

%description

%define installdir $RPM_BUILD_ROOT/litarbo/%{name}-%{version}-%{release}

%define kernel_version %{expand:%{kernel_version_%{_target_cpu}}}
%define kernel_release %{expand:%{kernel_release_%{_target_cpu}}}
%define kernel_smp    %{expand:%{kernel_smp_%{_target_cpu}}}

%prep
%setup -c -q

# Verify that the release in release.h matches what we are building.  Changing release.h
# was easy to forgot so I enforce that here.
pushd server
perl -p \
  -e 'BEGIN { $major_level = 0; $minor_level = 0; $patch_level = 0; $build_level = 0 }' \
  -e 'if (/RELEASE_MAJOR_LEVEL\s*=\s*(\d+)\s*;/) { $major_level = $1; }' \
  -e 'if (/RELEASE_MINOR_LEVEL\s*=\s*(\d+)\s*;/) { $minor_level = $1; }' \
  -e 'if (/RELEASE_PATCH_LEVEL\s*=\s*(\d+)\s*;/) { $patch_level = $1; }' \
  -e 'if (/RELEASE_BUILD_NUMBER\s*=\s*(\d+)\s*;/) { $build_level = $1; }' \
  -e 'END {if ($ENV{'BUILD_NO_RELEASE_CHECK'} == 1) { print "WARNING: Skipping Release Check"; exit 0; }}' \
  -e 'END { if ( "$major_level.$minor_level.$patch_level" ne $ENV{RPM_PACKAGE_VERSION} ) { die "\n*** release.h wrong expecting:$major_level.$minor_level.$patch_level got:$ENV{RPM_PACKAGE_VERSION} ***\n\n"; } }' \
  -e 'END { if ( "$build_level" ne $ENV{RPM_PACKAGE_RELEASE} ) { die "\n*** release.h wrong expecting:$build_level got:$ENV{RPM_PACKAGE_RELEASE} ***\n\n"; } }' \
  release.h
popd

# Create new kernel_versions file.
pushd etc
echo -e "\n%{version} /boot/vmlinuz-%{kernel_version}-%{kernel_release}%{kernel_smp}\n" > kernel_versions
popd

%build

#------------------------------------------------------------------------------

# capri addition
pushd accelshare
make all
popd


# capri linux_driver compile requires ADSSDK environment variable
%define ADSSDK %{_topdir}/BUILD/%{name}-%{litarboversion}/adssdk_linux
export ADSSDK=%{ADSSDK}
pushd linux_driver
mkdir modules

if expr "%{kernel_version}" : "2\.4\."
then
  make clean
  make KERNELVER=unused KERNELDIR=/usr/src/linux-%{kernel_version}-%{kernel_release}%{kernel_smp} KERNELCONFIG=kernel-%{kernel_version}-%{_target_cpu}.config %{_target_cpu}
  cp litarbo-%{_target_cpu}.o modules
else
  make KERNELVER="%{kernel_version}-%{kernel_release}%{kernel_smp}" clean
  make KERNELVER="%{kernel_version}-%{kernel_release}%{kernel_smp}"
  cp litarbo.ko modules
fi

popd


if expr "%{kernel_version}" : "2\.4\."
then
  pushd n22xx_driver/n22xx
  mkdir modules
  make KERNELVER=unused KERNELDIR=/usr/src/linux-%{kernel_version}-%{kernel_release}%{kernel_smp} KERNELCONFIG=kernel-%{kernel_version}-%{_target_cpu}.config %{_target_cpu}
  cp n22xx-%{_target_cpu}.o modules

  # The KERNEL* vars aren't really needed for n22xx_util but it make the Makefile happy.
  make KERNELVER=unused KERNELDIR=/usr/src/linux-%{kernel_version}-%{kernel_release}%{kernel_smp} KERNELCONFIG=kernel-%{kernel_version}-%{_target_cpu}.config n22xx_util
  popd

  pushd n22xx_driver/n2245
  mkdir modules
  make -f Makefile.24 KERNELDIR=/usr/src/linux-%{kernel_version}-%{kernel_release}%{kernel_smp} clean
  make -f Makefile.24 KERNELDIR=/usr/src/linux-%{kernel_version}-%{kernel_release}%{kernel_smp}
  cp n2245.o modules
  popd

  # No n2264 for 32 bit.
  # No n2265 for 32 bit.
  # No n2285 for 32 bit.
else
  for card in n22xx n2245 n2264 n2265 n2285
  do
      pushd n22xx_driver/${card}
      mkdir modules
      make KERNELVER="%{kernel_version}-%{kernel_release}%{kernel_smp}" clean
      make KERNELVER="%{kernel_version}-%{kernel_release}%{kernel_smp}"
      cp ${card}.ko modules
      popd
  done
fi


#------------------------------------------------------------------------------

pushd lib/zlib
make PROCESSOR=%{_target_cpu}
popd

pushd lib/minizip
make PROCESSOR=%{_target_cpu}
popd

pushd lib/lzs
make PROCESSOR=%{_target_cpu}
popd

pushd util/tac_plus
make
popd

pushd scripts
./make_branding_scripts
popd

pushd lib/xmlrpc
make USE_32BIT=0
popd

pushd lib/libedit
./build.sh
popd

pushd lib/libwsapi
make production
popd

pushd server
make clean PROCESSOR=%{_target_cpu}
make production PROCESSOR=%{_target_cpu}
make level1 PROCESSOR=%{_target_cpu}
make level2 PROCESSOR=%{_target_cpu}
g++ -g3 -pthread -shared -fPIC mcpreload.cpp -o mcpreload.so
# capri qos server uses make
make
popd

pushd wscli
make production
popd

#------------------------------------------------------------------------------

%install
rm -rf $RPM_BUILD_ROOT

#------------------------------------------------------------------------------
# install capri ads and plugins
# plugins use the same load/unload.module as ads
#------------------------------------------------------------------------------

install --directory                    %{installdir}/linux_driver
install adssdk_linux/bin/ads.ko        %{installdir}/linux_driver/ads.ko
install linux_driver/litarbo.ko        %{installdir}/linux_driver/litarbo.ko

install accelshare/plugin/linux/tp.ko  %{installdir}/linux_driver/tp.ko
install adssdk_linux/bin/load_module  %{installdir}/linux_driver/load_module
install adssdk_linux/bin/unload_module %{installdir}/linux_driver/unload_module

# make the dir for ads's registry
## install --directory /var
## install --directory /var/ads
### hmm this doesn't work either, gets:
## + install --directory /var
## install: cannot change permissions of `/var': Operation not permitted
##

if [ -d /var/ads ]
then
    echo the /var/ads directory already exists
else
    mkdir /var/ads
fi
 #------------------------------------------------------------------------------
# # OLD install driver
# # capri server uses ads & plugins above
# # ##------------------------------------------------------------------------------
# # install --directory %{installdir}/linux_driver
# # install linux_driver/litarbo_load %{installdir}/linux_driver/litarbo_load
# # install linux_driver/litarbo_unload %{installdir}/linux_driver/litarbo_unload
# # install linux_driver/modules/* %{installdir}/linux_driver/


#------------------------------------------------------------------------------
# install n22xx driver
#------------------------------------------------------------------------------
install --directory %{installdir}/n22xx_driver
pushd n22xx_driver
install load_all %{installdir}/n22xx_driver/load_all
install util_all %{installdir}/n22xx_driver/util_all
popd

install --directory %{installdir}/n22xx_driver/n22xx
pushd n22xx_driver/n22xx
install n22xx_load %{installdir}/n22xx_driver/n22xx/n22xx_load
install n22xx_unload %{installdir}/n22xx_driver/n22xx/n22xx_unload
install modules/* %{installdir}/n22xx_driver/n22xx
install n22xx_util %{installdir}/n22xx_driver/n22xx/n22xx_util
popd

install --directory %{installdir}/n22xx_driver/n2245
pushd n22xx_driver/n2245
install n2245_load %{installdir}/n22xx_driver/n2245/n2245_load
install n2245_unload %{installdir}/n22xx_driver/n2245/n2245_unload
install modules/* %{installdir}/n22xx_driver/n2245
install n2245_util %{installdir}/n22xx_driver/n2245/n2245_util
popd

if [ "%{_target_cpu}" = "x86_64" ]
then
  for card in n2264 n2265 n2285
  do
      install --directory %{installdir}/n22xx_driver/${card}     
      pushd n22xx_driver/${card}
      install ${card}_load %{installdir}/n22xx_driver/${card}/${card}_load
      install ${card}_unload %{installdir}/n22xx_driver/${card}/${card}_unload
      install modules/* %{installdir}/n22xx_driver/${card}
      install ${card}_util %{installdir}/n22xx_driver/${card}/${card}_util
      popd
  done
fi

#------------------------------------------------------------------------------
# install server
#------------------------------------------------------------------------------
install --directory %{installdir}/server
install --directory %{installdir}/server/Trace
install --directory %{installdir}/server/Log
install --directory %{installdir}/scripts
install --directory %{installdir}/etc
install --directory %{installdir}/lib
install --directory %{installdir}/lib/xmlrpc
install --directory %{installdir}/lib/libedit
install --directory %{installdir}/lib/libwsapi
install --directory %{installdir}/wscli

install server/litarbo_production %{installdir}/server/litarbo_server
install server/litarbo_level1 %{installdir}/server/litarbo_level1
install server/litarbo_level2 %{installdir}/server/litarbo_level2
install server/litarbo_server_mc %{installdir}/server/litarbo_server_mc
install server/litarbo_level1_mc %{installdir}/server/litarbo_level1_mc
install server/litarbo_level2_mc %{installdir}/server/litarbo_level2_mc
install server/mcleaks.sh %{installdir}/server/mcleaks.sh
install server/mcpreload.so %{installdir}/server/mcpreload.so
install server/mcpreload.so %{installdir}/server/Trace/mcpreload.so

install lib/xmlrpc/libxmlrpc.*.so %{installdir}/lib/xmlrpc
install lib/libedit/*.so* %{installdir}/lib/libedit
install lib/libwsapi/libwsapi.so %{installdir}/lib/libwsapi

install wscli/wscli %{installdir}/wscli
install wscli/.editrc %{installdir}/wscli/.editrc
install wscli/wsclihelp.txt %{installdir}/wscli/wsclihelp.txt
install wscli/wsclioptions.txt %{installdir}/wscli/wsclioptions.txt

install scripts/brod.pl %{installdir}/scripts/brod.pl
install scripts/broinit %{installdir}/scripts/broinit
install scripts/postinit %{installdir}/scripts/postinit
install scripts/create_nic_config_files %{installdir}/scripts/create_nic_config_files
install scripts/reboot %{installdir}/scripts/reboot
install scripts/edit.syslog.conf %{installdir}/scripts/edit.syslog.conf
install scripts/edit.FactoryDefaults.txt %{installdir}/scripts/edit.FactoryDefaults.txt

install util/tac_plus/tacc %{installdir}/scripts/tacc
install scripts/follow_command %{installdir}/scripts/follow_command
install scripts/megarc %{installdir}/scripts/megarc
install scripts/megarc.bin %{installdir}/scripts/megarc.bin
if [ "%{_target_cpu}" = "x86_64" ]
then
    install scripts/lsiutil %{installdir}/scripts/lsiutil
fi

install etc/kernel_versions %{installdir}/etc/kernel_versions
install etc/features        %{installdir}/etc/features

install --mode a=r scripts/BrandingDefaults.*.txt %{installdir}/scripts
touch  %{installdir}/server/Limits.txt
touch  %{installdir}/server/PermanentLimits.txt


#------------------------------------------------------------------------------
# everything in etc/snmp get shipped
#------------------------------------------------------------------------------
install --directory %{installdir}/etc/snmp
cp -r etc/snmp %{installdir}/etc

#------------------------------------------------------------------------------
# everything in etc/mibs get shipped
#------------------------------------------------------------------------------
install --directory %{installdir}/etc/mibs
cp -r etc/mibs %{installdir}/etc

#------------------------------------------------------------------------------
# install http_root
#------------------------------------------------------------------------------
install --directory %{installdir}/http_root
cp -r http_root %{installdir}
install --directory %{installdir}/apache
install --mode a=r apache/httpd.conf %{installdir}/apache/httpd.conf
install --mode a=r,u=rw apache/default/httpd.port.conf %{installdir}/apache/httpd.port.conf
install --mode a=r,u=rw apache/default/server.crt %{installdir}/apache/server.crt
install --mode a=r,u=rw apache/default/server.key %{installdir}/apache/server.key
install --directory %{installdir}/http_root/temp

#------------------------------------------------------------------------------
# SNMP MIBs
#------------------------------------------------------------------------------
install --directory %{installdir}/http_root/mibs
cp -r etc/mibs %{installdir}/http_root

%post
cd /litarbo

SoftBoostSettings=''
if [ -r current/server/Parameters.txt ]
then
  #
  # If the previous release is 1, 2, 3, 4.0, or 4.1 and softboost is not on
  # then carry that setting to the new release.  That was the old default.
  #
  OldCurrent=$(/litarbo/util/brosys --currentrelease)
  if echo $OldCurrent | egrep --quiet '^(1\.|2\.|3\.|4\.0\.|4\.1\.)' &&
      ! egrep --quiet --ignore-case '^UI.Softboost on' current/server/Parameters.txt
  then
      SoftBoostSetting='UI.Softboost off\n'
  fi
fi

UseHttpsSetting=''
SecurePortSetting=''
if [ -r current/server/Parameters.txt ]
then
  #
  # If the previous release is 4.3 or earlier, carry correct port and https settings.
  #
  OldCurrent=$(/litarbo/util/brosys --currentrelease)
  if echo $OldCurrent | egrep --quiet '^(1\.|2\.|3\.|4\.0\.|4\.1\.|4\.2|4\.3)'
  then
      if ! egrep --quiet --ignore-case '^HTTP.UseHttps on' current/server/Parameters.txt
      then
        UseHttpsSetting='HTTP.UseHttps off\n'
      else
        HttpsPort=$(perl -n -e 'BEGIN {$Port=80;}' -e '$Port=$1 if (m/HTTP.Port\s+(\d+)/i);' -e 'END { print "$Port";}' current/server/Parameters.txt)
        SecurePortSetting="HTTP.SecurePort $HttpsPort"'\n'
      fi
  fi
fi

TransparentMode=''
if [ -r current/server/Parameters.txt ]
then
  #
  # If the previous release is 4.3 or earlier, carry correct TransparentMode Setting.
  #
  OldCurrent=$(/litarbo/util/brosys --currentrelease)
  if echo $OldCurrent | egrep --quiet '^(1\.|2\.|3\.|4\.0\.|4\.1\.|4\.2|4\.3)' &&
      ! egrep --quiet --ignore-case '^WSCLIENT.TransparentMode off' current/server/Parameters.txt
  then
      TransparentMode='WSCLIENT.TransparentMode on\n'
  fi
fi

rm -f previous
[ -h current ] && mv current previous
ln -s %{name}-%{version}-%{release} current

# Be sure to preserve the ownership of Limits.txt so the web GUI and install new ones.
[ -r previous/server/Limits.txt ]      && cp --verbose --preserve previous/server/Limits.txt current/server/Limits.txt
[ -r previous/server/PermanentLimits.txt ]      && cp --verbose --preserve previous/server/PermanentLimits.txt current/server/PermanentLimits.txt
[ -r previous/server/Parameters.txt ] && cp --verbose previous/server/Parameters.txt /litarbo/current/server/Parameters.txt
echo -en $SoftBoostSetting >> current/server/Parameters.txt
echo -en $UseHttpsSetting >> current/server/Parameters.txt
echo -en $SecurePortSetting >> current/server/Parameters.txt
echo -en $TransparentMode >> current/server/Parameters.txt

[ -r previous/server/Trace/clientcert.pem ] && cp --verbose --preserve previous/server/Trace/clientcert.pem current/server/Trace/clientcert.pem

[ -r previous/apache/httpd.port.conf ] && cp --verbose previous/apache/httpd.port.conf /litarbo/current/apache/httpd.port.conf
[ -r previous/apache/server.crt ] && cp --verbose previous/apache/server.crt /litarbo/current/apache/server.crt
[ -r previous/apache/server.key ] && cp --verbose previous/apache/server.key /litarbo/current/apache/server.key

# Cleanup incorrect 1.0 sudoers line.
perl -pi -e 's|nobody ALL=NOPASSWD:/bin/date/|nobody ALL=NOPASSWD:/bin/date|' /etc/sudoers

perl -n \
  -e 'BEGIN { $found = 0; }' \
  -e 'BEGIN { $line  = "nobody ALL=NOPASSWD:/bin/date"; }' \
  -e 'if (/$line/) { $found = 1; }' \
  -e 'END { if (! $found) { `echo $line >> /etc/sudoers`; } }' \
  /etc/sudoers

perl -n \
  -e 'BEGIN { $found = 0; }' \
  -e 'BEGIN { $line  = "nobody ALL=NOPASSWD:/sbin/reboot"; }' \
  -e 'if (/$line/) { $found = 1; }' \
  -e 'END { if (! $found) { `echo $line >> /etc/sudoers`; } }' \
  /etc/sudoers

perl -n \
  -e 'BEGIN { $found = 0; }' \
  -e 'BEGIN { $line  = "nobody ALL=NOPASSWD:/litarbo/util/brosys"; }' \
  -e 'if (/$line/) { $found = 1; }' \
  -e 'END { if (! $found) { `echo $line >> /etc/sudoers`; } }' \
  /etc/sudoers


%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)

# Everything install above
/litarbo/%{name}-%{version}-%{release}

%attr(664, root, nobody) %config(noreplace) /litarbo/%{name}-%{version}-%{release}/server/Limits.txt
%attr(664, root, nobody) %config(noreplace) /litarbo/%{name}-%{version}-%{release}/server/PermanentLimits.txt
%attr(775, root, nobody)  /litarbo/%{name}-%{version}-%{release}/server/Trace
%attr(775, root, nobody)  /litarbo/%{name}-%{version}-%{release}/http_root/temp

%changelog


unSpawn 12-02-2008 05:40 PM

No comments, looks pretty neat...


All times are GMT -5. The time now is 03:02 PM.