Browse code

Add -b (batch) flag for run under cron

I've patched aptly in order to add --no-tty flag to gpg.
Now repo-create.sh works perfectly when executed via cron.

I think you need aptly version >=0.9
Or just check whether your aptly version has '-batch=false/true' flag.

Dmitrii Kashin authored on 10/10/2014 00:45:56
Showing 3 changed files
... ...
@@ -2,8 +2,9 @@
2 2
 * Issues & wishes
3 3
 ** TODO omitting flag -g cause problems with signing.
4 4
    aptly supports unsigned repos, shall I use it in this case?
5
-** TODO gpg in cron doesn't work
5
+** DONE gpg in cron doesn't work
6 6
    Signing file 'Release' with gpg, please enter your passphrase when prompted:
7 7
    gpg: cannot open tty `/dev/tty': Нет такого устройства или адреса
8 8
    ERROR: unable to publish: unable to detached sign file: exit status 2
9
-
9
+   
10
+   I've patched aptly for this: 59055d7fbddba4ea18b59ef4bdda601d4ebee278
10 11
deleted file mode 100644
... ...
@@ -1,3 +0,0 @@
1
-2014-10-07
2
-	Создал начальную версию. Настраиваю репозиторий.
3
-	
... ...
@@ -29,6 +29,7 @@ repo-update.sh [-d] [-g <gpg-key-passphrase>] [-l <log-file>] <action>
29 29
 -g	Set a passphrase for your gpg key (it can be useful if you run script
30 30
         with cron.
31 31
 -l	File to store log. Type '-' for output to screen.
32
+-b	Batch mode (not to use tty)
32 33
 
33 34
 Action could be one of:
34 35
 update	update mirrors and publications
... ...
@@ -44,12 +45,14 @@ DATE=`date +%F-%T`
44 44
 SUFFIX="$DATE"
45 45
 GPG_PASSWD=""
46 46
 DEBUG=0
47
+BATCH=""
47 48
 
48 49
 ## Configuration:
49
-while getopts hdg:l: option
50
+while getopts hdbg:l: option
50 51
 do
51 52
     case "$option" in
52 53
         d) DEBUG=1;;
54
+	b) BATCH='-batch=true';;
53 55
         g) GPG_PASSWD="$OPTARG";;
54 56
 	l) LOGFILE="$OPTARG";;
55 57
 	h) usage; exit 0;;
... ...
@@ -145,7 +148,7 @@ cmd_create_publications () {
145 145
 cmd_update_publications () {
146 146
     logger "RUN: CMD_UPRATE_PUBLICATIONS"
147 147
     # check here for available publications maybe?
148
-    CMD_UPRATE_PUBLICATIONS=$(aptly mirror list -raw | awk -F/ "{targets[\$1]=targets[\$1]\" \"\$2;} END{for (tar in targets) print tar, targets[tar];}" | awk "{release=\$1; comp=snapshots=\"\"; for(i=2; i<=NF; i++) {(comp!=\"\") ? comp=comp\",\"\$i : comp=\$i; snapshots=snapshots\" \"release\"/\"\$i\"-$SUFFIX\"}; print \"aptly publish switch -component=\"comp\" -passphrase=$GPG_PASSWD \"release\" \"snapshots\" $TO_LOGFILE;\"; }")
148
+    CMD_UPRATE_PUBLICATIONS=$(aptly mirror list -raw | awk -F/ "{targets[\$1]=targets[\$1]\" \"\$2;} END{for (tar in targets) print tar, targets[tar];}" | awk "{release=\$1; comp=snapshots=\"\"; for(i=2; i<=NF; i++) {(comp!=\"\") ? comp=comp\",\"\$i : comp=\$i; snapshots=snapshots\" \"release\"/\"\$i\"-$SUFFIX\"}; print \"aptly publish switch $BATCH -component=\"comp\" -passphrase=$GPG_PASSWD \"release\" \"snapshots\" $TO_LOGFILE;\"; }")
149 149
     run_command "$CMD_UPRATE_PUBLICATIONS"
150 150
 }
151 151