-
Notifications
You must be signed in to change notification settings - Fork 0
/
rust-info.sh
executable file
·144 lines (123 loc) · 4.41 KB
/
rust-info.sh
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
#!/bin/bash
# Automatic $PRGNAM.info generator for Rust software. Use this script for
# software that supports both x86-64 and x86 architecture.
# Copyright 2022-2023 K. Eugene Carlson Tsukuba, Japan
# 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 "AS IS" 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.
# Running this script in a dedicated directory for your Rust package would be
# convenient (a DEBUG directory with files from intermediate steps is
# generated).
# Information about the program goes here
PRGNAM=${PRGNAM:-""}
VERSION=${VERSION:-""}
HOMEPAGE=${HOMEPAGE:-""}
REQUIRES=${REQUIRES:-""}
MAINTAINER=${MAINTAINER:-""}
EMAIL=${EMAIL:-""}
# Change the following, if necessary
ARCHIVE=${ARCHIVE:-$PRGNAM-$VERSION.tar.gz}
# Command to extract the tarball
TARCMD=${TARCMD:-"tar xf $ARCHIVE"}
PRGDIR=${PRGDIR:-"$PRGNAM-$VERSION"}
# Package tarball download
URL=${URL:-""}
# Rust crates come from here
WEBADDR="https://static.crates.io/crates/"
rm -rf DEBUG CRATES
wget $URL || exit
$TARCMD || exit
# Get name and version for Crate dependencies
grep -e ^name -e ^version $PRGDIR/Cargo.lock | grep \" | cut -d \" -f2- | tr -d \" > deps
# Get checksum as well
grep ^checksum $PRGDIR/Cargo.lock | grep \" | cut -d \" -f2- | tr -d \" > checksums
echo DOWNLOAD='"'$URL \\ > DOWNLOADS
# Generating depsgood; name of crate with suffix and version info
while read -r line; do
# Even-numbered lines in the deps document are version numbers
linemod=$((linecount % 2))
if [ "$linemod" = 0 ]; then
echo ' '"$WEBADDR$line/$line" | tr \\n \- >> DOWNLOADS
else
echo "$line".crate \\ >> DOWNLOADS
fi
if [ "$linemod" = 0 ]; then
echo $line | tr \\n \- >> depsgood
else
echo $line.crate >> depsgood
fi
linecount=$((linecount + 1))
done < deps
# Don't actually use crates without checksums (not for download)
grep -v -e ^$ -e ^# $PRGDIR/Cargo.lock > ignore1
cat ignore1 | tr -d \\n > ignore2
sed -i 's|package]]|package]]\n|g' ignore2
grep -v "checksum =" ignore2 > ignore3
grep ^name ignore3 > ignore4
while read -r line; do
echo $line | cut -d\" -f2- | cut -d\" -f-3 >> ignore
done < ignore4
sed -i 's|"version = "|-|g' ignore
sed -i 's|$|.crate|g' ignore
sed -i 's|^| -e |g' ignore
cat ignore | tr -d \\n > greparg
# Use constructed grep argument to ignore
if [ $(cat greparg | wc -c) -gt 0 ]; then
grep -v $(cat greparg) depsgood > depsgood2
grep -v $(cat greparg) DOWNLOADS > DOWNLOADS2
mv depsgood2 depsgood
mv DOWNLOADS2 DOWNLOADS
fi
sed -i '$ s| \\|"|' DOWNLOADS
# Quick cleanup
rm -f ignore*
source ./DOWNLOADS
mkdir -p CRATES
cd CRATES
wget $DOWNLOAD || exit
cd ..
# Using depsgood, check sha256sum
COUNT=0
while read -r crate; do
sha256=$(sha256sum CRATES/$crate | cut -d' ' -f-1)
COUNT=$((COUNT + 1))
cksum=$(head -n $COUNT checksums | tac | head -n 1)
[ $sha256 != $cksum ] && echo $crate has a bad sha256sum! && exit
done < depsgood
echo MD5SUM='"'$(md5sum $ARCHIVE | cut -d' ' -f-1) \\ > MD5SUMS
# Getting md5sums based on depsgood list (ensures the sums don't get mixed up)
while read -r crate; do
md5=$(md5sum CRATES/$crate | cut -d' ' -f-1)
echo ' '$md5 \\ >> MD5SUMS
done < depsgood
sed -i '$ s| \\|"|' MD5SUMS
# Putting $PRGNAM.info together
cat << EOF > $PRGNAM.info
PRGNAM="$PRGNAM"
VERSION="$VERSION"
HOMEPAGE="$HOMEPAGE"
$(cat DOWNLOADS MD5SUMS)
DOWNLOAD_x86_64=""
MD5SUM_x86_64=""
REQUIRES="$REQUIRES"
MAINTAINER="$MAINTAINER"
EMAIL="$EMAIL"
EOF
# Cleaning up; see the DEBUG directory for intermediate documents.
mkdir DEBUG
mv DOWNLOADS MD5SUMS deps depsgood checksums greparg DEBUG/