nginx + uwsgi + flask 补充内容

于 2024年6月1号开始把的云主机从张北迁移到杭州来,因为 OS 是从 6U 升级到 阿里云的龙蜥OS 8u,所以,光 WordPress 就折腾了1天多,终于搞定。

然后,记起来以前也通过 php 的 server 支持了 ios 的 API服务,所以,尝试把 ios 的服务端切换到 flask + python 来。

继续研究了 2018年的在博客记录的 flask 的配置,稍作了修改,如下:

1: 首先,使用一个域名 cmesoft.com 提供服务。

2:其次,配置 /etc/nginx/conf.d/cmesoft.conf 支持 WordPress站点,内容如下:

server {
	    	listen       80;                        # 监听端口
		server_name www.cmesoft.com cmesoft.com;    # 站点域名
		#server_name  121.199.16.184 121.199.16.184;
			client_max_body_size 50M;
	                  # 站点根目录

	    	
	       location / {
		       		#index index.html index.htm index.php;   # 默认导航页
				root  /data/web/cmesoft;    
				index  index.php index.html index.htm;
						        }

	           location ~ \.php$ {

			        fastcgi_pass 127.0.0.1:9000;
				#fastcgi_index index.php;
				#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
				fastcgi_param  SCRIPT_FILENAME  /data/web/cmesoft/$fastcgi_script_name;
				include        fastcgi_params;
			}
}

3:因为 wordpress 的页面放在: /data/web/cmesoft 下,而 python api的代码放在 /data/web/pyapi 底下,所以,为了把服务隔离开,不同的目录,不同额端口,给 pyapi 配置另外一个服务端口。

4. pyapi 的 nginx 配置如下:

cat  /etc/nginx/conf.d/pyapi.conf 
server {
	listen       8080 default_server;
	server_name  _;

	location ~ /pyapi { 
		proxy_pass http://127.0.0.1:8888;
			}

		error_page 404 /404.html;
		location = /40x.html {
				}

		error_page 500 502 503 504 /50x.html;
			location = /50x.html {
			}

}

让 pyapi 监听 8080 端口,转到后端 flask 的 8888 端口,uwsgi 配置如下:

cat uwsgi.ini
[uwsgi]
## For directlly http access
http-socket=127.0.0.1:8888

### For nginx proxy
#socket=/tmp/ppt.sock

wsgi-file=/data/web/pyapi/server.py
#plugins = python
callable = app
#chdir = /data/install/bin
touch-reload=/data/web/pyapi/
processes = 4
threads = 4
stats = 127.0.0.1:9191
post-buffering = 8192
buffer-size = 65535
socket-timeout = 10
uid = apache
gid = apache
master = true
#protocol = uwsgi
daemonize = uwsgi.log
pidfile = uwsgi.pid

然后,/data/web/pyapi/server.py 内容如下:

cat server.py 
from flask import Flask,render_template, jsonify
from flask import request

app = Flask(__name__)

@app.route('/pyapi', methods=['GET', 'POST'])
def index():
    requester = request.remote_addr
    #logging.info('Data request from: %s' % requester)
    url = request.url
    uid = url.split('uid=')[-1]
    get_name=request.args.get("name")
    post_name=request.form.get("name")
                                            #return "Test message, your input uid=%s, method=%s, get_name=%s, post_name=%s  from %s\n" % (uid, request.method, get_name, post_name, requester)
                                            
    return jsonify(get_name=get_name,post_name=post_name)

if __name__ == '__main__':
    app.run()

在阿里云的ECS上开启对外的 8080 端口服务,测试如下:

# curl -s "cmesoft.com:8080/pyapi?uid=3434&name=get_Wade" -d "name=post_james" | jq
{
  "get_name": "get_Wade",
  "post_name": "post_james"
}

从代码和测试可以看到,我们的 FLASK API 接受 GET 和 POST 调用,可以作为一个小小的 服务端 API 网关。

今天就更新到这里。 —- 2024-06-02 22:20 分。

Posted in 运维相关 | 添加回复

mysql几个常用知识【2007-11-20 19:14:22】

(1)一般情况下,我们在后台直接访问数据库的机会很少,大多数时间都是通过工具如mysqladmin或者phpadmin远程访问mysql数据库服务器的,以mysqladmin为例。
如果想从192.168.1.102上以cme身份访问192.168.1.10上的mysql数据库服务,那么就需要在数据库服务器上添加这个账户。
首先,登录数据库后台:
mysql -uroot -plinuxmysql
登录到数据库提示符,然后创建cme用户,指定主机为192.168.1.102,从192.168.1.102以cme用户名登录到这台数据库服务器的密码为‘windowsmysql’,如下:
mysql>CREATE USER cme@192.168.1.102 IDENTIFIED BY ‘windowsmysql’;
mysql>exit;
这个时候,在192.168.1.102上用mysqladmin连接192.168.1.10上的mysql服务,默认端口为3306,不需要修改。
我们可以看到,很快就连接上了,如果有问题请检查防火墙设置等问题。
然后,右键创建数据库,你会发现弹出对话框提示不能创建,因为还没有给cme分配数据库的操作权限,所以下来需要给cme@192.168.1.102分配权限。
mysql>GRANT CREATE ON . TO cme@192.168.1.102 WITH GRANT OPTION;
给cme@192.168.1.102分配了create database的权限,然后我们退出mysqladmin后再次用mysqladmin连接上,创建数据库,成功,相应的,如果你还想使得在cme@192.168.1.102访问数据库时拥有跟多权限,就需要给它grant跟多的操作,如INSERT, DROP, UPDAE等。ON ‘数据库’表示对某个数据库的操作。
一般都是分配所有的权限,比如
mysql > GRANT ALL PRIVILEGES ON . TO cme@192.168.1.102 WITH GRANT OPTION
这样cme@192.168.1.102登录到192.168.1.10上的数据库后就能进行任何操作了。
如果你想在任何机子上都能登录数据库服务器并进行操作,可以如下写:
mysql>RANT ALL PRIVILEGES ON . TO cme@”%” [IDENTIFIED BY ‘windowsmysql’] WITH GRANT OPTION
如果已经设置了密码就没有必要再写上[IDENTIFIED BY ’windowsmysql’]了。
然后就可以尽情的访问了
一般情况下需要以root超级用户登录到数据库上设置其他超级用户的权限。
所以,我的数据库一般都设置为
mysql>
mysql>RANT ALL PRIVILEGES ON . TO root@”%” [IDENTIFIED BY ‘windowsmysql’] WITH GRANT OPTION
直接使用root进行访问。
注意,我们在这里给root grant的密码跟root直接从后台登陆的密码并不一定一致。linuxmysql是在localhost上登录时root的密码,windowsmysql是从任意主机登录时的密码(或者你也可以针对不同的客户端给root分配不同的连接密码,比如192.168.1.102连接到数据库的root密码为123455,而192.168.1.104以root连接数据库时密码可以为54321等等),这个我们可以从mysql的user表中的数据得到验证。
mysql>use mysql;
mysql> select Host, User, PassWord from user;
+———————–+——+——————————+
| Host | User | PassWord |
+———————–+——+—————–+
| localhost | root | *0E2B5059346AC0140970837959E5F4B3BA8E96E0 |
| localhost.localdomain | root | *0E2B5059346AC0140970837959E5F4B3BA8E96E0 |
| 127.0.0.1 | root | *0E2B5059346AC0140970837959E5F4B3BA8E96E0 |
| % | root | *6C24E7AC61619C4631613121B51F419DAA626E5E |
| 192.168.1.102 | cme | *6C24E7AC61619C4631613121B51F419DAA626E5E |
+———————–+——+——————————————-+
我们能看到,虽然密码加密了,但是不同的Host还是有不同的密码的。
(2)root密码忘记后恢复。
这个只能在后台直接修改了,远程就不行了。
先停止数据库服务
service mysqld stop
然后启动msyql,跳过身份验证。
#/usr/local/mysql/bin/mysqld_safe –skip-grant-tables &
然后mysql -uroot登录就不需要输入密码了
mysql>update mysql.user set password=PASSWORD(‘nothing’) where (User=’root’) and (Host = ‘localhost’);
mysql>flush privileges;
mysql>exit;
注意:如果你不加上Host = “localhost”的话,就改了所有root的密码
即192.168.1.102登录mysql的密码也被改了,这个要慎重修改喔。
然后再次连接就OK了
#mysql -uroot -pnothing
正常登录了。

