Skip to content

Commit 32b7462

Browse files
author
emmett1
committed
updated
1 parent a1ef1c5 commit 32b7462

File tree

7 files changed

+348
-7
lines changed

7 files changed

+348
-7
lines changed

INSTALL.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ install -dm777 ${DESTDIR}${CACHE_DIR}/packages
1616
install -dm777 ${DESTDIR}${CACHE_DIR}/sources
1717
install -dm777 ${DESTDIR}${CACHE_DIR}/work
1818

19-
install -m755 xchroot revdep pkgadd pkgdel pkgbuild pkgquery scratch updateconf ${DESTDIR}${BINDIR}
19+
install -m755 xchroot revdep pkgadd pkgdel pkgbuild pkgquery scratch updateconf \
20+
pkgbase pkgdepends pkgrebuild pkgfix portcreate ${DESTDIR}${BINDIR}
2021
install -m644 scratchpkg.conf scratchpkg.repo scratchpkg.alias ${DESTDIR}${CONFDIR}
2122

2223
install -m644 revdep.conf ${DESTDIR}${REVDEPCONF}

pkgbase

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/sh
2+
#
3+
# script to remove all packages other than base and any user input
4+
#
5+
6+
parseopt() {
7+
while [ "$1" ]; do
8+
case $1 in
9+
-n) dryrun=1;;
10+
-y) yes=$1;;
11+
-h) printhelp; exit 0;;
12+
*) pkg="$pkg $1"
13+
esac
14+
shift
15+
done
16+
}
17+
18+
printhelp() {
19+
cat << EOF
20+
Usage:
21+
$(basename $0) [options] [packages]
22+
23+
Options:
24+
-n dry-run
25+
-y dont ask user confirmation
26+
-h print this help msg
27+
28+
EOF
29+
}
30+
31+
parseopt "$@"
32+
33+
echo "Calculate packages to keep..."
34+
keep=$(scratch deplist base $pkg | awk '{print $2}')
35+
36+
echo "Calculate selected packages to remove..."
37+
for pkg in $(scratch installed | awk '{print $1}'); do
38+
echo $keep | tr ' ' '\n' | grep -qx $pkg || {
39+
remove="$remove $pkg"
40+
}
41+
done
42+
43+
[ "$remove" ] && {
44+
[ "$dryrun" = 1 ] && {
45+
for i in $remove; do
46+
echo "remove: $i..."
47+
done
48+
echo "This is dry-run, no real action is run!"
49+
} || {
50+
scratch remove $yes $remove
51+
}
52+
}
53+
54+
exit $?

pkgdepends

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/sh
2+
3+
#
4+
# script to check dependencies
5+
#
6+
7+
get_libpath() {
8+
ldd $1 2>/dev/null | grep $2 | awk '{print $3}'
9+
}
10+
11+
scratch files $1 | while read -r line; do
12+
case $line in
13+
usr/share/gir-1.0/*.gir) extra_dep="$extra_dep gobject-introspection";;
14+
usr/share/vala/vapi/*.vapi) extra_dep="$extra_dep vala";;
15+
esac
16+
case $line in
17+
*/) continue;;
18+
esac
19+
case "$(file -bi /$line)" in
20+
*application/x-sharedlib* | *application/x-executable* | *application/x-pie-executable*)
21+
for NEEDED in $(objdump -x /$line | grep NEEDED | awk '{print $2}'); do
22+
case $NEEDED in
23+
libc.so|libc.so.6) continue;;
24+
esac
25+
[ "$NEEDED" ] || continue
26+
[ -f /"$line" ] || continue
27+
libs=$(get_libpath /$line $NEEDED)
28+
[ "$libs" ] || continue
29+
if ! echo $all_libs | grep -qw $libs; then
30+
pkg=$(scratch provide $libs$ | awk '{print $1}' | head -n1)
31+
case $pkg in
32+
$1|gcc|glibc|musl) continue;;
33+
esac
34+
[ "$pkg" ] || continue
35+
if ! echo $all_pkgs | grep -qw $pkg; then
36+
echo $pkg
37+
all_pkgs="$all_pkgs $pkg"
38+
unset pkg
39+
fi
40+
all_libs="$all_libs $libs"
41+
unset libs
42+
fi
43+
done ;;
44+
esac
45+
[ "$extra_dep" ] && {
46+
for e in $extra_dep; do
47+
if ! echo $all_pkgs | grep -qw $e; then
48+
echo $e
49+
all_pkgs="$all_pkgs $e"
50+
fi
51+
done
52+
}
53+
done
54+
55+
exit 0

