<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Linux Forum &mdash; Скрипт подписи пакетов]]></title>
	<link rel="self" href="https://linuxforum.ru/extern.php?action=feed&amp;tid=27797&amp;type=atom" />
	<updated>2013-04-28T09:10:38Z</updated>
	<generator>PunBB</generator>
	<id>https://linuxforum.ru/viewtopic.php?id=27797</id>
		<entry>
			<title type="html"><![CDATA[Re: Скрипт подписи пакетов]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=342932#p342932" />
			<content type="html"><![CDATA[<p>Если не ошибаюсь, rpm сам не подписывает, а вызывает для подписи gpg. После освоения gpg накатал такой скриптик:<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>#!/bin/bash
# Sign the packages in a specified directory.
# Written by yars, Tambovskaya oblast, Russia.
# &lt;yars068@yandex.ru&gt;
# Copyright 2012. All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

checkgpg()
{
    gpg --verify $1
}

funcgpg()
{
    echo -n &quot;Enter passphrase: &quot;
    read pass
    for file in `find $1 -name &quot;*.txz&quot;` ; do
    echo &quot;Checking the signature of $file:&quot;
    if [ ! `checkgpg &quot;$file&quot; 2&gt;/dev/null` ] ; then 
        echo -n &quot;Signature not found. Signing up package: $file: &quot;
        gpg -ba --yes --no-tty --passphrase $pass $file 2&gt;/dev/null 1&gt;/dev/null &amp;&amp; echo &quot; Done.&quot;
    fi;
    done
}

# Checking for arguments are specified:
case $# in
    0) echo &quot;Usage: $0 path-to-directory&quot;
       exit 1;;
    *) funcgpg $1;;
esac</code></pre></div></div></div><p>Еще немного допилить надо, чуть позже выложу окончательный вариант <img src="https://linuxforum.ru/img/smilies/ab.gif" alt="ab" /><br />UPD: пока так:<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>#!/bin/bash
# Sign or verify the signatures of packages in a directory.
# Written by Yaroslav Shmelev, Tambovskaya oblast, Russia.
# aka yars &lt;yars068@yandex.ru&gt;
# Copyright 2012. All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

set -e

SIGTYPE=&quot;asc&quot;

checkgpg()
{
    if `gpg --verify  &quot;$1&quot; 2&gt;/dev/null` ;then
    return 0
    else
    return 1
    fi;
}

funcgpg()
{
    echo -n &quot;Enter passphrase: &quot;
    read -s pass
    echo &quot;Location of packages: $1.&quot;
    while read l ; do
    echo -n &quot;Checking the signature of $(basename &quot;$l&quot;)... &quot;
    if ! `checkgpg &quot;$l.$SIGTYPE&quot; 2&gt;/dev/null` ; then 
        echo &quot;Signature not found.&quot;
        echo -n &quot;Signing up package: $(basename &quot;$l&quot;)... &quot;
        gpg -ba --yes --no-tty --passphrase $pass &quot;$l&quot; 2&gt;/dev/null 1&gt;/dev/null &amp;&amp; echo &quot; Done.&quot;
    else
        echo &quot;Already signed. Skipping.&quot; 
    fi;
    done &lt; &lt;( find $1 -name &quot;*.txz&quot; )
}

# Checking for arguments are specified:
case $1 in
    --sign)  shift
         if [ -d $1 ]; then 
         funcgpg $1
         fi;;
    --check) shift
         if [ -d $1 ]; then 
            echo &quot;Location of packages is: $1.&quot;
            while read l; do
                echo -n &quot;Checking: $(basename &quot;$l&quot;)... &quot;
                if `checkgpg &quot;$l.$SIGTYPE&quot;` ; then 
                echo &quot; Signed&quot;
                else 
                echo &quot; Not signed.&quot;
            fi;
            done &lt; &lt;( find $1 -name &quot;*.txz&quot; );
         else
            echo &quot;$1 isn&#039;t directory. Exiting.&quot;
         fi;;
    *)          echo &quot;Usage: $0 --sign | --check path-to-directory&quot;
         exit 0;;