(2)

Posted in 运维相关 | mysql几个常用知识【2007-11-20 19:14:22】已关闭评论

sun880服务器安装sparc solaris9以及网络配置-[2006-11-22 15:31:29]

昨天下午进驻机房安装sparc Solaris9,目标机是一台sun880的服务器
4G内存,6个70G的硬盘。到刚才终于把网络配置好了,赶紧收藏一下经验!
记录一些关键点:
(1):机子启动后同时按 stop + a 这两个键,然后输入boot cdrom,会进入光盘安装模式,这个不知道就惨了。
(2):语言选择 Chinese-GBXXX,不要选chinese utfXXX之类的
(3):网络不要选nis,dns之类的,选择none
(4):网络设备选择eri0或者hme0,但是不要选择ge0,否则会遇到我们今天遇到的问题,后面再说。
(5):分区时,先让系统自己分,然后手动调整,但是记住/export/home要分最大的,剩下的空间都给它。如果多个磁盘不支持raid,就分成/export/home0 /export/home1 ==。
(6):流程 disk1(1/2 software) installing ->auto reboot->disk2(2/2 software)->disk3(language)
(7):安装完成
如果网络配置好但是却不通,就要检测启用的设备是否正确
我在安装时选择了ge0,但是怎么都ping不通内网
最后看帖子发现是设备选错了,修改如下
ifconfig ge0 down
ifconfig ge0 unplumb
ifconfig eri0 plumb
ifconfig eri0 up
…配置参数
但是默认的配置再Reboot后又会恢复,所以写个脚本让它开机自己修改
以我们的Solaris9 图形登陆方式为例
在/etc/rc3.d下建立一个文件S51network,注意你的机子不一定是这个目录这个文件,要根据具体情况进行判断。
内容为:
ifconfig ge0 down
ifconfig ge0 unplumb
ifconfig eri0 plumb
ifconfig eri0 up
ifconfig eri0 10.0.0.58 netmask 255.255.0.0
route add default 10.0.254.254
如果你想在开机时和关机时各执行不通的任务,那就加几句:
case “$1” in
‘start’)
开机做的事情
;;
‘stop’)
关机做的事情
;;
*)
其他的
;;
esac
exit 0
比较容易理解,这个就跟Linux的chkconfig的原理一样。
然后 reboot就行了
。。。。。
估计还要装gcc 和 glibc,有空再加上来吧。(瞌睡死了,阿米豆腐)

Posted in 运维相关 | sun880服务器安装sparc solaris9以及网络配置-[2006-11-22 15:31:29]已关闭评论

redhat8 安装 ffmpeg

安装repo

安装repo:

dnf -y install https://download.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Posted in 系统管理 | redhat8 安装 ffmpeg已关闭评论

Centos7u6 配置多个本地盘做 RAID10

(1) 安装软件包


sudo yum install mdadm

(2) 查看磁盘信息


sudo fdisk -l | grep --color=auto 3840 | awk '{print $2}'
/dev/nvme4n1:
/dev/nvme2n1:
/dev/nvme3n1:
/dev/nvme6n1:
/dev/nvme5n1:
/dev/nvme11n1:
/dev/nvme7n1:
/dev/nvme9n1:
/dev/nvme8n1:
/dev/nvme10n1:
/dev/nvme0n1:
/dev/nvme1n1:

(3) 创建raid设备


sudo mdadm -C --metadata=1.0 -v /dev/md10 -l 10 -a yes -n 12 /dev/nvme0n1 /dev/nvme10n1 /dev/nvme11n1 /dev/nvme1n1 /dev/nvme2n1 /dev/nvme3n1 /dev/nvme4n1 /dev/nvme5n1 /dev/nvme6n1 /dev/nvme7n1 /dev/nvme8n1 /dev/nvme9n1

(4) 格式化磁盘


sudo mkfs.ext4 /dev/md10

(5) 存储mdadm.conf 内容

清空每个盘的超级块:


for((i=0;i<=11;i++)); do dd if=/dev/zero of=/dev/nvme${i}n1 bs=1M count=10 oflag=direct; done

生成配置文件


echo "DEVICE /dev/nvme0n1 /dev/nvme10n1 /dev/nvme11n1 /dev/nvme1n1 /dev/nvme2n1 /dev/nvme3n1 /dev/nvme4n1 /dev/nvme5n1 /dev/nvme6n1 /dev/nvme7n1 /dev/nvme8n1 /dev/nvme9n1" > mdadm.conf
sudo mdadm -Ds >> mdadm.conf
sudo mv mdadm.conf /etc/

内容如下:

DEVICE /dev/nvme0n1 /dev/nvme10n1 /dev/nvme11n1 /dev/nvme1n1 /dev/nvme2n1 /dev/nvme3n1 /dev/nvme4n1 /dev/nvme5n1 /dev/nvme6n1 /dev/nvme7n1 /dev/nvme8n1 /dev/nvme9n1
ARRAY /dev/md10 metadata=1.0 name=g87c05434.cloud.et91:10 UUID=471a5242:a9272664:438f0881:ab3889bf

(6)尝试挂载

在 /etc/fstab添加一行

/dev/md10 /data ext4 defaults,noatime,nofail 0 0

然后

sudo mkdir /data
sudo mount -a

查看下

df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 50G 2.7G 44G 6% /
/dev/md10 21T 20K 20T 1% /data

(7)测试于排查

1.注释掉 fstab 中的内容,然后reboot重启查看能否加载上来/dev/md0
2.如果重启时raid信息丢失
mdadm -As -v 提示找不到superblock啥的,可能跟 HDD/SSD盘有关,注意更换下 –metadata=xx的版本,比如 0.9,1.0或者1.2
3.参考:https://www.cnblogs.com/lpfuture/p/6385657.html?utm_source=itdadao&utm_medium=referral

Posted in 系统管理 | Centos7u6 配置多个本地盘做 RAID10已关闭评论

python 的 yaml 操作例子

依赖


rpm -qa | grep PyYAML
PyYAML-3.10-3.1.el6.x86_64

例子代码


#!/usr/bin/python
import os, sys,yaml

fname="index.yaml"

f = open(fname,"r")
x=yaml.load(f)

#print(x)

dist={}

dlist="centos6.x86_64|centos7.x86_64"
arr = dlist.split("|")

for ite in arr:
dist[ite] = {}
dist[ite]['release'] = "{{.gitcount}}.{{.dist}}"
x['distribution'] = dist
#print "\n\n"
#print x
#print "\n"
ret = yaml.dump(x)
print ret

Posted in 运维相关 | 2 Comments

字幕校准脚本

1 先在编辑器把时间补充上,内容写上特殊字符,如 OOO
2 然后下载字幕文件如 srt, 拷贝到 linux 下,存成 v.txt
3 运行 ad.py 会把 OOO 杭内容过滤掉,后面的内容依次往上提。
代码如下:

#!/usr/bin/env python

if name == 'main':
f=open("v.txt", "r")
plist=[]
mlist=[]
tlist=[]
while True:
ptr1 = f.readline()
tm1 = f.readline()
msg1 = f.readline()
blank = f.readline()
ptr = ptr1.strip('\n')
if not ptr:
break
tm = tm1.strip('\n')
msg = msg1.strip('\n')
plist.append(ptr)
mlist.append(msg)
tlist.append(tm)
diff=0
for i in range(0, len(mlist)):
if(i+diff >= len(mlist)):
break
print "%s\n%s" % (plist[i], tlist[i])
while(mlist[i+diff] == "ooo"):
diff = diff + 1
print "%s\n" % mlist[i+diff]

        #print "%s\n%s\n%s\n" % (ptr, tm, msg)

Posted in DEVOPS | 1 Comment

rpm 宏定义文档

路径为:
/usr/lib/rpm/macros

内容为:
#/*! \page config_macros Default configuration: /usr/lib/rpm/macros

\verbatim

#

This is a global RPM configuration file. All changes made here will

be lost when the rpm package is upgraded. Any per-system configuration

should be added to /etc/rpm/macros, while per-user configuration should

be added to ~/.rpmmacros.

#
#==============================================================================

Macro naming conventions (preliminary):

#
# Macros that begin with an underscore are “local” in the sense that
# they (if used) will not be exported in rpm headers. Some macros
# that don’t start with an underscore (but look like they should)
# are compatible with macros generated by rpm-2.5.x and will be made
# more consistent in a future release.
#

#==============================================================================

—- A macro that expands to nothing.

#
%nil %{!?nil}

#==============================================================================

—- filesystem macros.

#
%_usr /usr
%_usrsrc %{_usr}/src
%_var /var

#==============================================================================

—- Generally useful path macros.

#
%__7zip /usr/bin/7za
%__awk gawk
%__bzip2 /usr/bin/bzip2
%__cat /usr/bin/cat
%__chgrp /usr/bin/chgrp
%__chmod /usr/bin/chmod
%__chown /usr/bin/chown
%__cp /usr/bin/cp
%__cpio /usr/bin/cpio
%__file /usr/bin/file
%__gpg %{_bindir}/gpg2
%__grep /usr/bin/grep
%__gzip /usr/bin/gzip
%__id /usr/bin/id
%__id_u %{__id} -u
%__install /usr/bin/install
%__ln_s ln -s
%__lrzip /usr/bin/lrzip
%__lzip /usr/bin/lzip

Deprecated, use %__xz instead.

%__lzma %__xz –format=lzma
%__xz /usr/bin/xz
%__make /usr/bin/make
%__mkdir /usr/bin/mkdir
%__mkdir_p /usr/bin/mkdir -p
%__mv /usr/bin/mv
%__patch /usr/bin/patch
%__perl /usr/bin/perl
%__python /usr/bin/python
%__restorecon /sbin/restorecon
%__rm /usr/bin/rm
%__rsh /usr/bin/rsh
%__sed /usr/bin/sed
%__semodule /usr/bin/semodule
%__ssh /usr/bin/ssh
%__tar /usr/bin/tar
%__unzip /usr/bin/unzip
%__git /usr/bin/git
%__hg /usr/bin/hg
%__bzr /usr/bin/bzr
%__quilt /usr/bin/quilt

#==============================================================================

—- Build system path macros.

#
%__ar ar
%__as as
%__cc gcc
%__cpp gcc -E
%__cxx g++
%__ld /usr/bin/ld
%__nm /usr/bin/nm
%__objcopy /usr/bin/objcopy
%__objdump /usr/bin/objdump
%__ranlib ranlib
%__remsh %{__rsh}
%__strip /usr/bin/strip

XXX avoid failures if tools are not installed when rpm is built.

%__libtoolize libtoolize
%__aclocal aclocal
%__autoheader autoheader
%__automake automake
%__autoconf autoconf

#==============================================================================

Conditional build stuff.

Check if symbol is defined.

Example usage: %if %{defined with_foo} && %{undefined with_bar} …

%defined() %{expand:%%{?%{1}:1}%%{!?%{1}:0}}
%undefined() %{expand:%%{?%{1}:0}%%{!?%{1}:1}}

Shorthand for %{defined with_…}

%with() %{expand:%%{?with_%{1}:1}%%{!?with_%{1}:0}}
%without() %{expand:%%{?with_%{1}:0}%%{!?with_%{1}:1}}

Handle conditional builds. %bcond_with is for case when feature is

default off and needs to be activated with –with … command line

switch. %bcond_without is for the dual case.

#

%bcond_with foo defines symbol with_foo if –with foo was specified on

command line.

%bcond_without foo defines symbol with_foo if –without foo was not

specified on command line.

#

For example (spec file):

#

(at the beginning)

%bcond_with extra_fonts

%bcond_without static

(and later)

%if %{with extra_fonts}

%else

%endif

%if ! %{with static}

%endif

%ifdef %{with static}

%endif

%{?with_static: … }

%{!?with_static: … }

%{?with_extra_fonts: … }

%{!?with_extra_fonts: … }

#

The bottom line: never use without_foo, _with_foo nor _without_foo, only

with_foo. This way changing default set of bconds for given spec is just

a matter of changing single line in it and syntax is more readable.

%bcond_with() %{expand:%%{?with%{1}:%%global with_%{1} 1}}
%bcond_without() %{expand:%%{!?without%{1}:%%global with_%{1} 1}}
#
#==============================================================================

—- Required rpmrc macros.

# Macros that used to be initialized as a side effect of rpmrc parsing.
# These are the default values that can be overridden by other
# (e.g. per-platform, per-system, per-packager, per-package) macros.
#
# The directory where rpm’s configuration and scripts live
%_rpmconfigdir %{getconfdir}

# The directory where sources/patches will be unpacked and built.
%_builddir %{_topdir}/BUILD

# The interpreter used for build scriptlets.
%_buildshell /bin/sh

# The path to the bzip2 executable (legacy, use %{__bzip2} instead).
%_bzip2bin %{__bzip2}

# The location of the rpm database file(s).
%_dbpath %{_var}/lib/rpm

# The location of the rpm database file(s) after “rpm –rebuilddb”.
%_dbpath_rebuild %{_dbpath}

%_keyringpath %{_dbpath}/pubkeys/

#
# Path to script that creates debug symbols in a /usr/lib/debug
# shadow tree.
#
# A spec file can %%define _find_debuginfo_opts to pass options to
# the script. See the script for details.
#
%__debug_install_post \
%{_rpmconfigdir}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:–strict-build-id} %{?_include_minidebuginfo:-m} %{?_find_debuginfo_dwz_opts} %{?_find_debuginfo_opts} “%{_builddir}/%{?buildsubdir}”\
%{nil}

# Template for debug information sub-package.
%debug_package \
%ifnarch noarch\
%global __debug_package 1\
%package debuginfo\
Summary: Debug information for package %{name}\
Group: Development/Debug\
AutoReqProv: 0\
%description debuginfo\
This package provides debug information for package %{name}.\
Debug information is useful when developing applications that use this\
package or when debugging this package.\
%files debuginfo -f debugfiles.list\
%defattr(-,root,root)\
%endif\
%{nil}

%_defaultdocdir %{_datadir}/doc
%_defaultlicensedir %{_datadir}/licenses

# The path to the gzip executable (legacy, use %{__gzip} instead).
%_gzipbin %{__gzip}

# The Unix time of the latest kept changelog entry in binary packages.
# Any older entry is not packaged in binary packages.
%_changelog_trimtime 0

# The directory where newly built binary packages will be written.
%_rpmdir %{_topdir}/RPMS

# A template used to generate the output binary package file name
# (legacy).
%_rpmfilename %{_build_name_fmt}

# The directory where sources/patches from a source package will be
# installed. This is also where sources/patches are found when building.
%_sourcedir %{_topdir}/SOURCES

# The directory where the spec file from a source package will be
# installed.
%_specdir %{_topdir}/SPECS

# The directory where newly built source packages will be written.
%_srcrpmdir %{_topdir}/SRPMS

# The directory where buildroots will be created.
%_buildrootdir %{_topdir}/BUILDROOT

# Build root path, where %install installs the package during build.
%buildroot %{_buildrootdir}/%{name}-%{version}-%{release}.%{_arch}

# Directory where temporaray files can be created.
%_tmppath %{_var}/tmp

# Path to top of build area.
%_topdir %{getenv:HOME}/rpmbuild

# The path to the unzip executable (legacy, use %{__unzip} instead).
%_unzipbin %{__unzip}

#==============================================================================

—- Optional rpmrc macros.

# Macros that are initialized as a side effect of rpmrc and/or spec
# file parsing.
#
# The sub-directory (relative to %{_builddir}) where sources are compiled.
# This macro is set after processing %setup, either explicitly from the
# value given to -n or the default name-version.
#
#%buildsubdir

# Configurable distribution information, same as Distribution: tag in a
# specfile.
#
#%distribution

# Configurable distribution URL, same as DistURL: tag in a specfile.
# The URL will be used to supply reliable information to tools like
# rpmfind.
#

Note: You should not configure with disturl (or build packages with

the DistURL: tag) unless you are willing to supply content in a

