This commit is contained in:
emmett1
2017-11-18 13:29:53 +08:00
parent 996b9fd5ba
commit 327c0ea792
9 changed files with 366 additions and 54 deletions

15
INSTALL.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
DESTDIR=${DESTDIR:-}
BINDIR=${BINDIR:-/usr/bin}
FUNCDIR=/usr/share/scratchpkg
CONFDIR=/etc
HTTPUPDIR=/etc/ports
mkdir -pv ${DESTDIR}{${BINDIR},${FUNCDIR},${CONFDIR},${HTTPUPDIR}}
install -m755 buildpkg installpkg removepkg scratch ${DESTDIR}${BINDIR}
install -m644 functions/{color,functions,options} ${DESTDIR}${FUNCDIR}
install -m644 scratchpkg.conf ${DESTDIR}${CONFDIR}/scratchpkg.conf.orig
install -m644 ports/{core,extra,xorg}.httpup ${DESTDIR}${HTTPUPDIR}
install -m755 extra/* ${DESTDIR}${BINDIR}

90
extra/baseinstall Executable file
View File

@@ -0,0 +1,90 @@
#!/bin/bash
index_dir="/var/spkg/index"
basepkg=(linux-api-headers
man-pages
glibc
tzdata
zlib
file
readline
m4
bc
binutils
gmp
mpfr
libmpc
gcc
bzip2
pkg-config
ncurses
attr
acl
libcap
sed
shadow
psmisc
iana-etc
bison
flex
grep
bash
libtool
gdbm
gperf
expat
inetutils
perl
perl-xml-parser
intltool
autoconf
automake
xz
kmod
gettext
procps-ng
e2fsprogs
coreutils
diffutils
gawk
findutils
groff
grub
less
gzip
iproute2
kbd
libpipeline
make
patch
sysklogd
sysvinit
eudev
util-linux
man-db
tar
texinfo
vim
filesystem
rc-init
base-meta)
for list in ${basepkg[@]}; do
if [ -d $index_dir/$list ]; then
echo "$list is installed"
else
case $list in
gcc | bash | perl | coreutils | filesystem )
scratch -p $list -i -id -ic
;;
* )
scratch -p $list -i -id
;;
esac
if [ ! -d /var/spkg/index/$list ]; then
echo "ERROR $list"
read
fi
fi
done

41
extra/checklibdepends Executable file
View File

@@ -0,0 +1,41 @@
#!/bin/bash -e
if [ ! $1 ]; then
echo -e "this script requires one arguments."
exit 1
fi
if [ ! -d /var/spkg/index/$1 ]; then
echo "Package $1 not installed"
exit 1
fi
pushd / >/dev/null
while IFS=' ' read -r LINE; do
case "$(file -Lbi "${LINE}")" in
*application/x-sharedlib* | *application/x-executable*)
NEEDED_LIB=$(objdump -x "$LINE" | grep NEEDED | awk '{print $2}')
for i in ${NEEDED_LIB[@]}; do
if [ "$i" != "ld-linux-x86-64.so.2" ]; then
libpath=$(ldd "$LINE" | grep -v "not found" | grep -w "$i" | awk '{print $3}')
#echo "==> $libpath"
if [ "$libpath" ]; then
FILEPATH=$(readlink -f $(echo $libpath))
FILENAME=$(echo $FILEPATH | sed -e '1s/^.//')
PKG_NAME=$(basename $(dirname $(grep -Rx $FILENAME /var/spkg/index | cut -d ':' -f1)))
if [ "$PKG_NAME" != $1 ]; then
if [ ! "$(echo "$deppkg" | grep -w "$PKG_NAME")" ]; then
deppkg="$deppkg $PKG_NAME "
fi
fi
else
echo "$LINE (missing shared lib) => $i"
fi
fi
done
esac
done < <(tac /var/spkg/index/$1/.files | grep -E ^"(bin/|lib/|libexec/|sbin/|usr/bin/|usr/lib/|usr/libexec/|usr/sbin/)" | grep -v "/$")
popd >/dev/null
echo "Shared lib from package(s):"
echo $deppkg | tr ' ' '\n'

50
extra/depinstall Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/bash -e
checkpkg() {
for repo in ${PORT_REPO[@]}; do
if [ -f $repo/$pkgname/spkgbuild ]; then
PORT_EXIST=yes
break
fi
done
[ "$PORT_EXIST" ] || (echo "Port $pkgname not exist" && exit 1)
}
index_dir="/var/spkg/index"
if [ ! "$1" ]; then
echo "specify package name to install"
exit 1
fi
source /etc/scratchpkg.conf
pkgname=$1
checkpkg
if [ -d $index_dir/$1 ]; then
echo "Package $1 already installed" && exit 0
fi
for i in $(deplist $1 | awk '{print $1}'); do
if [ -d $index_dir/$i ]; then
continue
else
if [ $UID != 0 ]; then
if [ -x /usr/bin/fakeroot ]; then
echo "==> Build using fakeroot"
fakeroot scratch -p $i && sudo scratch -p $i -i || exit 1
else
sudo scratch -p $i -i || exit 1
fi
else
scratch -p $i -i || exit 1
fi
if [ ! -d $index_dir/$i ]; then
echo "Error installing $i..."
read
fi
fi
done
exit 0

69
extra/deplist Executable file
View File

@@ -0,0 +1,69 @@
#!/bin/bash -e
calcdep() {
dep=$(scratch -d $1 | awk '{print $3}')
for i in $dep; do
deps="$deps $i"
done
}
loop() {
for depends in ${dep[@]}; do
if [ "$(echo "$checked" | tr ' ' '\n' | grep -x "$depends")" ]; then
continue
else
checked="$checked $depends"
fi
#echo $checked
calcdep $depends
loop
done
}
checkpkg() {
for repo in ${PORT_REPO[@]}; do
if [ -f $repo/$pkgname/spkgbuild ]; then
PORT_EXIST=yes
break
fi
done
[ "$PORT_EXIST" ] || (echo "Port $pkgname not exist" && exit 1)
}
index_dir="/var/spkg/index"
if [ ! "$1" ]; then
echo "specify package name to list its dependencies"
exit 1
fi
source /etc/scratchpkg.conf
pkgname=$1
checkpkg # check for existence port
calcdep $pkgname # calculate dependencies
loop # loop through all dependencies
#echo $deps | tr ' ' '\n'
#read
# filter all same dependencies and sort backwards
for i in $(echo $deps | tr ' ' '\n'); do
[ $(echo $filterdep | tr ' ' '\n' | grep -x $i) ] || filterdep="$filterdep $i"
done
filterdep="$filterdep $pkgname" # add package to install to final dependency list
for alldep in $(echo $filterdep | tr ' ' '\n'); do
if [ -d $index_dir/$alldep ]; then
echo "$alldep [installed]"
else
echo "$alldep"
fi
done
exit 0

41
extra/dochroot Executable file
View File

@@ -0,0 +1,41 @@
#!/bin/bash
if [ "$UID" != "0" ]; then
echo "chroot need root access!"
exit 1
fi
LFS=/mnt/lfs
if [ ! -d $LFS ]; then
echo "Dir $LFS not exist"
exit 1
fi
pushd $LFS
mount -v --bind /dev $LFS/dev
mount -vt devpts devpts $LFS/dev/pts -o gid=5,mode=620
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys
mount -vt tmpfs tmpfs $LFS/run
if [ -h $LFS/dev/shm ]; then
mkdir -pv $LFS/$(readlink $LFS/dev/shm)
fi
if [ -d $LFS/tools ]; then
chroot "$LFS" /tools/bin/env -i HOME=/root TERM="$TERM" PS1='\u:\w\$ ' PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin /tools/bin/bash --login +h
else
chroot "$LFS" /usr/bin/env -i HOME=/root TERM="$TERM" PS1='\u:\w\$ ' PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/bash --login
fi
popd
echo chroot exited
echo "Unmounting virtual filesystem"
umount -v $LFS/dev/pts
umount -v $LFS/dev
umount -v $LFS/run
umount -v $LFS/proc
umount -v $LFS/sys

37
extra/listinstall Executable file
View File

@@ -0,0 +1,37 @@
#!/bin/bash
index_dir="/var/spkg/index"
if [ ! "$1" ]; then
echo "specify list file"
exit 1
fi
if [ ! -f "$1" ]; then
echo "file $1 not exist"
exit 1
fi
list=$(cat $1)
for i in $list; do
if [ -d $index_dir/$i ]; then
echo "$i is installed"
else
echo "installing $i..."
if [ $UID != 0 ]; then
if [ -x /usr/bin/fakeroot ]; then
echo "==> Build using fakeroot"
fakeroot scratch -p $i && sudo scratch -p $i -i
else
sudo scratch -p $i -i
fi
else
scratch -p $i -i
fi
if [ ! -d $index_dir/$i ]; then
echo "Error installing $i..."
read
fi
fi
done

23
extra/revdep Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/bash -e
INDEX_DIR="/var/spkg/index"
if [ ! -d $INDEX_DIR ]; then
echo "$INDEX_DIR not exist!"
exit 1
fi
find {,/usr}/{bin,lib,libexec,sbin} -type f ! -path */debug/* ! -path */java/* ! -path */vmware*/* \
! -path */syslinux/* 2>/dev/null | while read BUILD_BINARY ; do
case "$(file -Lbi "${BUILD_BINARY}")" in
*application/x-sharedlib* | *application/x-executable*)
if [ "$(ldd $BUILD_BINARY 2>/dev/null | grep "not found" | sort | uniq)" ]; then
LIB_NAME=$(ldd $BUILD_BINARY 2>/dev/null | grep "not found" | sort | uniq | awk '{print $1}')
FILENAME=$(echo $BUILD_BINARY | sed -e '1s/^.//')
PKG_NAME=$(basename $(dirname $(grep -Rx $FILENAME $INDEX_DIR | cut -d ':' -f1)))
for i in ${LIB_NAME[@]}; do
echo "($PKG_NAME) $BUILD_BINARY is missing $i"
done
fi
esac
done

54
setup
View File

@@ -1,54 +0,0 @@
#!/bin/bash
install() {
if [ ! -d $bindir ]; then
mkdir -pv $bindir
for i in scratch installpkg buildpkg removepkg; do
cp -v $i $bindir
done
else
for i in scratch installpkg buildpkg removepkg; do
[ ! -f $bindir/$i ] && cp -v $i $bindir || echo "$bindir/$i exists"
done
fi
if [ ! -d $confdir ]; then
mkdir -pv $confdir
[ ! -f $confdir/scratchpkg.conf ] && cp -v scratchpkg.conf $confdir
else
[ ! -f $confdir/scratchpkg.conf ] && cp -v scratchpkg.conf $confdir || echo "$confdir/scratchpkg.conf exists"
fi
if [ ! -d $funcdir ]; then
mkdir -pv $funcdir
[ ! -f $funcdir/functions ] && cp -v functions/* $funcdir
else
[ ! -f $funcdir/functions ] && cp -v functions/functions $funcdir || echo "$funcdir/functions exists"
[ ! -f $funcdir/options ] && cp -v functions/options $funcdir || echo "$funcdir/options exists"
[ ! -f $funcdir/color ] && cp -v functions/color $funcdir || echo "$funcdir/color exists"
fi
}
update() {
for i in "$bindir/scratch" "$bindir/installpkg" "$bindir/removepkg" "$bindir/buildpkg" "$funcdir/functions"; do
rm -v $i || true
done
[ -f /etc/scratchpkg.conf.backup ] && rm /etc/scratchpkg.conf.backup
mv -v /etc/scratchpkg.conf{,.backup}
install
}
bindir="/usr/bin"
confdir="/etc"
funcdir="/usr/share/scratchpkg"
if [ $(id -u) != 0 ]; then
echo "You need root access to install/update"
exit 1
fi
if [ "$1" = "update" ]; then
update
else
install
fi