esac</code></pre></div></div></div><p>Наверное, тоже не самый оптимальный вариант, но он работает. Умеет проверять и подписывать пакеты...<br />Примеры:<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header"><strong>+</strong>&nbsp;подписываем</div><div class="fancy_spoiler"><div class="codebox"><pre><code>./signpackages.sh --sign soft/Linux/Packages/slackware-14.0/
Enter passphrase: 
Location of packages: soft/Linux/Packages/slackware-14.0/.
Checking the signature of gedit-3.4.2-i486-1_yars.txz... Signature not found.
Signing up package: gedit-3.4.2-i486-1_yars.txz...  Done.
Checking the signature of slim-1.3.4-i486-2_yars.txz... Signature not found.
Signing up package: slim-1.3.4-i486-2_yars.txz...  Done.
Checking the signature of network-manager-applet-0.9.8.0-i486-1_yars.txz... Signature not found.
Signing up package: network-manager-applet-0.9.8.0-i486-1_yars.txz...  Done.
Checking the signature of wxPython-2.8.12.1-i486-1_yars.txz... Signature not found.
Signing up package: wxPython-2.8.12.1-i486-1_yars.txz...  Done.
Checking the signature of MPlayer-1.0rc4-i486-1_yars.txz... Signature not found.
Signing up package: MPlayer-1.0rc4-i486-1_yars.txz...  Done.
Checking the signature of opera-12.00-i386-1_yars.txz... Signature not found.
Signing up package: opera-12.00-i386-1_yars.txz...  Done.
Checking the signature of flash-player-plugin-11.2_r270-i486-1_yars.txz... Signature not found.
Signing up package: flash-player-plugin-11.2_r270-i486-1_yars.txz...  Done.
Checking the signature of flash-player-plugin-11.2_r258-i486-1_yars.txz... Signature not found.
Signing up package: flash-player-plugin-11.2_r258-i486-1_yars.txz...  Done.
Checking the signature of opera-12.14-i386-1_yars.txz... Signature not found.
Signing up package: opera-12.14-i386-1_yars.txz...  Done.
Checking the signature of modem-manager-gui-0.0.15.4-i486-1_yars.txz... Signature not found.
Signing up package: modem-manager-gui-0.0.15.4-i486-1_yars.txz...  Done.
Checking the signature of xfce4-xkb-plugin-0.5.4.3-i486-1_yars.txz... Signature not found.
Signing up package: xfce4-xkb-plugin-0.5.4.3-i486-1_yars.txz...  Done.
Checking the signature of xfce4-genmon-plugin-3.4-i486-1_yars.txz... Signature not found.
Signing up package: xfce4-genmon-plugin-3.4-i486-1_yars.txz...  Done.
Checking the signature of xfce4-mailwatch-plugin-git20130427-i486-1_yars.txz... Signature not found.
Signing up package: xfce4-mailwatch-plugin-git20130427-i486-1_yars.txz...  Done.</code></pre></div></div></div><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header"><strong>+</strong>&nbsp;проверяем</div><div class="fancy_spoiler"><div class="codebox"><pre><code>./signpackages.sh --check soft/Linux/Packages/slackware-14.0/
Location of packages is: soft/Linux/Packages/slackware-14.0/.
Checking: gedit-3.4.2-i486-1_yars.txz...  Signed
Checking: slim-1.3.4-i486-2_yars.txz...  Signed
Checking: network-manager-applet-0.9.8.0-i486-1_yars.txz...  Signed
Checking: wxPython-2.8.12.1-i486-1_yars.txz...  Signed
Checking: MPlayer-1.0rc4-i486-1_yars.txz...  Signed
Checking: opera-12.00-i386-1_yars.txz...  Signed
Checking: flash-player-plugin-11.2_r270-i486-1_yars.txz...  Signed
Checking: flash-player-plugin-11.2_r258-i486-1_yars.txz...  Signed
Checking: opera-12.14-i386-1_yars.txz...  Signed
Checking: modem-manager-gui-0.0.15.4-i486-1_yars.txz...  Signed
Checking: xfce4-xkb-plugin-0.5.4.3-i486-1_yars.txz...  Signed
Checking: xfce4-genmon-plugin-3.4-i486-1_yars.txz...  Signed
Checking: xfce4-mailwatch-plugin-git20130427-i486-1_yars.txz...  Signed</code></pre></div></div></div>]]></content>
			<author>
				<name><![CDATA[yars]]></name>
				<uri>https://linuxforum.ru/profile.php?id=22799</uri>
			</author>
			<updated>2013-04-28T09:10:38Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=342932#p342932</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Скрипт подписи пакетов]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=340328#p340328" />
			<content type="html"><![CDATA[<p>На всякий случай: нашёл у себя, как когда-то вводил пароль по запросу скрипта:<br /></p><div class="codebox"><pre><code>#!/bin/bash

/bin/echo -n -e &quot;Enter password 9: .........\b\b\b\b\b\b\b\b\b&quot;
read pssw
export pssw
echo $pssw</code></pre></div><p>Пётр.</p>]]></content>
			<author>
				<name><![CDATA[Peter]]></name>
				<uri>https://linuxforum.ru/profile.php?id=5246</uri>
			</author>
			<updated>2013-04-14T19:11:07Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=340328#p340328</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Скрипт подписи пакетов]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=340310#p340310" />
			<content type="html"><![CDATA[<p>Нормально, ИМХО. Я сам в bash не джедай <img src="https://linuxforum.ru/img/smilies/ab.gif" alt="ab" /></p>]]></content>
			<author>
				<name><![CDATA[yars]]></name>
				<uri>https://linuxforum.ru/profile.php?id=22799</uri>
			</author>
			<updated>2013-04-14T17:21:05Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=340310#p340310</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Скрипт подписи пакетов]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=340301#p340301" />
			<content type="html"><![CDATA[<p>Сделал проверку на подпись. Не криво ли?<br /></p><div class="codebox"><pre><code>#!/bin/bash

rep_i586=&quot;/var/www/html/packages.mageialinux.ru/mageia2/RPMS/i586/&quot;
spisok_i586=`ls ${rep_i586}`;
pass=&quot; &quot;


for rpmpkg586 in `echo $spisok_i586`
do
if  rpm --checksig $rep_i586$rpmpkg586
then
#               echo &quot;Есть подпись!&quot;
        echo $rpmpkg586 &gt;&gt; pkg_sig.log
else   
        echo &quot;Нет подписи!&quot;
        echo $rpmpkg586 &gt;&gt; pkg_no_sig.log
        /usr/bin/expect &lt;&lt; EOF
                spawn rpm --addsign $rep_i586$rpmpkg586
                expect &quot;Введите ключевую фразу: &quot; { send &quot; \n&quot; }
                expect &quot;# &quot; { send &quot;q&quot; }
                exit
EOF
fi
done</code></pre></div>]]></content>
			<author>
				<name><![CDATA[XliN]]></name>
				<uri>https://linuxforum.ru/profile.php?id=6412</uri>
			</author>
			<updated>2013-04-14T16:27:20Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=340301#p340301</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Скрипт подписи пакетов]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=340298#p340298" />
			<content type="html"><![CDATA[<p>Вот так он отрабатывает<br /></p><div class="codebox"><pre><code>spawn rpm --addsign /root/key/bmpanel2-2.1pre1-1.mrc.mga2.i586.rpm
Введите ключевую фразу: 
Ключевая фраза принята.
/root/key/bmpanel2-2.1pre1-1.mrc.mga2.i586.rpm:
предупреждение: /root/key/bmpanel2-2.1pre1-1.mrc.mga2.i586.rpm already contains identical signature, skipping
spawn rpm --addsign /root/key/bmpanel2-debug-2.1pre1-1.mrc.mga2.i586.rpm
Введите ключевую фразу: 
Ключевая фраза принята.
/root/key/bmpanel2-debug-2.1pre1-1.mrc.mga2.i586.rpm:
предупреждение: /root/key/bmpanel2-debug-2.1pre1-1.mrc.mga2.i586.rpm already contains identical signature, skipping
spawn rpm --addsign /root/key/key.sh
Введите ключевую фразу: 
Ключевая фраза принята.
/root/key/key.sh:
ошибка: /root/key/key.sh: not an rpm package</code></pre></div>]]></content>
			<author>
				<name><![CDATA[XliN]]></name>
				<uri>https://linuxforum.ru/profile.php?id=6412</uri>
			</author>
			<updated>2013-04-14T15:42:18Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=340298#p340298</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Скрипт подписи пакетов]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=340297#p340297" />
			<content type="html"><![CDATA[<p><strong>yars</strong>, <br />Проблема в том что rpm --addsign спрашивает ключевую фразу сразу после отработки. Из-за него и пришлось использовать expect.</p><p>Собственно скрипт рабочий. Хоть и для каждого пакета вводится пустой пароль, главное что в автомате. Подскажи как мне на него напустить именно те пакеты которые еще не подписаны?</p>]]></content>
			<author>
				<name><![CDATA[XliN]]></name>
				<uri>https://linuxforum.ru/profile.php?id=6412</uri>
			</author>
			<updated>2013-04-14T15:36:35Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=340297#p340297</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Скрипт подписи пакетов]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=340296#p340296" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>XliN пишет:</cite><blockquote><p>Да и пароль пустой.</p></blockquote></div><p>Это rpm требует пароль? (немного непонятно, зачем тогда его спрашивать, если он пустой)<br />Ок, тогда чуток попозже -- нужно накатить что-нибудь rpm-based, чтобы отладить скрипт. <br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><p>P.S. В Интернете я не так чтобы уж совсем щепетильно отношусь к обращению «ты»/«вы», так что можете ко мне и на «ты», да и вроде бы в одной команде работаем&nbsp; <img src="https://linuxforum.ru/img/smilies/ah.gif" alt="ah" /></p></div></div>]]></content>
			<author>
				<name><![CDATA[yars]]></name>
				<uri>https://linuxforum.ru/profile.php?id=22799</uri>
			</author>
			<updated>2013-04-14T15:28:53Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=340296#p340296</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Скрипт подписи пакетов]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=340293#p340293" />
			<content type="html"><![CDATA[<p>Окей попробую. Но я не силен в баше, хотя сделать точно надо. Буду стараться. Если что надеюсь на помощь форума. А может подскажите, пример кинете, как сделать? Понимаю что не айс просьба ))) Но все же.</p><p>Да и пароль пустой.</p>]]></content>
			<author>
				<name><![CDATA[XliN]]></name>
				<uri>https://linuxforum.ru/profile.php?id=6412</uri>
			</author>
			<updated>2013-04-14T14:53:54Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=340293#p340293</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Скрипт подписи пакетов]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=340292#p340292" />
			<content type="html"><![CDATA[<p>Вынеси запрос на ввод пароля из функции, запомни пароль в переменную, да и дело с концом. И там, где надо, подставляй. А перед началом процесса подписывания пройдись по списку циклом с rpm --checksig, и на основе этого формируй список неподписанных пакетов, который и скармливай функциям подписывания...</p>]]></content>
			<author>
				<name><![CDATA[yars]]></name>
				<uri>https://linuxforum.ru/profile.php?id=22799</uri>
			</author>
			<updated>2013-04-14T14:26:21Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=340292#p340292</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Скрипт подписи пакетов]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=340272#p340272" />
			<content type="html"><![CDATA[<p>Есть кривой скрипт. Сам писал. Как бы его улучшить, что бы он подписывал сразу все пакеты, а не спрашивал пароль для каждого пакета?<br />Еще хочется что бы была проверка уже подписанных пакетов и подписывать только новые. Поможете? <br /></p><div class="codebox"><pre><code>#!/bin/bash

rep_i586=&quot;/var/www/html/packages.mageialinux.ru/mageia2/RPMS/i586/&quot;
rep_x86_64=&quot;/var/www/html/packages.mageialinux.ru/mageia2/RPMS/x86_64/&quot;
spisok_i586=`ls ${rep_i586}`;
spisok_x64=`ls ${rep_x86_64}`;

function gpg_i586(){
for rpmpkg586 in `echo $spisok_i586`
do
/usr/bin/expect &lt;&lt; EOF
        spawn rpm --addsign $rep_i586$rpmpkg586
         expect &quot;Введите ключевую фразу: &quot; { send &quot; \n&quot; }
         expect &quot;# &quot; { send &quot;q&quot; }
        exit
EOF
done
}

function gpg_x86_64(){
for rpmpkg_x64 in `echo $spisok_x64`
do
/usr/bin/expect &lt;&lt; EOF
        spawn rpm --addsign $rep_x86_64$rpmpkg_x64
         expect &quot;Введите ключевую фразу: &quot; { send &quot; \n&quot; }
         expect &quot;# &quot; { send &quot;q&quot; }
        exit
EOF
done
}

gpg_i586
gpg_x86_64</code></pre></div>]]></content>
			<author>
				<name><![CDATA[XliN]]></name>
				<uri>https://linuxforum.ru/profile.php?id=6412</uri>
			</author>
			<updated>2013-04-14T10:23:49Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=340272#p340272</id>
		</entry>
</feed>