yet-to-be-determined format at the URL specified.

#
#%disturl

# Configurable bug URL, same as BugURL: tag in a specfile.
# The URL will be used to supply reliable information to where
# to file bugs.
#
#%bugurl

# Boolean (i.e. 1 == “yes”, 0 == “no”) that controls whether files
# marked as %doc should be installed.
#%_excludedocs

# The port and machine name of a FTP proxy host running TIS firewall.
#
#%_ftpport
#%_ftpproxy

# The signature to use and the location of configuration files for
# signing packages with GNU gpg.
#
#%_gpg_name
#%_gpg_path

# The port and machine name of an HTTP proxy host.
#
#%_httpport
#%_httpproxy

# The PATH put into the environment before running %pre/%post et al.
#
%_install_script_path /sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin

# A colon separated list of desired locales to be installed;
# “all” means install all locale specific files.
#
%_install_langs all

# The value of CLASSPATH in build scriptlets (iff configured).
#
#%_javaclasspath all

# Import packaging conventions from jpackage.org (prefixed with _
# to avoid name collisions).
#
%_javadir %{_datadir}/java
%_javadocdir %{_datadir}/javadoc

# A colon separated list of paths where files should not be installed.
# Usually, these are network file system mount points.
#
#%_netsharedpath

# (experimental)
# The type of pattern match used on rpmdb iterator selectors:
# “default” simple glob-like regex, periods will be escaped,
# splats will have period prepended, full “^…$” match
# required. Also, file path tags will use glob(7).
# “strcmp” compare strings
# “regex” regex(7) patterns using regcomp(3)/regexec(3)
# “glob” glob(7) patterns using fnmatch(3)
#
%_query_selector_match default

# Configurable packager information, same as Packager: in a specfile.
#
#%packager

# Compression type and level for source/binary package payloads.
# “w9.gzdio” gzip level 9 (default).
# “w9.bzdio” bzip2 level 9.
# “w7.xzdio” xz level 7, xz’s default.
# “w7.lzdio” lzma-alone level 7, lzma’s default
#
#%_source_payload w9.gzdio
#%_binary_payload w9.gzdio

# Algorithm to use for generating file checksum digests on build.
# If not specified or 0, MD5 is used.
# WARNING: non-MD5 is backwards incompatible, don’t enable lightly!
# The supported algorithms may depend on NSS version, as of NSS
# 3.11.99.5 the following are supported:
# 1 MD5 (default)
# 2 SHA1
# 8 SHA256
# 9 SHA384
# 10 SHA512
#
#%_source_filedigest_algorithm 1
#%_binary_filedigest_algorithm 1

# Configurable vendor information, same as Vendor: in a specfile.
#
#%vendor

# Default fuzz level for %patch in spec file.
%_default_patch_fuzz 0

# Default patch flags
#%_default_patch_flags -s

#==============================================================================

—- Build configuration macros.

#

Script gets packaged file list on input and buildroot as first parameter.

Returns list of unpackaged files, i.e. files in $RPM_BUILD_ROOT not packaged.

#

Note: Disable (by commenting out) for legacy compatibility.

%__check_files %{_rpmconfigdir}/check-files %{buildroot}

#

Should unpackaged files in a build root terminate a build?

#

Note: The default value should be 0 for legacy compatibility.

%_unpackaged_files_terminate_build 1

#

Should missing %doc files in the build directory terminate a build?

#

Note: The default value should be 0 for legacy compatibility.

%_missing_doc_files_terminate_build 1

#

Should binaries in noarch packages terminate a build?

%_binaries_in_noarch_packages_terminate_build 1

#

Should rpm try to download missing sources at build-time?

Enabling this is dangerous as long as rpm has no means to validate

the integrity of the download with a digest or signature.

%_disable_source_fetch 1

#

Program to call for each successfully built and written binary package.

The package name is passed to the program as a command-line argument.

#
#%_build_pkgcheck %{_bindir}/rpmlint

#

Program to call for the whole binary package set after build.

The package set is passed to the program via command-line arguments.

#
#%_build_pkgcheck_set %{_bindir}/rpmlint

#

Program to call for successfully built and written SRPM.

The package name is passed to the program as a command-line argument.

#
#%_build_pkgcheck_srpm %{_bindir}/rpmlint

#

Should the build of packages fail if package checker (if defined) returns

non-zero exit status?

#
#%_nonzero_exit_pkgcheck_terminate_build 1

#

Should an ELF file processed by find-debuginfo.sh having no build ID

terminate a build? This is left undefined to disable it and defined to

enable.

#
#%_missing_build_ids_terminate_build 1

#

Include minimal debug information in build binaries.

Requires _enable_debug_packages.

#
#%_include_minidebuginfo 1

#

Use internal dependency generator rather than external helpers?

%_use_internal_dependency_generator 1

#

Filter GLIBC_PRIVATE Provides: and Requires:

%_filter_GLIBC_PRIVATE 0

Directories whose contents should be considered as documentation.

%__docdir_path %{_datadir}/doc:%{_datadir}/man:%{_datadir}/info:%{_datadir}/gtk-doc/html:%{?_docdir}:%{?_mandir}:%{?_infodir}:%{?_javadocdir}:/usr/doc:/usr/man:/usr/info:/usr/X11R6/man

#

Path to scripts to autogenerate package dependencies,

#

Note: Used iff _use_internal_dependency_generator is zero.

#%__find_provides %{_rpmconfigdir}/rpmdeps –provides
#%__find_requires %{_rpmconfigdir}/rpmdeps –requires
%__find_provides %{_rpmconfigdir}/find-provides
%__find_requires %{_rpmconfigdir}/find-requires
#%__find_conflicts ???
#%__find_obsoletes ???

Path to file attribute classifications for automatic dependency

extraction, used when _use_internal_dependency_generator

is used (on by default). Files can have any number of attributes

attached to them, and dependencies are separately extracted for

each attribute.

To define a new file attribute called “myattr”, add a file named

“myattr” to this directory, defining the requires and/or provides

finder script(s) + magic and/or path pattern regex(es).

provides finder and

%__myattr_requires path + args to requires finder script for

%__myattr_provides path + args to provides finder script for

%__myattr_magic libmagic classification match regex

%__myattr_path path based classification match regex

%__myattr_flags flags to control behavior (just “exeonly” for now)

%__myattr_exclude_magic exclude by magic regex

%__myattr_exclude_path exclude by path regex

#
%_fileattrsdir %{_rpmconfigdir}/fileattrs

#==============================================================================

—- Database configuration macros.

# Macros used to configure Berkley db parameters.
#

rpmdb macro configuration values are a colon (or white space) separated

list of tokens, with an optional ‘!’ negation to explicitly disable bit

values, or a “=value” if a parameter. A per-tag value is used (e.g.

%_dbi_config_Packages) if defined, otherwise a per-rpmdb default

(e.g. %_dbi_config).

#

Here’s a short list of the tokens, with a guess of whether the option is

useful:

# (nothing) currently used in rpm, known to work.
# “+++” under development, will be supported in rpm eventually.
# “???” I have no clue, you’re mostly on your own.
#

If you do find yourself inclined to fiddle, here’s what I see (shrug):

1) Only the value of mp_size has any serious impact on overall performance,

and you will need ~256Kb to handle a typical machine install.

2) Only the Packages hash, because of the size of the values (i.e. headers),

will ever need tuning. Diddle the pagesize if you’re interested, although

I believe that you will find pagesize=512 “best”.

3) Adding nofsync increases speed, but risks total data loss. Fiddle shared

and/or mp_size instead.

#

token works? Berkeley db flag or value

#==================================================
#———————- DBENV tunable values:

mmapsize=16Mb DBENV->set_mp_mmapsize

cachesize=1Mb DBENV->set_cachesize, DB->set_cachesize

#———————- DB->open bits:

nommap ??? DB_NOMMAP

#———————– rpmdb specific configuration:

lockdbfd (always on for Packages) Use fcntl(2) locking ?

nofsync Disable fsync(2) call performed after db3 writes?

#

Misc BDB tuning options

%__dbi_other mp_mmapsize=128Mb mp_size=1Mb

%_dbi_config %{?__dbi_other}

“Packages” should have shared/exclusive fcntl(2) lock using “lockdbfd”.

%_dbi_config_Packages %{?_dbi_config} lockdbfd

#==============================================================================

—- GPG/PGP/PGP5 signature macros.

# Macro(s) to hold the arguments passed to GPG/PGP for package
# signing and verification.
#
%__gpg_check_password_cmd %{__gpg} \
gpg –batch –no-verbose –passphrase-fd 3 -u “%{_gpg_name}” -so –

%__gpg_sign_cmd %{__gpg} \
gpg –batch –no-verbose –no-armor –passphrase-fd 3 \
%{?_gpg_digest_algo:–digest-algo %{_gpg_digest_algo}} \
–no-secmem-warning \
-u “%{_gpg_name}” -sbo %{__signature_filename} %{__plaintext_filename}

XXX rpm >= 4.1 verifies signatures internally

#%__gpg_verify_cmd %{__gpg} \
# gpg –batch –no-verbose –verify –no-secmem-warning \
# %{__signature_filename} %{__plaintext_filename}
#

XXX rpm-4.1 verifies prelinked libraries using a prelink undo helper.

# Normally this macro is defined in /etc/rpm/macros.prelink, installed
# with the prelink package. If the macro is undefined, then prelinked
# shared libraries contents are MD5 digest verified (as usual), rather
# than MD5 verifying the output of the prelink undo helper.
#
# Note: The 2nd token is used as argv[0] and “library” is a
# placeholder that will be deleted and replaced with the appropriate
# library file path.
#%__prelink_undo_cmd /usr/sbin/prelink prelink -y library

Horowitz Key Protocol server configuration

#
%_hkp_keyserver http://pgp.mit.edu
%_hkp_keyserver_query %{_hkp_keyserver}:11371/pks/lookup?op=get&search=0x

#==============================================================================

—- Transaction macros.

# Macro(s) used to parameterize transactions.
#
# The output binary package file name template used when building
# binary packages.
#

XXX Note: escaped %% for use in headerSprintf()

%_build_name_fmt %%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm

# Verify digest/signature flags for various rpm modes:
# 0x30300 (_RPMVSF_NODIGESTS) –nohdrchk if set, don’t check digest(s)
# 0xc0c00 (_RPMVSF_NOSIGNATURES) –nosignature if set, don’t check signature(s)
# 0xf0000 (_RPMVSF_NOPAYLOAD) –nolegacy if set, check header+payload (if possible)
# 0x00f00 (_RPMVSF_NOHEADER) –nohdrchk if set, don’t check rpmdb headers
#
# For example, the value 0xf0c00 (=0xf0000+0xc0c00) disables legacy
# digest/signature checking, disables signature checking, but attempts
# digest checking, also when retrieving headers from the database.
#
# You also can do:
# >>> hex(rpm._RPMVSF_NOSIGNATURES)
# ‘0xc0c00’
# or:
# >>> hex(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NOPAYLOAD)
# ‘0xf0c00’
# at the python prompt for example, after “import rpm”.
#
# The checking overhead is ~11ms per header for digests/signatures;
# each header from the database is checked only when first encountered
# for each database open.
#
# Note: the %_vsflags_erase applies to –upgrade/–freshen modes as
# well as –erase.
#
%__vsflags 0xf0000
%_vsflags_build %{__vsflags}
%_vsflags_erase %{__vsflags}
%_vsflags_install %{__vsflags}
%_vsflags_query %{__vsflags}
%_vsflags_rebuilddb 0xc0c00
%_vsflags_verify %{__vsflags}

#

Default output format string for rpm -qa

#

XXX Note: escaped %% for use in headerFormat()

%_query_all_fmt %%{nvra}

#

Default path to the file used for transaction fcntl lock.

%_rpmlock_path %{_dbpath}/.rpm.lock

#

ISA dependency marker, none for noarch and name-bitness for others

%_isa %{?__isa:(%{__isa})}%{!?__isa:%{nil}}

#

Define per-arch and per-os defaults. Normally overridden by per-target macros.

%__arch_install_post %{nil}
%__os_install_post %{___build_post}

Macro to fix broken permissions in sources

%_fixperms %{__chmod} -Rf a+rX,u+w,g-w,o-w

#==============================================================================

—- Scriptlet template templates.

# Global defaults used for building scriptlet templates.
#

%___build_shell %{?_buildshell:%{_buildshell}}%{!?_buildshell:/bin/sh}
%___build_args -e
%___build_cmd %{?_sudo:%{_sudo} }%{?_remsh:%{_remsh} %{_remhost} }%{?_remsudo:%{_remsudo} }%{?_remchroot:%{_remchroot} %{_remroot} }%{___build_shell} %{___build_args}
%___build_pre \
RPM_SOURCE_DIR=\”%{u2p:%{_sourcedir}}\”\
RPM_BUILD_DIR=\”%{u2p:%{_builddir}}\”\
RPM_OPT_FLAGS=\”%{optflags}\”\
RPM_LD_FLAGS=\”%{?__global_ldflags}\”\
RPM_ARCH=\”%{_arch}\”\
RPM_OS=\”%{_os}\”\
export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_LD_FLAGS RPM_ARCH RPM_OS\
RPM_DOC_DIR=\”%{_docdir}\”\
export RPM_DOC_DIR\
RPM_PACKAGE_NAME=\”%{name}\”\
RPM_PACKAGE_VERSION=\”%{version}\”\
RPM_PACKAGE_RELEASE=\”%{release}\”\
export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE\
LANG=C\
export LANG\
unset CDPATH DISPLAY ||:\
%{?buildroot:RPM_BUILD_ROOT=\”%{u2p:%{buildroot}}\”\
export RPM_BUILD_ROOT}\
%{?_javaclasspath:CLASSPATH=\”%{_javaclasspath}\”\
export CLASSPATH}\
PKG_CONFIG_PATH=\”${PKG_CONFIG_PATH}:%{_libdir}/pkgconfig:%{_datadir}/pkgconfig\”\
export PKG_CONFIG_PATH\
\
%{verbose:set -x}%{!verbose:exec > /dev/null}\
umask 022\
cd \”%{u2p:%{_builddir}}\”\

#%___build_body %{nil}
%___build_post exit 0

%___build_template #!%{___build_shell}\
%{___build_pre}\
%{nil}

#%{___build_body}\
#%{___build_post}\
#%{nil}

#==============================================================================

—- Scriptlet templates.

# Macro(s) that expand to a command and script that is executed.
# CAVEAT: All macro expansions must fit in a BUFSIZ (8192 byte) buffer.
#
%__spec_prep_shell %{___build_shell}
%__spec_prep_args %{___build_args}
%__spec_prep_cmd %{___build_cmd}
%__spec_prep_pre %{___build_pre}
%__spec_prep_body %{___build_body}
%__spec_prep_post %{___build_post}
%__spec_prep_template #!%{__spec_prep_shell}\
%{__spec_prep_pre}\
%{nil}

#%{__spec_prep_body}\
#%{__spec_prep_post}\
#%{nil}

%__spec_build_shell %{___build_shell}
%__spec_build_args %{___build_args}
%__spec_build_cmd %{___build_cmd}
%__spec_build_pre %{___build_pre}
%__spec_build_body %{___build_body}
%__spec_build_post %{___build_post}
%__spec_build_template #!%{__spec_build_shell}\
%{__spec_build_pre}\
%{nil}

#%{__spec_build_body}\
#%{__spec_build_post}\
#%{nil}

%__spec_install_shell %{___build_shell}
%__spec_install_args %{___build_args}
%__spec_install_cmd %{___build_cmd}
%__spec_install_pre %{___build_pre}
%__spec_install_body %{___build_body}
%__spec_install_post\
%{?__debug_package:%{__debug_install_post}}\
%{__arch_install_post}\
%{__os_install_post}\
%{nil}
%__spec_install_template #!%{__spec_install_shell}\
%{__spec_install_pre}\
%{nil}

#%{__spec_install_body}\
#%{__spec_install_post}\
#%{nil}

%__spec_check_shell %{___build_shell}
%__spec_check_args %{___build_args}
%__spec_check_cmd %{___build_cmd}
%__spec_check_pre %{___build_pre}
%__spec_check_body %{___build_body}
%__spec_check_post %{___build_post}
%__spec_check_template #!%{__spec_check_shell}\
%{__spec_check_pre}\
%{nil}

#%{__spec_check_body}\
#%{__spec_check_post}\
#%{nil}

#%__spec_autodep_shell %{___build_shell}
#%__spec_autodep_args %{___build_args}
#%__spec_autodep_cmd %{___build_cmd}
#%__spec_autodep_pre %{___build_pre}
#%__spec_autodep_body %{___build_body}
#%__spec_autodep_post %{___build_post}
#%__spec_autodep_template #!%{__spec_autodep_shell}\
#%{__spec_autodep_pre}\
#%{nil}

#%{__spec_autodep_body}\
#%{__spec_autodep_post}\
#%{nil}

%__spec_clean_shell %{___build_shell}
%__spec_clean_args %{___build_args}
%__spec_clean_cmd %{___build_cmd}
%__spec_clean_pre %{___build_pre}
%__spec_clean_body %{___build_body}
%__spec_clean_post %{___build_post}
%__spec_clean_template #!%{__spec_clean_shell}\
%{__spec_clean_pre}\
%{nil}

#%{__spec_clean_body}\
#%{__spec_clean_post}\
#%{nil}

%__spec_rmbuild_shell %{___build_shell}
%__spec_rmbuild_args %{___build_args}
%__spec_rmbuild_cmd %{___build_cmd}
%__spec_rmbuild_pre %{___build_pre}
%__spec_rmbuild_body %{___build_body}
%__spec_rmbuild_post %{___build_post}
%__spec_rmbuild_template #!%{__spec_rmbuild_shell}\
%{__spec_rmbuild_pre}\
%{nil}

#%{__spec_rmbuild_body}\
#%{__spec_rmbuild_post}\
#%{nil}

XXX We don’t expand pre/post install scriptlets (yet).

#%__spec_pre_pre %{nil}
#%__spec_pre_post %{nil}
#%__spec_post_pre %{nil}
#%__spec_post_post %{nil}
#%__spec_preun_pre %{nil}
#%__spec_preun_post %{nil}
#%__spec_postun_pre %{nil}
#%__spec_postun_post %{nil}
#%__spec_triggerpostun_pre %{nil}
#%__spec_triggerpostun_post %{nil}
#%__spec_triggerun_pre %{nil}
#%__spec_triggerun_post %{nil}
#%__spec_triggerin_pre %{nil}
#%__spec_triggerin_post %{nil}

#==============================================================================

—- configure macros.

# Macro(s) slavishly copied from autoconf’s config.status.
#
%_prefix /usr
%_exec_prefix %{_prefix}
%_bindir %{_exec_prefix}/bin
%_sbindir %{_exec_prefix}/sbin
%_libexecdir %{_exec_prefix}/libexec
%_datadir %{_prefix}/share
%_sysconfdir /etc
%_sharedstatedir %{_prefix}/com
%_localstatedir %{_prefix}/var
%_lib lib
%_libdir %{_exec_prefix}/%{_lib}
%_includedir %{_prefix}/include
%_infodir %{_datadir}/info
%_mandir %{_datadir}/man

#==============================================================================

—- config.guess platform macros.

# Macro(s) similar to the tokens used by configure.
#
%_build %{_host}
%_build_alias %{_host_alias}
%_build_cpu %{_host_cpu}
%_build_vendor %{_host_vendor}
%_build_os %{_host_os}
%_host x86_64-redhat-linux-gnu
%_host_alias x86_64-redhat-linux-gnu%{nil}
%_host_cpu x86_64
%_host_vendor redhat
%_host_os linux
%_target %{_host}
%_target_alias %{_host_alias}
%_target_cpu %{_host_cpu}
%_target_vendor %{_host_vendor}
%_target_os %{_host_os}

#==============================================================================

—- specfile macros.

# Macro(s) here can be used reliably for reproducible builds.
# (Note: Above is the goal, below are the macros under development)
#

The configure macro runs autoconf configure script with platform specific

directory structure (–prefix, –libdir etc) and compiler flags

such as CFLAGS.

#

The configure macro should be invoked as %configure (rather than %{configure})

because the rest of the arguments will be expanded using %*.

#
%_configure ./configure
%configure \
CFLAGS=”${CFLAGS:-%optflags}” ; export CFLAGS ; \
CXXFLAGS=”${CXXFLAGS:-%optflags}” ; export CXXFLAGS ; \
FFLAGS=”${FFLAGS:-%optflags}” ; export FFLAGS ; \
%{_configure} –host=%{_host} –build=%{_build} \\
–program-prefix=%{?_program_prefix} \\
–disable-dependency-tracking \\
–prefix=%{_prefix} \\
–exec-prefix=%{_exec_prefix} \\
–bindir=%{_bindir} \\
–sbindir=%{_sbindir} \\
–sysconfdir=%{_sysconfdir} \\
–datadir=%{_datadir} \\
–includedir=%{_includedir} \\
–libdir=%{_libdir} \\
–libexecdir=%{_libexecdir} \\
–localstatedir=%{_localstatedir} \\
–sharedstatedir=%{_sharedstatedir} \\
–mandir=%{_mandir} \\
–infodir=%{_infodir}

#——————————————————————————

The “make” analogue, hiding the _smp_mflags magic from specs

%make_build %{__make} %{?_smp_mflags}

#——————————————————————————

The make install analogue of %configure for modern autotools:

%make_install %{__make} install DESTDIR=%{?buildroot}

#——————————————————————————

Former make install analogue, kept for compatibility and for old/broken

packages that don’t support DESTDIR properly.

%makeinstall \
%{__make} \\
prefix=%{?buildroot:%{buildroot}}%{_prefix} \\
exec_prefix=%{?buildroot:%{buildroot}}%{_exec_prefix} \\
bindir=%{?buildroot:%{buildroot}}%{_bindir} \\
sbindir=%{?buildroot:%{buildroot}}%{_sbindir} \\
sysconfdir=%{?buildroot:%{buildroot}}%{_sysconfdir} \\
datadir=%{?buildroot:%{buildroot}}%{_datadir} \\
includedir=%{?buildroot:%{buildroot}}%{_includedir} \\
libdir=%{?buildroot:%{buildroot}}%{_libdir} \\
libexecdir=%{?buildroot:%{buildroot}}%{_libexecdir} \\
localstatedir=%{?buildroot:%{buildroot}}%{_localstatedir} \\
sharedstatedir=%{?buildroot:%{buildroot}}%{_sharedstatedir} \\
mandir=%{?buildroot:%{buildroot}}%{_mandir} \\
infodir=%{?buildroot:%{buildroot}}%{_infodir} \\
install

#——————————————————————————

The GNUconfigure macro does the following:

update config.guess and config.sub.

regenerate all autoconf/automake files

optionally change to a directory (make the directory if requested).

run configure with correct prefix, platform, and CFLAGS.

optionally restore current directory.

#

Based on autogen.sh from GNOME and original GNUconfigure

#
%GNUconfigure(MCs:) \
CFLAGS=”${CFLAGS:-%optflags}” ; export CFLAGS; \
LDFLAGS=”${LDFLAGS:-%{-s:-s}}” ; export LDFLAGS; \
%{-C:_mydir=”`pwd`”; %{-M: %{__mkdir} -p %{-C*};} cd %{-C*}} \
dirs=”`find ${_mydir} -name configure.in -print`”; export dirs; \
for coin in `echo ${dirs}` \
do \
dr=`dirname ${coin}`; \
if test -f ${dr}/NO-AUTO-GEN; then \

