View Single Post
Posts: 2,225 | Thanked: 3,822 times | Joined on Jun 2010 @ Florida
#5
And here is the entire script I used to do the above, if anyone wanted to see a programmatic specification.

Anyone familiar with my other work might notice that most of this code is yanked right out from the fkdep script I wrote about a year ago, since that's where/when I figured out how to build .deb files using stock-N900-only tools. The key difference is that unlike my normal code (which is usuall 50+% comments), this is 100% code, and devoid of any blank lines, because I just slapped it together for myself.

I use the variable PACKAGE to define the name of the package being made. That way if anyone wants to copy this script directly but wants to change the package name, you only have to change it in one place, and the variable is reused everywhere that's needed.

Code:
#!/bin/sh
arAddFile()
{
 SIZE=`ls -l $1 | awk '{print $5}'`
 printf '%-16s%-12s0     0     100644  %-10s`\n' $1 $TIMESTAMP $SIZE >> "$DEB"
 cat $1 >> "$DEB"
 if [ $((SIZE % 2)) = 1 ]
 then
  printf '\n' >> "$DEB"
 fi
}
PACKAGE=root
WORKDIR=`mktemp -d /tmp/"$PACKAGE".XXXXXX` || exit 1
SUBDIR=$WORKDIR/sub
mkdir "$SUBDIR"
cd "$SUBDIR"
tar -czf "$WORKDIR"/data.tar.gz .
cat > "$SUBDIR"/changelog <<DELIM
$PACKAGE (1.0) unstable; urgency=low
  * Automatically generated from script!

 -- nobody <nobody@example.com>  `date -R`
DELIM
cat > "$SUBDIR"/control <<DELIM
Source: $PACKAGE
Section: user/admin
Priority: extra
Maintainer: nobody <nobody@example.com>
Package: $PACKAGE
Architecture: all
Version: 1.0
Depends: 
Description: Adds basic rules for sudo: password-protected root access.
DELIM
cat > "$SUBDIR"/copyright <<DELIM
These auto-generated package contents are in the public domain.
DELIM
cat > "$SUBDIR"/preinst <<DELIM
#!/bin/sh
patchSudoers()
{
 sed -i '
  1 i root ALL = (ALL) NOPASSWD: ALL
  1 i user ALL = (ALL) PASSWD: ALL
  /user ALL = NOPASSWD: \/usr\/sbin\/gainroot/ d
 ' "$1"
}
patchSudoers /etc/sudoers.d/01sudo
patchSudoers /etc/sudoers
passwd -d user
osso-xterm passwd
DELIM
chmod +x "$SUBDIR"/preinst
tar -czf "$WORKDIR"/control.tar.gz .
cd "$WORKDIR"
rm -r "$SUBDIR"
printf '2.0\n' > debian-binary
DEB="$WORKDIR"/"$PACKAGE".deb
touch "$DEB"
TIMESTAMP=`date +%s -r "$DEB"`
printf '!<arch>\n' > "$DEB"
arAddFile debian-binary
arAddFile control.tar.gz
arAddFile data.tar.gz
rm debian-binary control.tar.gz data.tar.gz
dbus-send --type=method_call --print-reply='' \
 --dest=com.nokia.hildon_application_manager \
 /com/nokia/hildon_application_manager \
 com.nokia.hildon_application_manager.mime_open \
 string:"$DEB"
__________________
If you want to donate in support of anything that I do, you can do so with either of these options:
PayPal | Bitcoin: 1J4XG2z97iFEKNZXThHdFHq6AeyWEHs8BJ | [Will add other donation options eventually]
 

The Following 14 Users Say Thank You to Mentalist Traceur For This Useful Post: