File: prepare_missing_cran_package

package info (click to toggle)
dh-r 20210303
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 224 kB
  • sloc: perl: 1,935; sh: 393; makefile: 21
file content (252 lines) | stat: -rwxr-xr-x 8,379 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/bin/sh -e

show_usage () {
  echo "Usage: `basename $0` <package_name>"
  echo
  echo "`basename $0` searches the CRAN and BioConductor repositories for package with the exact name given as a single argument. It will download, unpack, and prepare all the Debian packaging for the requested packages and all those dependencies that are not yet shipping with Debian."
}

if [ $# -ne 1 ] ; then
  show_usage
  exit 1
fi

if [ "$1" = "-h" -o "$1" = "--help" ] ; then
  show_usage
  exit 1
fi

if [ "$1" = "splines" ] ; then
  echo "I: Package $1 already ships with r-base-core."
  exit 0
fi

if [ "$1" = "stats4" ] ; then
  echo "I: Package $1 already ships with r-base-core."
  exit 0
fi

if ! (which $(basename $0) > /dev/null 2>&1); then
  echo "E: Extending PATH for $(dirname $0)"
  PATH=$PATH:$(dirname "$0")
fi

for tool in cme dh-make-R git
do
  p=$(which $tool||true)
  if [ "" = "$p" ]; then
    echo "E: Missing tool '$tool'"
    exit 1
  fi
done

do_wnpp_check () {
  retval=""
  wnpp=`wnpp-check $wnppname | sed 's/^(.* - #\([0-9]\+\)) http.*/\1/'`
  if [ "$wnpp" != "" ] ; then
    if which psql 2>/dev/null ; then
      newversion=`PGPASSWORD="udd-mirror" psql --port=5432 --host=udd-mirror.debian.net --username=udd-mirror -t udd -c "select version from new_packages where package = '$wnppname' ;"`
      if [ "$newversion" != "" ] ; then
        >&2 echo "W: Package $wnppname is just in Debian new queue waiting for processing"
        retval="new"
      else
        >&2 echo "W: Package $wnppname was ITPed in bug #$wnpp.  Please check http://bugs.debian.org/$wnpp"
        retval="$wnpp"
      fi
    else
      >&2 echo "W: Unable to check whether Package $wnppname is in new.  Please either install postgresql-client-common or inspect https://ftp-master.debian.org/new.html."
    fi
  fi
  echo $retval
}

cranname=$1
pkgname=""
workdir=`pwd`
for repository in bioc cran
do
  pkgname=r-${repository}-`echo $cranname | tr '[A-Z]' '[a-z]'`

  a=$(apt-cache show $pkgname|wc -l)
  if [ 0 -lt $a ]; then
    echo "$a"
    echo "I: Package $pkgname is already known - see 'apt-cache show $pkgname'."
    exit 0
  fi

  if apt-cache policy $pkgname | grep -v "(none)" | grep -q "Installed:" ; then
    echo "I: Package $pkgname is available. Try 'apt-cache policy $pkgname' to find its author."
    exit 0
  fi

  wnppname=$pkgname
  wnppcheck=$( do_wnpp_check )
  if [ "$wnppcheck" = "new" ] ; then
    echo "I: No point to deal with a package which is in new - exitting"
    exit 0
  else
    # If wnpp_check did not found r-cran-NAME try r-bioc
    if [ "$wnppcheck" = "" ] ; then
      wnppname="r-bioc-`echo $cranname | tr '[A-Z]' '[a-z]'`"
      wnppcheck=$( do_wnpp_check )
      if [ "$wnppcheck" = "new" ] ; then
        echo "I: No point to deal with a package which is in new - exitting"
        exit 0
      fi
    fi
  fi
done

if echo $workdir | grep -q CRAN_prospective ; then
  basedir=`echo $workdir | sed 's#\(CRAN_prospective\).*#\1#'`
else
  basedir=`dirname $workdir`/CRAN_prospective
fi
targetdir="$basedir/$pkgname"

for p in "`dirname ${targetdir}`/${cranname}/debian" "$targetdir"
do
  if [ -d "$p" ]; then
    echo "E: Previous packaging attempt for package $cranname exists in '$p'."
    exit 1
  fi
done

createdDirs=""
if [ ! -d "$targetdir" ]; then
  mkdir -p "$targetdir"/debian
  createdDirs="$targetdir"
elif [ ! -d "$targetdir"/debian ]; then
  mkdir $targetdir/debian
  createdDirs="$targetdir/debian"
fi
cd $targetdir

if [ "$DEBFULLNAME" != "" -a "$DEBEMAIL" != "" ] ; then
  AUTHOR="$DEBFULLNAME <${DEBEMAIL}>"
else
  AUTHOR="FIXME: DEBFULLNAME <DEBEMAIL> (you should set these variables in your environment)"
fi

cat > debian/changelog <<EOT
$pkgname (0.0-1) UNRELEASED; urgency=medium

  * Initial release

 -- $AUTHOR  `date -R`
EOT

cat > debian/watch <<EOT
version=4
https://cloud.r-project.org/src/contrib/${cranname}@ANY_VERSION@@ARCHIVE_EXT@
EOT

echo "I: Checking CRAN repository for ${cranname}"
tarball=`uscan --verbose 2>/dev/null | grep ".orig.tar.[gx]z" | sed 's#^.* \(\.\./.*\.orig\.tar\.[gx]z\).*#\1#'`
#echo "I: - testing for '$tarball'"

BIOCDATA=""
if [ "$tarball" = "" ] ; then
  # if nothing was found on CRAN try BioConductor
  echo "I: Checking BioConductor release repository"
  sed -i 's/^r-cran-/r-bioc-/' debian/changelog
  cat > debian/watch <<EOT
version=4
opts=downloadurlmangle=s?^(.*)\.\.?https://bioconductor.org/packages/release/bioc? \
 https://www.bioconductor.org/packages/release/bioc/html/${cranname}.html .*/${cranname}@ANY_VERSION@@ARCHIVE_EXT@
EOT
  tarball=`uscan --verbose 2>/dev/null | grep ".orig.tar.[gx]z" | sed 's#^.* \(\.\./.*\.orig\.tar\.[gx]z\).*#\1#'`
  if [ "$tarball" = "" ] ; then
    echo "I: Checking BioConductor experiment data repository"
    # There is a last resort chance to find the package in BioConductor data area
    cat > debian/watch <<EOT
version=4
opts=downloadurlmangle=s?^(.*)\.\.?https://bioconductor.org/packages/release/data/experiment? https://www.bioconductor.org/packages/release/data/experiment/html/${cranname}.html .*/${cranname}@ANY_VERSION@@ARCHIVE_EXT@
EOT
    tarball=`uscan --verbose 2>/dev/null | grep ".orig.tar.[gx]z" | sed 's#^.* \(\.\./.*\.orig\.tar\.[gx]z\).*#\1#'`
    if [ "$tarball" = "" ] ; then
      echo "I: Checking BioConductor annotation data repository"
      # There is a last resort chance to find the package in BioConductor annotation data area
      cat > debian/watch <<EOT
version=4
opts=downloadurlmangle=s?^(.*)\.\.?https://bioconductor.org/packages/release/data/annotation? https://www.bioconductor.org/packages/release/data/annotation/html/${cranname}.html .*/${cranname}@ANY_VERSION@@ARCHIVE_EXT@
EOT
      tarball=`uscan --verbose 2>/dev/null | grep ".orig.tar.[gx]z" | sed 's#^.* \(\.\./.*\.orig\.tar\.[gx]z\).*#\1#'`
      if [ "$tarball" = "" ] ; then
        echo "E: $cranname was neither found on CRAN nor part of the BioConductor release nor BioConductor annotation/experiment data"
        if [ "" != "$createdDirs" ]; then
          echo "   Please remove directory '$createdDirs'"
        fi
        exit 1
      fi
    fi
    # If this line was reached, then the package was found somewhere in BioConductor
    BIOCDATA="true"
    pkgname=r-bioc-`echo $cranname | tr '[A-Z]' '[a-z]'`
    cp -a debian/watch /tmp/watch_$pkgname
  fi
  pkgname=r-bioc-`echo $cranname | tr '[A-Z]' '[a-z]'`
fi

echo "I: Preparing package '$pkgname'"

cd ..
rm -rf r-cran-`echo $cranname | tr '[A-Z]' '[a-z]'`
tarball=`echo $tarball | sed 's#^\.\./##'`
if [ ! -r "$tarball" ]; then
  echo "I: Something went wrong - expected file '$tarball' in $(pwd)"
  exit 1
fi
echo "I: Untaring '$tarball' in $(pwd)"
tar xaf $tarball
cd $cranname
if [ `find . -iname "test*" | wc -l` -gt 0 ] ; then
  dh-make-R --test run-unit-test 2>/dev/null >/dev/null
else
  dh-make-R 2>/dev/null >/dev/null
fi

echo "I: Preparing debian/control"

# FIXME: dh-r does not know BioC data location yet.
#        This hack restores working watch file and hacks in proper Homepage
# FIXME FIXME: Handling annoation packages still needs to be addressed
if [ "$BIOCDATA" = "true" -a -e /tmp/watch_$pkgname ] ; then
  mv /tmp/watch_$pkgname debian/watch
  # Fix Homepage
  sed -i 's+^\(Homepage.*.org/packages/\)+&data/experiment/+' debian/control
fi

# Hack to get cme formatted d/control
sed -i 's/^Standards-Version: .*/Standards-Version: 4.0.0/' debian/control
cme fix dpkg-control 2>/dev/null >/dev/null || true

if [ `find . -iname "*.rda" -o -iname "*.rdata" | wc -l` -gt 0 ] ; then
  cd debian
  /usr/share/dh-r/create_README.source > README.source
  cd ..
fi

echo "I: Preparing local git repository"
cd ..
gitdir="$basedir/$pkgname"
mkdir $gitdir
cd $gitdir
git init
#newversion=`echo ../$tarball | sed 's/^.*_\([0-9].*\)\.orig\.tar\..*/\1/'`
#gbp import-orig --pristine-tar --upstream-version=$newversion ../$tarball
gbp import-orig --pristine-tar --no-interactive ../$tarball
mv ../$cranname/debian .
git add debian
git commit -a -m"Initial packaging by `basename $0`"
echo "I: Cleaning up"
rm -f ../`readlink ../$tarball`
rm -f ../$tarball
rm -rf ../$cranname

if [ "$wnppcheck" != "" ] ; then
  echo "Please make sure you contact reporter of ITP bug $wnppcheck to sort out the status if the package"
  sed -i "/Initial release/s/xxxxxx/$wnppcheck/" debian/changelog
fi

echo "You can find a packaging repository for $cranname in `pwd`"