\
else \
macrodirs=sed -n -e 's,AM_ACLOCAL_INCLUDE(\(.*\)),\1,gp' < ${coin}; \
( cd ${dr}; \
aclocalinclude=”${ACLOCAL_FLAGS}”; \
for k in ${macrodirs}; do \
if test -d ${k}; then \
aclocalinclude=”${aclocalinclude} -I ${k}”; \
##else \
## echo “Warning: No such directory `${k}’. Ignored.” \
fi \
done \
if grep “^AM_GNU_GETTEXT” configure.in >/dev/null; then \
if grep “sed.*POTFILES” configure.in >/dev/null; then \
: do nothing — we still have an old unmodified configure.in \
else \
test -r ${dr}/aclocal.m4 || touch ${dr}/aclocal.m4; \
echo “no” | gettextize –force –copy; \
test -r ${dr}/aclocal.m4 && %{__chmod} u+w ${dr}/aclocal.m4; \
fi \
fi \
if grep “^AM_PROG_LIBTOOL” configure.in >/dev/null; then \
%{__libtoolize} –force –copy; \
fi \
aclocal ${aclocalinclude}; \
if grep “^AM_CONFIG_HEADER” configure.in >/dev/null; then \
%{__autoheader}; \
fi \
echo “Running automake –gnu ${am_opt} …”; \
%{__automake} –add-missing –gnu ${am_opt}; \
%{__autoconf}; \
); \
fi \
done \
%{-C:${_mydir}}%{!-C:.}/configure –prefix=%{_prefix} –exec-prefix=%{_exec_prefix} –bindir=%{_bindir} –sbindir=%{_sbindir} –sysconfdir=%{_sysconfdir} –datadir=%{_datadir} –includedir=%{_includedir} –libdir=%{_libdir} –libexecdir=%{_libexecdir} –localstatedir=%{_localstatedir} –sharedstatedir=%{_sharedstatedir} –mandir=%{_mandir} –infodir=%{_infodir} %* ; \
%{-C:cd ${_mydir}; unset _mydir}

%patches %{lua: for i, p in ipairs(patches) do print(p..” “) end}
%sources %{lua: for i, s in ipairs(sources) do print(s..” “) end}

#——————————————————————————

Useful perl macros (from Artur Frysiak wiget@t17.ds.pwr.wroc.pl)

#

For example, these can be used as (from ImageMagick.spec from PLD site)

# […]
# BuildPrereq: perl
# […]
# %package perl
# Summary: libraries and modules for access to ImageMagick from perl
# Group: Development/Languages/Perl
# Requires: %{name} = %{version}
# %requires_eq perl
# […]
# %install
# rm -fr $RPM_BUILD_ROOT
# install -d $RPM_BUILD_ROOT/%{perl_sitearch}
# […]
# %files perl
# %defattr(644,root,root,755)
# %{perl_sitearch}/Image
# %dir %{perl_sitearch}/auto/Image
#
%requires_eq() %(LC_ALL=”C” echo ‘%*’ | xargs -r rpm -q –qf ‘Requires: %%{name} = %%{epoch}:%%{version}\n’ | sed -e ‘s/ (none):/ /’ -e ‘s/ 0:/ /’ | grep -v “is not”)
%perl_sitearch %(eval “%{__perl} -V:installsitearch“; echo $installsitearch)
%perl_sitelib %(eval “%{__perl} -V:installsitelib“; echo $installsitelib)
%perl_vendorarch %(eval “%{__perl} -V:installvendorarch“; echo $installvendorarch)
%perl_vendorlib %(eval “%{__perl} -V:installvendorlib“; echo $installvendorlib)
%perl_archlib %(eval “%{__perl} -V:installarchlib“; echo $installarchlib)
%perl_privlib %(eval “%{__perl} -V:installprivlib“; echo $installprivlib)

#——————————————————————————

Useful python macros for determining python version and paths

#
%python_sitelib %(%{__python} -c “from distutils.sysconfig import get_python_lib; import sys; sys.stdout.write(get_python_lib())”)
%python_sitearch %(%{__python} -c “from distutils.sysconfig import get_python_lib; import sys; sys.stdout.write(get_python_lib(1))”)
%python_version %(%{__python} -c “import sys; sys.stdout.write(sys.version[:3])”)

#——————————————————————————

arch macro for all Intel i?86 compatibile processors

(Note: This macro (and it’s analogues) will probably be obsoleted when

rpm can use regular expressions against target platforms in macro

conditionals.

#
%ix86 i386 i486 i586 i686 pentium3 pentium4 athlon geode

#——————————————————————————

arch macro for all supported ARM processors

%arm armv3l armv4b armv4l armv4tl armv5tel armv5tejl armv6l armv7l armv7hl armv7hnl

#——————————————————————————

arch macro for all supported Sparc processors

%sparc sparc sparcv8 sparcv9 sparcv9v sparc64 sparc64v

#——————————————————————————

arch macro for all supported Alpha processors

%alpha alpha alphaev56 alphaev6 alphaev67

#——————————————————————————

arch macro for all supported PowerPC 64 processors

%power64 ppc64 ppc64p7 ppc64le

#————————————————————————

Use in %install to generate locale specific file lists. For example,

#

%install

%find_lang %{name}

%files -f %{name}.lang

#
%find_lang %{_rpmconfigdir}/find-lang.sh %{buildroot}

Commands + opts to use for retrieving remote files

Proxy opts can be set through –httpproxy/–httpport popt aliases,

for any special local needs use %__urlhelper_localopts in system-wide

or per-user macro configuration.

%__urlhelpercmd /usr/bin/curl
%__urlhelperopts –silent –show-error –fail –globoff –location -o
%__urlhelper_proxyopts %{?_httpproxy:–proxy %{_httpproxy}%{?_httpport::%{_httpport}}}%{!?_httpproxy:%{nil}}
%_urlhelper %{__urlhelpercmd} %{?__urlhelper_localopts} %{?__urlhelper_proxyopts} %{__urlhelperopts}

#——————————————————————————

Collection specific macros

%__plugindir %{_libdir}/rpm-plugins

%__collection_font %{__plugindir}/exec.so /usr/bin/fc-cache

%__collection_java %{__plugindir}/exec.so /usr/bin/rebuild-gcj-db

%__collection_sepolicy %{__plugindir}/sepolicy.so

%__collection_sepolicy_flags 1

Transaction plugin macros

%__transaction_systemd_inhibit %{__plugindir}/systemd_inhibit.so

#——————————————————————————

Macros for further automated spec %setup and patch application

default to plain patch

%__scm patch

meh, figure something saner

%__scm_username rpm-build
%__scm_usermail
%__scm_author %{__scm_username} %{__scm_usermail}

Plain patch (-m is unused)

%__scm_setup_patch(q) %{nil}
%__scm_apply_patch(qp:m:)\
%{__patch} %{-p:-p%{-p*}} %{-q:-s}

Mercurial (aka hg)

%__scm_setup_hg(q)\
%{__hg} init %{-q} .\
%{__hg} add %{-q} .\
%{__hg} commit %{-q} –user “%{__scm_author}” -m “%{name}-%{version} base”

%__scm_apply_hg(qp:m:)\
%{__hg} import – %{-p:-p%{-p}} %{-q} -m %{-m} –user “%{__scm_author}”

Git

%__scm_setup_git(q)\
%{__git} init %{-q}\
%{__git} config user.name “%{__scm_username}”\
%{__git} config user.email “%{__scm_usermail}”\
%{__git} add .\
%{__git} commit %{-q} -a\\
–author “%{__scm_author}” -m “%{name}-%{version} base”

%__scm_apply_git(qp:m:)\
%{__git} apply –index %{-p:-p%{-p}} -\
%{__git} commit %{-q} -m %{-m
} –author “%{__scm_author}”

Git, using “git am” (-m is unused)

%__scm_setup_git_am(q)\
%{expand:%__scm_setup_git %{-q}}

%__scm_apply_git_am(qp:m:)\
%{__git} am %{-q} %{-p:-p%{-p*}}

Quilt

%__scm_setup_quilt(q) %{nil}
%__scm_apply_quilt(qp:m:)\
%{__quilt} import %{-p:-p%{-p*}} %{1} && %{__quilt} push

Bzr

%__scm_setup_bzr(q)\
%{__bzr} init %{-q}\
%{__bzr} whoami –branch “%{__scm_author}”\
%{__bzr} add .\
%{__bzr} commit %{-q} -m “%{name}-%{version} base”

bzr doesn’t seem to have its own command to apply patches?

%__scm_apply_bzr(qp:m:)\
%{__patch} %{-p:-p%{-p}} %{-q:-s}\
%{__bzr} commit %{-q} -m %{-m
}

Single patch application

%apply_patch(qp:m:)\
%{uncompress:%{1}} | %{expand:%__scm_apply_%{__scm} %{-q} %{-p:-p%{-p}} %{-m:-m%{-m}}}

Automatically apply all patches

%autopatch(vp:)\
%{lua:\
local options = rpm.expand(“%{!-v:-q} %{-p:-p%{-p*}} “)\
for i, p in ipairs(patches) do\
print(rpm.expand(“%apply_patch -m %{basename:”..p..”} “..options..p..”\n”))\
end}

One macro to (optionally) do it all.

-S Sets the used patch application style, eg ‘-S git’ enables

usage of git repository and per-patch commits.

-N Disable automatic patch application

-p Use -p for patch application

%autosetup(a:b:cDn:TvNS:p:)\
%setup %{-a} %{-b} %{-c} %{-D} %{-n} %{-T} %{!-v:-q}\
%{-S:%global __scm %{-S}}\
%{-S:%{expand:%__scm_setup_%{-S
} %{!-v:-q}}}\
%{!-N:%autopatch %{-v} %{-p:-p%{-p*}}}

\endverbatim

#*/

Posted in DEVOPS | rpm 宏定义文档已关闭评论

rpm 宏定义

http://cholla.mmto.org/computers/linux/rpm/dotrpmmacros.html

Custom RPM macros configuration file for building RPM packages

as a non-root user.

#

Author: Mike A. Harris

#

This is a copy of my own personal RPM configuration which I use

on my workstation for building and testing packages for Red Hat Linux.

There are many different possibilities on how to configure RPM, so

feel free to tweak however you desire. Make sure to create any

directories that are referenced prior to using. RPM will automatically

create some of them if missing, but not all of them. Which ones it

auto-creates is only known by the extraterrestrial aliens that have

created RPM.

#

For ANY help with anything related to RPM development, packaging,

or customization, please join the Red Hat RPM mailing list by sending

an email message to: rpm-list-request@redhat.com with the word

"subscribe" in the Subject: line.

#

Any suggestions/comments/ for improvements to this setup appreciated.

%_signature gpg
%_gpg_name T. E. Pickering

%_topdir defines the top directory to be used for RPM building purposes

By defaultROOT of the buildsystem

%_topdir %(echo $HOME)/rpmbuild

%_sourcedir is where the source code tarballs, patches, etc. will be

placed after you do an "rpm -ivh somepackage.1.0-1.src.rpm"

#%_sourcedir %{_topdir}/SOURCES/cpan
%_sourcedir %{_topdir}/SOURCES/%{name}-%{version}

%_specdir is where the specfile gets placed when installing a src.rpm. I

prefer the specfile to be in the same directory as the source tarballs, etc.

%_specdir %{_sourcedir}

%_tmppath is where temporary scripts are placed during the RPM build

process as well as the %_buildroot where %install normally dumps files

prior to packaging up the final binary RPM's.

%_tmppath %{_topdir}/tmp

%_builddir is where source code tarballs are decompressed, and patches then

applied when building an RPM package

%_builddir %{_topdir}/BUILD

%_buildroot is where files get placed during the %install section of spec

file processing prior to final packaging into rpms. This is oddly named

and probably should have been called "%_installroot" back when it was

initially added to RPM. Alas, it was not. ;o)