pkgfix

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2019 by Emmett1 ([email protected])
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
#
18+
#
19+
# script to detect broken kernel modules after kernel update
20+
# need to use with 'scratchpkg'
21+
#
22+
23+
export LANG=C
24+
25+
get_perlmodules() {
26+
command -v perl >/dev/null || return
27+
perlpath=$(dirname $(perl -V:sitearch | grep -o "'.*'" | sed "s/'//g"))
28+
for i in $(dirname $perlpath)/*; do
29+
[ "$perlpath" = "$i" ] && continue
30+
brokenpkg="$brokenpkg $(scratch provide $i/$ | awk '{print $1}')"
31+
done
32+
}
33+
34+
get_modules() {
35+
[ -f /lib/modules/KERNELVERSION ] || return
36+
KERVER=$(cat /lib/modules/KERNELVERSION)
37+
for i in /lib/modules/*; do
38+
case $i in
39+
/lib/modules/KERNELVERSION|/lib/modules/$KERVER) continue ;;
40+
esac
41+
brokenpkg="$brokenpkg $(scratch provide $i/$ | awk '{print $1}')"
42+
done
43+
}
44+
45+
get_rubygem() {
46+
command -v gem >/dev/null || return
47+
gempath=$(gem env gemdir)
48+
for i in $(dirname $gempath)/*; do
49+
[ "$gempath" = "$i" ] && continue
50+
brokenpkg="$brokenpkg $(scratch provide $i/$ | awk '{print $1}')"
51+
done
52+
}
53+
54+
sort_modules() {
55+
for all in $(scratch deplist $brokenpkg | cut -d ' ' -f2); do
56+
for r in $brokenpkg; do
57+
if [ $r = $all ]; then
58+
if [ -z "$order" ]; then
59+
order="$all"
60+
else
61+
order="$order $all"
62+
fi
63+
break
64+
fi
65+
done
66+
done
67+
}
68+
69+
confirm() {
70+
printf "$1 (Y/n) "
71+
read -r response
72+
case "$response" in
73+
[Nn][Oo]|[Nn]) echo "$2"; return 2 ;;
74+
*) : ;;
75+
esac
76+
return 0
77+
}
78+
79+
usage() {
80+
cat << EOF
81+
Usage:
82+
$(basename $0) [options]
83+
84+
Options:
85+
-r rebuild & reinstall broken package
86+
-y dont ask user confirmation to rebuild package (use with -r)
87+
-h print this help message
88+
89+
EOF
90+
}
91+
92+
parse_opt() {
93+
while [ "$1" ]; do
94+
case $1 in
95+
-r) REBUILD=1 ;;
96+
-y) YES=1 ;;
97+
-h) usage; exit 0 ;;
98+
*) echo "Invalid option ($1)"; exit 1 ;;
99+
esac
100+
shift
101+
done
102+
}
103+
104+
parse_opt $@
105+
106+
if [ "$REBUILD" ] && [ "$(id -u)" != 0 ]; then
107+
echo "Rebuild broken packages required root!"
108+
exit 1
109+
fi
110+
111+
get_modules
112+
get_perlmodules
113+
get_rubygem
114+
115+
if [ "$brokenpkg" ]; then
116+
sort_modules
117+
else
118+
echo "No broken packages found."
119+
exit 0
120+
fi
121+
122+
if [ "$REBUILD" = 1 ]; then
123+
[ "$YES" ] || {
124+
echo
125+
echo "Package will be rebuild & reinstall by this order:"
126+
echo " $order"
127+
echo
128+
confirm "Continue rebuild & reinstall broken packages?" "Operation cancelled."
129+
}
130+
for p in $order; do
131+
scratch build -f $p && scratch install -r $p || exit 1
132+
done
133+
else
134+
echo "Broken packages:"
135+
for p in $order; do
136+
echo " $p"
137+
done
138+
fi
139+
140+
exit 0

pkgrebuild

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
#
3+
# script to rebuild base packages in right toolchain order
4+
#
5+
6+
LIST="/tmp/$(basename $0)-list"
7+
touch $LIST
8+
9+
TOOLCHAIN="linux-api-headers glibc-pass1 binutils-pass1 gcc binutils glibc"
10+
11+
#scratch sync || exit 1
12+
13+
for tc in $TOOLCHAIN; do
14+
if [ ! $(grep -x $tc $LIST) ]; then
15+
pkgname="$(echo $tc | sed 's/-pass1//')"
16+
scratch build -f $pkgname || exit 1
17+
echo $tc >> $LIST
18+
scratch install -r $pkgname --no-backup || exit 1
19+
fi
20+
done
21+
22+
for pkg in $(scratch deplist base | awk '{print $2}'); do
23+
case $pkg in
24+
linux-api-headers|musl|gcc|binutils|glibc) continue;;
25+
esac
26+
if [ ! $(grep -x $pkg $LIST) ]; then
27+
scratch build -f $pkg || exit 1
28+
echo $pkg >> $LIST
29+
scratch install -r $pkg --no-backup || exit 1
30+
fi
31+
done
32+
33+
exit 0

portcreate

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/sh
2+
#
3+
# scratchpkg
4+
#
5+
# Copyright (c) 2018 by Emmett1 ([email protected])
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
#
20+
21+
if [ -d "$1" ]; then
22+
echo "ERROR: Directory '$1' already exist!"
23+
exit 1
24+
else
25+
mkdir "$1"
26+
echo "# description :
27+
# homepage :
28+
# maintainer :
29+
# depends :
30+
31+
name=$1
32+
version=
33+
release=1
34+
options=\"\"
35+
noextract=\"\"
36+
backup=\"\"
37+
source=\"\"
38+
39+
build() {
40+
cd \$name-\$version
41+
./configure --prefix=/usr
42+
make
43+
make DESTDIR=\$PKG install
44+
}" > "$1"/spkgbuild
45+
echo "Template port have created for '$1'."
46+
fi
47+
48+
exit 0

xchroot

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/sh
2+
#
3+
# script to enter chroot
4+
#
25

36
printhelp() {
47
cat << EOF
@@ -14,6 +17,13 @@ EOF
1417
msgerr() {
1518
echo "ERROR: $*"
1619
}
20+
21+
unmount() {
22+
while true; do
23+
mountpoint -q $1 || break
24+
umount $1 2>/dev/null
25+
done
26+
}
1727

1828
[ "$(id -u)" = "0" ] || {
1929
msgerr "$(basename $0) need root access!"
@@ -78,13 +88,13 @@ retval=$?
7888
mv $TARGET/etc/resolv.conf.tmp $TARGET/etc/resolv.conf
7989
}
8090

81-
umount -l $TARGET/dev/pts
82-
umount -l $TARGET/dev
83-
umount -l $TARGET/run
84-
umount -l $TARGET/proc
91+
unmount $TARGET/dev/pts
92+
unmount $TARGET/dev
93+
unmount $TARGET/run
94+
unmount $TARGET/proc
8595
if [ -n "$EFI_SYSTEM" ]; then
86-
umount -l $TARGET/sys/firmware/efi/efivars
96+
unmount $TARGET/sys/firmware/efi/efivars
8797
fi
88-
umount -l $TARGET/sys
98+
unmount $TARGET/sys
8999

90100
exit $retval

0 commit comments

Comments
 (0)