%_buildroot %{_tmppath}/%{name}-%{version}-root

%_rpmdir is where binary RPM packages are put after being built.

%_rpmdir %{_topdir}/RPMS

%_srcrpmdir is where src.rpm packages are put after being built.

%_srcrpmdir %{_topdir}/SRPMS

%_rpmfilename defines the naming convention of the produced RPM packages,

and should not be modified. It is listed here because I am overriding

RPM's default behaviour of dropping binary RPM's each in their own

separate subdirectories. I hate that. Grrr.

%_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm

Customized tags for local builds

%packager is the info that will appear in the "Packager:" field in the

RPM header on built packages. By default I have it read your username

and hostname. This should be customized appropriately.

%packager Joe Blow

%packager T. E. Pickering
%distribution The MMTO RPM Shack

GNU GPG config below

#%_signature gpg
#%_gpg_name Joe Blow
#%_gpg_path %(echo $HOME)/.gnupg

The following will try to create any missing directories required above

(Not implemented yet)

Posted in 系统管理 | rpm 宏定义已关闭评论

suse 上apache 启用 module_headers 并配置 cache-control

启用 headers_moule

在 centos 配置比较简单,只需要 loadmodules 即可:

cat /etc/httpd/conf.modules.d/00-base.conf | grep headers
LoadModule headers_module modules/mod_headers.so

但在 suse 上,却是通过 sysconfig 来配置的:


cat /etc/sysconfig/apache2 | grep MODULES | grep -v "^#"
APACHE_MODULES="actions alias auth_basic authn_core authn_file authz_core authz_groupfile authz_host authz_user autoindex cgi dir env expires include log_config mime negotiation perl reqtimeout setenvif socache_shmcb ssl userdir headers"

需要编辑这行内容,并且如果 /usr/lib64/apache2 下有 so 文件即可。查看模块方式如下:

/usr/sbin/apache2ctl -t -D DUMP_MODULES | grep shared
AH00557: httpd-prefork: apr_sockaddr_info_get() failed for mirrors
AH00558: httpd-prefork: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
actions_module (shared)
alias_module (shared)
auth_basic_module (shared)
authn_core_module (shared)
authn_file_module (shared)
authz_core_module (shared)
authz_groupfile_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
cgi_module (shared)
dir_module (shared)
env_module (shared)
expires_module (shared)
include_module (shared)
log_config_module (shared)
mime_module (shared)
negotiation_module (shared)
perl_module (shared)
reqtimeout_module (shared)
setenvif_module (shared)
socache_shmcb_module (shared)
ssl_module (shared)
userdir_module (shared)
headers_module (shared)

其中静态和动态加载的都显示出来了。

## 配置header中的cache-control

比如其中的一个配置为:


PerlRequire "/etc/apache2/smt-mod_perl-startup.pl"

Alias "/SUSE" "/srv/www/htdocs/repo/SUSE"
Alias repo "/srv/www/htdocs/repo"

<Directory "/srv/www/htdocs/repo">
    Options +Indexes +FollowSymLinks
    IndexOptions +NameWidth=*
    PerlAuthenHandler NU::SMTAuth
    AuthName SMTAuth
    AuthType Basic
    Require valid-user

    <IfModule mod_headers.c>
            Header set Via "host-name"
            Header set Cache-Control "max-age=43200"
            <FilesMatch "\.(xml|xm_|gz|sh|conf|tar|repo|bz2)$">
                    Header set Cache-Control "max-age=300"
            </FilesMatch>
    </IfModule>

    # Allow unauthenticated access to /repo/tools/ directory
    Require expr %{REQUEST_URI} =~ m#^/repo/tools/.*#
</Directory>



设置了两个 header, 并且根据文件后缀来设置不同的值。

验证效果

xml 文件


curl -I http://localhost/repo/SUSE/Updates/SLE-SAP/12-SP2/x86_64/update/repodata/repomd.xml
HTTP/1.1 200 OK
Date: Thu, 27 Sep 2018 03:41:23 GMT
Server: Apache
Last-Modified: Tue, 25 Sep 2018 16:06:01 GMT
ETag: "c22-576b448324c40"
Accept-Ranges: bytes
Content-Length: 3106
Via: smt-root-b
Cache-Control: max-age=300
Content-Type: text/xml

其他文件


curl -I http://localhost/repo/SUSE/Updates/SLE-SAP/12-SP2/x86_64/update/x86_64/MozillaFirefox-52.8.0esr-109.31.2.x86_64.rpm
HTTP/1.1 200 OK
Date: Thu, 27 Sep 2018 03:41:01 GMT
Server: Apache
Last-Modified: Fri, 18 May 2018 06:05:07 GMT
ETag: "2bfe4cd-56c74bbd72ac0"
Accept-Ranges: bytes
Content-Length: 46130381
Via: smt-root-b
Cache-Control: max-age=43200
Content-Type: application/x-rpm

Posted in web和容器 | suse 上apache 启用 module_headers 并配置 cache-control已关闭评论
« Older