95 Commits

Author SHA1 Message Date
emmett1
1161d001b8 fix scratch_orphan to use world 2022-08-13 21:57:48 +08:00
emmett1
a70018062e added scratch world option 2022-08-12 00:49:59 +08:00
Emmett1
70fa8b3bf2 Merge pull request #27 from XDream8/patch-1 2022-08-09 17:14:55 +08:00
XDream8
4a631ea4a7 added: lz4 and zstd compression mode 2022-08-09 12:02:08 +03:00
emmett1
b7cd1114da fix 2022-08-05 23:40:32 +08:00
emmett1
7612d83368 remove pkgfix from INSTALL.sh 2022-08-02 23:56:10 +08:00
emmett1
41151b383e conflict showing which package own the file 2022-08-02 23:54:56 +08:00
emmett1
ca93ecfe94 fix revdep -p 2022-08-02 23:54:07 +08:00
emmett1
cdd4cdd71c fix pkg_genpkgfiles 2022-07-22 16:24:44 +08:00
emmett1
31bba79556 use grep -x instead of -w when checking scratchpkg.mask 2022-07-21 08:02:01 +08:00
emmett1
643a7ec6bf make scratch locate ignore case 2022-07-20 23:35:42 +08:00
emmett1
b06326bfd0 fix scratch trigger 2022-07-18 23:22:19 +08:00
emmett1
9eef7b197b fixes 2022-07-18 01:11:18 +08:00
emmett1
6626017ff7 fix portsync 2022-07-02 23:45:03 +08:00
emmett1
0b3092bbfb fix and improve 2022-07-02 07:00:17 +08:00
emmett1
da5d1be623 merged pkgfix into revdep 2022-06-27 00:40:46 +08:00
emmett1
da7cce1e23 fix compress manpages 2022-06-27 00:02:10 +08:00
emmett1
d353ba3bfa add printconfig function and add missing opts 2022-04-11 00:45:27 +08:00
emmett1
d53b1b7b08 replace pre/post-upgrade.sh with pre/post-install.sh 2021-07-25 14:12:04 +08:00
emmett1
819f42df3a remove deprecated stuff leftover 2021-07-25 14:08:54 +08:00
emmett1
c254ac0dc6 fix pkg_fetch and pkg_clean 2021-07-02 13:02:43 +08:00
emmett1
61dd798a5f fix 2021-05-15 15:51:46 +08:00
emmett1
31e52cc3b5 remove fix permission msg 2021-05-12 11:47:54 +08:00
emmett1
4adcc4bfe9 fix revdep 2021-05-12 11:46:37 +08:00
Emmett1
a432db4c26 Merge pull request #20 from MCotocel/master
Fix grammar in pkgadd, pkgbuild, pkgdel, pkgfix, and revdep
2021-05-08 01:22:08 +08:00
Matei Cotocel
073e7433f7 Fix grammar in revdep 2021-05-07 21:01:19 +04:00
Matei Cotocel
e1dd623125 Fix grammar in pkgfix 2021-05-07 21:00:22 +04:00
Matei Cotocel
f396d41551 Fix grammar in pkgdel 2021-05-07 20:59:29 +04:00
Matei Cotocel
59ea432704 Fix grammar in pkgbuild 2021-05-07 20:58:37 +04:00
Matei Cotocel
3dcdee4f9d Fix grammar in pkgadd 2021-05-07 20:56:49 +04:00
emmett1
8691210b76 updated 2021-05-04 00:42:28 +08:00
emmett1
d56e9e4d6c re-add --no-backup opt 2021-05-01 06:16:53 +08:00
emmett1
278bc6c512 updated 2021-04-30 17:24:56 +08:00
emmett1
b9e49bcfac scratch, pkgadd 2021-04-29 23:32:41 +08:00
emmett1
5c5324970f updated 2021-04-10 23:43:07 +08:00
emmett1
ece22a4c4a add usr/lib/locale 2021-03-31 22:28:24 +08:00
emmett1
1234389c38 add KEEP_LOCALE and KEEP_DOC 2021-03-31 00:29:21 +08:00
emmett1
e2588ff9c8 updated 2021-03-20 23:22:24 +08:00
emmett1
f94e5714a1 add homepage to portcreate 2021-03-19 14:23:00 +08:00
emmett1
d800fa1f91 added reposync 2021-03-19 14:22:25 +08:00
emmett1
0444fb4937 add -i to search grep 2021-03-19 14:14:18 +08:00
emmett1
c6131b545a update pkgfix 2021-02-24 23:50:00 +08:00
emmett1
57c3779d86 update INSTALL.sh 2021-02-21 23:07:32 +08:00
emmett1
80e4afcaac updated 2021-02-15 00:00:20 +08:00
emmett1
0e1dd428c0 add pkg details in .pkgfiles 2021-02-07 22:33:47 +08:00
emmett1
b14ab18b8d remove options var from portcreate 2021-01-25 00:14:27 +08:00
emmett1
e651bf371f fix trigger fonts 2021-01-23 13:59:55 +08:00
Emmett1
059174e644 Merge pull request #17 from Byl3x/master
Add quiet option
2021-01-22 21:58:28 +08:00
emmett1
8c3f3e4bc7 updated 2021-01-22 21:59:15 +08:00
Byl3x
6c85489b2c updated man page 2021-01-21 10:38:37 +01:00
Byl3x
dba27d791f added option in pkgbuild 2021-01-21 10:29:09 +01:00
Byl3x
7e07dcdd0a added quiet option 2021-01-21 10:26:27 +01:00
emmett1
fd011dd3dc updated 2021-01-11 22:46:18 +08:00
emmett1
bc77ed9758 updated 2020-11-18 23:19:51 +08:00
emmett1
b42c48a88c fix how scratch read masked packages 2020-09-20 22:06:51 +08:00
emmett1
497b92c1cd fix scratch search grep error msg 2020-08-14 12:23:50 +08:00
emmett1
f3018114dd add mask function 2020-07-29 22:09:27 +08:00
emmett1
eee0a24f61 remove obsolete part in scratch info 2020-04-28 23:57:15 +08:00
emmett1
ab23dbde67 add CROSS_COMPILE env for strip 2020-04-28 23:56:04 +08:00
emmett1
f74b026a13 add logging option to scratch build 2020-04-27 18:02:18 +08:00
emmett1
552e0c7bfe updated 2020-04-27 13:52:05 +08:00
emmett1
34b9568afb fix printf colourize 2020-04-27 13:09:02 +08:00
emmett1
0aa9868d15 fixesss 2020-04-22 14:27:39 +08:00
emmett1
f0ff3d070e add function to use custom repo and alias file 2020-04-10 22:41:09 +08:00
emmett1
985f59fc97 update alias function 2020-04-10 13:18:13 +08:00
emmett1
2651ad3188 remove pkglocate 2020-04-07 00:39:36 +08:00
emmett1
3602e0a8e8 add locate function 2020-04-07 00:39:12 +08:00
emmett1
c816e3b409 update pkgbase 2020-04-02 16:22:27 +08:00
emmett1
8d4b7902eb add usr/lib/locale to removelocales function 2020-04-02 16:20:02 +08:00
emmett1
32b7462f2d updated 2020-03-30 17:17:39 +08:00
emmett1
a1ef1c5b33 move pkgquery function back to scratch 2020-03-16 17:52:49 +08:00
emmett1
b72816f8df revert logging 2020-03-14 00:12:29 +08:00
emmett1
9b186bfd31 add logging, --log 2020-03-13 17:20:31 +08:00
emmett1
8e8c62d338 xchroot: add '-l' to umount 2020-03-05 17:32:54 +08:00
emmett1
c8b2eca5ba updated 2020-02-25 23:59:33 +08:00
emmett1
a23a22c659 fix scratch_upgrade 2020-02-25 18:07:35 +08:00
emmett1
9a06fbd474 fix pkgadd 2020-02-19 17:03:24 +08:00
emmett1
7a91fbdcd4 replace type with command 2020-02-19 15:23:42 +08:00
emmett1
00e55a2473 replace type with command 2020-02-19 00:39:34 +08:00
emmett1
0ee256b921 fix 2020-02-17 23:58:18 +08:00
emmett1
424c56f075 fix typo 2020-02-12 23:48:17 +08:00
emmett1
0440395881 fix 2020-02-10 17:44:48 +08:00
emmett1
6dddc034f9 updated 2020-02-10 00:18:14 +08:00
emmett1
4d8f539f45 updated 2020-02-08 23:44:01 +08:00
emmett1
cfaca4e65f updated 2020-02-08 17:50:37 +08:00
emmett1
0a9cfce26a add xchroot script 2020-02-07 23:31:35 +08:00
emmett1
5eeb974b17 updated 2020-02-07 23:22:30 +08:00
emmett1
2e26f7c2f0 add package alias function 2020-02-06 13:35:11 +08:00
emmett1
6e4134550e fix typo 2020-02-01 11:40:11 +08:00
emmett1
be8cbb552a add sort to pkgquery and scratch search function 2020-01-31 23:19:21 +08:00
emmett1
cf8d6c9cc9 fix generate_pkgfiles on pkgbuild 2020-01-20 11:53:54 +08:00
emmett1
b5733b2f8f fix scratch_build 2020-01-17 22:59:54 +08:00
emmett1
b6710e58c4 fix scratch search and pkgquery search 2020-01-16 10:05:32 +08:00
emmett1
0b78bb986d fix typos 2020-01-16 00:17:24 +08:00
emmett1
3b7a73c0d8 bring back search function to scratch, maybe for now 2020-01-15 12:45:38 +08:00
19 changed files with 1562 additions and 1208 deletions

View File

@@ -14,10 +14,10 @@ install -d ${DESTDIR}${REVDEPD}
install -dm777 ${DESTDIR}${CACHE_DIR}/packages
install -dm777 ${DESTDIR}${CACHE_DIR}/sources
install -dm777 ${DESTDIR}${CACHE_DIR}/log
install -dm777 ${DESTDIR}${CACHE_DIR}/work
install -m755 revdep pkgadd pkgdel pkgbuild pkgquery scratch updateconf ${DESTDIR}${BINDIR}
install -m644 scratchpkg.conf scratchpkg.repo ${DESTDIR}${CONFDIR}
install -m755 xchroot revdep pkgadd pkgdel pkgbuild scratch updateconf portsync \
pkgbase pkgdepends pkgrebuild portcreate ${DESTDIR}${BINDIR}
install -m644 scratchpkg.conf scratchpkg.repo scratchpkg.alias scratchpkg.mask ${DESTDIR}${CONFDIR}
install -m644 revdep.conf ${DESTDIR}${REVDEPCONF}

View File

@@ -129,7 +129,7 @@ Available options:
### pkgadd
`pkgadd` is a tool to install and upgrade package created by `pkgbuild`. Install package is simply extract
`<name>-<version>-<release>.spkg.txz` by using tar into real system then save list extracted file into package `INDEX_DIR`.
`<name>-<version>-<release>.spkg.txz` by using tar into real system then save list extracted file into package `PKGDB_DIR`.
Upgrading package is also using same extract as install, it will replace old files then compare list file from old and new
package and remove old file which not exist in new package (like Slackware pkgtool does).
@@ -154,7 +154,7 @@ package and remove old file which not exist in new package (like Slackware pkgto
old configuration files and skip conflict check
### pkgdel
`pkgdel` is a tool to remove package from system. It will read file listed in package `INDEX_DIR` and remove it.
`pkgdel` is a tool to remove package from system. It will read file listed in package `PKGDB_DIR` and remove it.
Usage:
pkgdel [ <options> <package name> ]

179
pkgadd
View File

@@ -36,14 +36,14 @@ msg2() {
}
msgerr() {
echo "==> ERROR: $1"
echo "==> ERROR: $1" >&2
}
msgwarn() {
echo "==> WARNING: $1"
echo "==> WARNING: $1" >&2
}
help() {
help() {
cat << EOF
Usage:
$(basename $0) [ <options> <package.spkg.txz> ]
@@ -59,6 +59,7 @@ Options:
--no-preupgrade skip preupgrade script before upgrade package
--no-postupgrade skip postupgrade script after upgrade package
--no-backup skip backup when upgrading package
--print-dbdir print package database path
--root=<path> install to custom root directory
EOF
@@ -70,9 +71,9 @@ extract_opts() {
--*) opts="$opts $1";;
-*) char=${#1}; count=1
while [ "$count" != "$char" ]; do
count=$((count+1))
opts="$opts -$(echo $1 | cut -c $count)"
done;;
count=$((count+1))
opts="$opts -$(echo $1 | cut -c $count)"
done;;
*) opts="$opts $1"
esac
shift
@@ -93,12 +94,13 @@ parse_opts() {
-h | --help) SHOWHELP=yes ;;
--no-preinstall) NO_PREINSTALL=yes ;;
--no-postinstall) NO_POSTINSTALL=yes ;;
--no-preupgrade) NO_PREUPGRADE=yes ;;
--no-postupgrade) NO_POSTUPGRADE=yes ;;
--no-backup) NO_BACKUP=yes ;;
--root=*) ROOT_DIR="${1#*=}" ;;
*.spkg.tar.*) PKGNAME="$(realpath $1)" ;;
*) msg "Invalid option! ($1)"; exit 1 ;;
--no-preupgrade) NO_PREUPGRADE=yes ;;
--no-postupgrade) NO_POSTUPGRADE=yes ;;
--no-backup) NO_BACKUP=yes ;;
--print-dbdir) PRINTDBDIR=yes ;;
--root=*) ROOT_DIR="${1#*=}" ;;
*.spkg.tar.*) PKGNAME="$(realpath $1)" ;;
*) msg "Invalid option! ($1)"; exit 1 ;;
esac
shift
done
@@ -107,12 +109,12 @@ parse_opts() {
ret() {
# remove lock and all tmp files on exit
rm -f "$LOCK_FILE" "$TMP_PKGADD" "$TMP_PKGINSTALL" "$TMP_CONFLICT"
rm -f "$ROOT_DIR/$LOCK_FILE" "$TMP_PKGADD" "$TMP_PKGINSTALL" "$TMP_CONFLICT"
exit $1
}
isinstalled() {
if [ -s "$INDEX_DIR/$1/.pkginfo" ] && grep -q "$1" "$INDEX_DIR/$1/.pkginfo"; then
if [ -s "$ROOT_DIR/$PKGDB_DIR/$1" ]; then
return 0
else
return 1
@@ -121,16 +123,17 @@ isinstalled() {
parse_opts $(extract_opts "$@")
INDEX_DIR="$ROOT_DIR/var/lib/scratchpkg/index"
LOCK_FILE="$ROOT_DIR/var/lib/scratchpkg/spkg.lock"
SCRATCHPKG_DIR="var/lib/scratchpkg"
PKGDB_DIR="$SCRATCHPKG_DIR/db"
PKGDBPERMS_DIR="$PKGDB_DIR.perms"
LOCK_FILE="$SCRATCHPKG_DIR/spkg.lock"
# disable pre/post install/upgrade script when install to custom root location
if [ "$ROOT_DIR" != "" ]; then
NO_PREINSTALL=yes
NO_POSTINSTALL=yes
NO_PREUPGRADE=yes
NO_POSTUPGRADE=yes
fi
ROOT_DIR="${ROOT_DIR%/}" # remove trailing slash
[ "$PRINTDBDIR" ] && {
echo "$ROOT_DIR/$PKGDB_DIR"
ret 0
}
# show help page
[ "$SHOWHELP" ] || [ -z "$PKGNAME" ] && {
@@ -138,25 +141,26 @@ fi
ret 0
}
[ -d "$INDEX_DIR" ] || {
msgerr "Package's database directory not exist! ($INDEX_DIR)"
[ -d "$ROOT_DIR/$PKGDB_DIR" ] || {
msgerr "Package's database directory does not exist: $ROOT_DIR/$PKGDB_DIR"
ret 1
}
# check for root access, non-root only allowed if use custom --root= location
[ "$(id -u)" = "0" ] || [ "$ROOT_DIR" ] || {
msgerr "Installing package need root access!"
# check for root access
[ "$(id -u)" = "0" ] || {
msgerr "Installing packages requires root access!"
ret 1
}
# check for lock file
[ -f "$LOCK_FILE" ] && {
msgerr "Cant install/remove package simultaneously."
msgerr "remove '$LOCK_FILE' if no install/remove package process running."
[ -f "$ROOT_DIR/$LOCK_FILE" ] && {
msgerr "Cannot install/remove package simultaneously."
msgerr "remove '$ROOT_DIR/$LOCK_FILE' if no install/remove package process running."
exit 1
}
touch "$LOCK_FILE" 2>/dev/null || {
msgerr "Cant create lock file in '$LOCK_FILE'."
touch "$ROOT_DIR/$LOCK_FILE" 2>/dev/null || {
msgerr "Cannot create lock file in '$ROOT_DIR/$LOCK_FILE'."
exit 1
}
@@ -164,7 +168,7 @@ BASEPKGNAME=$(basename $PKGNAME)
# check existence of package file
[ -f "$PKGNAME" ] || {
msgerr "Package '$1' not exist!"
msgerr "Package '$1' does not exist!"
ret 1
}
@@ -173,11 +177,11 @@ release=${noextname##*-}
noextname=${noextname%-*}
version=${noextname##*-}
name=${noextname%-*}
# get package information if installed
if isinstalled $name; then
iversion=$(grep ^version $INDEX_DIR/$name/.pkginfo | cut -d " " -f3-)
irelease=$(grep ^release $INDEX_DIR/$name/.pkginfo | cut -d " " -f3-)
iversion=$(head -n1 $ROOT_DIR/$PKGDB_DIR/$name | awk '{print $1}')
irelease=$(head -n1 $ROOT_DIR/$PKGDB_DIR/$name | awk '{print $2}')
ALREADYINSTALLED=yes
fi
@@ -200,12 +204,12 @@ if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then
fi
fi
TMP_PKGADD="/tmp/.tmp_pkgadd.$$"
TMP_PKGINSTALL="/tmp/.tmp_pkginstall.$$"
TMP_CONFLICT="/tmp/.tmp_conflict.$$"
TMP_PKGADD="$ROOT_DIR/$SCRATCHPKG_DIR/.tmp_pkgadd"
TMP_PKGINSTALL="$ROOT_DIR/$SCRATCHPKG_DIR/.tmp_pkginstall"
TMP_CONFLICT="$ROOT_DIR/$SCRATCHPKG_DIR/.tmp_conflict"
# check integrity of package and save list file/dirs to install in the meantime
tar -tf $PKGNAME > $TMP_PKGADD 2>/dev/null || {
tar -tvf $PKGNAME > $TMP_PKGADD 2>/dev/null || {
msgerr "Package '$1' is corrupted!"
ret 1
}
@@ -219,18 +223,22 @@ echo "$opr: $name-$version-$release..."
# check for file conflict
if [ ! "$IGNORE_CONFLICT" ]; then
grep -Ev "^.pkg*" "$TMP_PKGADD" | grep -v '/$' | while read -r line; do
grep -v '/$' "$TMP_PKGADD" | awk '{print $6}' | while read -r line; do
if [ "$line" = "${line%.*}.spkgnew" ]; then
line=${line%.*}
fi
if [ -e "$ROOT_DIR/$line" ] || [ -L "$ROOT_DIR/$line" ]; then
if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then
if ! grep -Fqx "$line" "$INDEX_DIR/$name/.files"; then
echo "$line"
if ! grep -Fqx "$line" "$ROOT_DIR/$PKGDB_DIR/$name"; then
_f=$(grep -x ^"$line"$ $ROOT_DIR/$PKGDB_DIR/* | cut -d : -f1 | awk -F / '{print $(NF)}' | head -n1 | grep -v $name)
_f=${_f:-(none)}
echo "$_f $line"
touch "$TMP_CONFLICT"
fi
else
echo "$line"
_f=$(grep -x ^"$line"$ $ROOT_DIR/$PKGDB_DIR/* | cut -d : -f1 | awk -F / '{print $(NF)}' | head -n1)
_f=${_f:-(none)}
echo "$_f $line"
touch "$TMP_CONFLICT"
fi
fi
@@ -242,32 +250,10 @@ if [ ! "$IGNORE_CONFLICT" ]; then
fi
fi
# pre-install and pre-upgrade script
if grep -qx .pkginstall $TMP_PKGADD; then
TMP_PKGINSTALL_SCRIPT="/tmp/.tmp_pkgadd_installscript.$$"
tar -xf "$PKGNAME" .pkginstall -O > "$TMP_PKGINSTALL_SCRIPT"
if [ ! "$NO_PREINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then
(cd "$ROOT_DIR"/
sh "$TMP_PKGINSTALL_SCRIPT" pre-install "$version"
)
fi
if [ "$UPGRADE_PKG" ] && [ ! "$NO_PREUPGRADE" ]; then
(cd "$ROOT_DIR"/
sh "$TMP_PKGINSTALL_SCRIPT" pre-upgrade "$version" "$iversion"
)
fi
rm -f "$TMP_PKGINSTALL_SCRIPT"
fi
# exclude .pkg* files when extract into system
for i in $(grep "^.pkg*" $TMP_PKGADD); do
excludefile="$excludefile --exclude=$i"
done
rm -f $TMP_PKGINSTALL
# extract package into ROOT_DIR
tar --keep-directory-symlink -p -x -v -f "$PKGNAME" -C "$ROOT_DIR"/ $excludefile | while read -r line; do
tar -xvhpf "$PKGNAME" -C "$ROOT_DIR"/ | while read -r line; do
if [ "$line" = "${line%.*}.spkgnew" ]; then
line=${line%.*}
if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then
@@ -284,53 +270,26 @@ done
# remove old files from old package that not exist in new package
if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then
rmlist_file="/tmp/.rmlist_file.$$"
rmlist_dir="/tmp/.rmlist_dir.$$"
reserve_dir="/tmp/.reserve_dir.$$"
rmlist_all="/tmp/.rmlist_all.$$"
grep '/$' $INDEX_DIR/*/.files | grep -v $INDEX_DIR/$name/.files | awk -F : '{print $2}' | sort | uniq > $reserve_dir # get list reserved dirs
grep -Fxv -f "$TMP_PKGINSTALL" $INDEX_DIR/$name/.files > $rmlist_all # get list files and dirs to remove
grep -v '/$' "$rmlist_all" | tac > "$rmlist_file" # get files only to remove
grep -Fxv -f "$reserve_dir" "$rmlist_all" | grep '/$' | tac > "$rmlist_dir" # get dirs only (safe) to remove
# remove pseudo fs from remove list
#sed '/^dev\//d;/^sys\//d;/^proc\//d;/^run\//d;/^tmp\//d' -i $rmlist_file
#sed '/^dev\//d;/^sys\//d;/^proc\//d;/^run\//d;/^tmp\//d' -i $rmlist_dir
(cd "$ROOT_DIR"/
[ -s $rmlist_file ] && xargs -a $rmlist_file -d'\n' rm $VERBOSE_INSTALL
[ -s $rmlist_dir ] && xargs -a $rmlist_dir -d'\n' rmdir $VERBOSE_INSTALL
)
rm -f "$rmlist_file" "$rmlist_dir" "$reserve_dir" "$rmlist_all"
tail -n+2 "$ROOT_DIR/$PKGDB_DIR/$name" | tac | while read -r line; do
case $line in
*/) grep "^$line$" $ROOT_DIR/$PKGDB_DIR/* "$TMP_PKGINSTALL" 2>/dev/null | grep -qv "$ROOT_DIR/$PKGDB_DIR/$name" || rmdir $([ "$VERBOSE_INSTALL" ] && echo -v) "$ROOT_DIR/$line";;
*) grep -q "^$line$" "$TMP_PKGINSTALL" || rm $([ "$VERBOSE_INSTALL" ] && echo -v) "$ROOT_DIR/$line";;
esac
done
fi
# register package into database
rm -fr "$INDEX_DIR/$name"
mkdir "$INDEX_DIR/$name"
echo "name = $name" > "$INDEX_DIR/$name/.pkginfo"
echo "version = $version" >> "$INDEX_DIR/$name/.pkginfo"
echo "release = $release" >> "$INDEX_DIR/$name/.pkginfo"
install -m644 "$TMP_PKGINSTALL" "$INDEX_DIR/$name/.files"
for ii in $(grep ^.pkg* $TMP_PKGADD); do
pkgfiles="$pkgfiles $ii"
echo "$version $release" > "$ROOT_DIR/$PKGDB_DIR/$name"
cat "$TMP_PKGINSTALL" >> "$ROOT_DIR/$PKGDB_DIR/$name"
mkdir -p "$ROOT_DIR/$PKGDBPERMS_DIR"
rm -f "$ROOT_DIR/$PKGDBPERMS_DIR/$name"
grep '/$' $TMP_PKGADD | while read -r perms own junk1 junk2 junk3 dir junk4; do
if [ "$perms" != drwxr-xr-x ] || [ "$own" != root/root ]; then
echo "$perms $own $dir" >> "$ROOT_DIR/$PKGDBPERMS_DIR/$name"
[ -s "$ROOT_DIR/$PKGDBPERMS_DIR/$name" ] || rm "$ROOT_DIR/$PKGDBPERMS_DIR/$name"
fi
done
if [ "$pkgfiles" ]; then
tar -x -f "$PKGNAME" -C "$INDEX_DIR/$name" $pkgfiles >/dev/null 2>&1
fi
if [ -f "$INDEX_DIR/$name/.pkginstall" ]; then
if [ ! "$NO_POSTINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then
(cd "$ROOT_DIR"/
sh "$INDEX_DIR/$name/.pkginstall" post-install "$version"
)
fi
if [ "$UPGRADE_PKG" ] && [ ! "$NO_POSTUPGRADE" ]; then
(cd "$ROOT_DIR"/
sh "$INDEX_DIR/$name/.pkginstall" post-upgrade "$version" "$iversion"
)
fi
fi
# running ldconfig
if [ -x "$ROOT_DIR"/sbin/ldconfig ]; then
"$ROOT_DIR"/sbin/ldconfig -r "$ROOT_DIR"/

76
pkgbase Executable file
View File

@@ -0,0 +1,76 @@
#!/bin/sh
#
# scratchpkg
#
# Copyright (c) 2018 by Emmett1 (emmett1.2miligrams@gmail.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#
# script to remove all packages other than base and any user input
#
parseopt() {
while [ "$1" ]; do
case $1 in
-n) dryrun=1;;
-y) yes=$1;;
-h) printhelp; exit 0;;
*) pkg="$pkg $1"
esac
shift
done
}
printhelp() {
cat << EOF
Usage:
$(basename $0) [options] [packages]
Options:
-n dry-run
-y dont ask user confirmation
-h print this help msg
EOF
}
error=0
parseopt "$@"
echo "Calculate packages to keep..."
keep=$(scratch deplist base $pkg | awk '{print $2}')
echo "Calculate selected packages to remove..."
for pkg in $(scratch installed | awk '{print $1}'); do
echo $keep | tr ' ' '\n' | grep -qx $pkg || {
remove="$remove $pkg"
}
done
[ "$remove" ] && {
[ "$dryrun" = 1 ] && {
for i in $remove; do
echo "remove: $i..."
done
echo "This is dry-run, no real action is run!"
} || {
scratch remove $yes $remove || error=1
}
} || {
echo "Already on base, nothing to remove."
}
exit $error

508
pkgbuild
View File

@@ -27,51 +27,52 @@ msg2() {
}
msgerr() {
echo "==> ERROR: $1"
echo "==> ERROR: $1" >&2
}
msgwarn() {
echo "==> WARNING: $1"
echo "==> WARNING: $1" >&2
}
updatemdsum() {
msg "Generating .checksums..."
generatemdsum > .checksums
}
generatemdsum() {
if [ -z "$source" ]; then
echo SKIP
return 0
fi
for src in $source; do
if echo $src | grep -qE "::(ftp|http|https)://"; then
FILENAME=$SOURCE_DIR/$(echo $src | awk -F '::' '{print $1}')
elif echo $src | grep -qE "(ftp|http|https)://"; then
FILENAME=$SOURCE_DIR/$(basename $src)
else
FILENAME=$src
fi
needupdatechecksum="$needupdatechecksum $FILENAME"
pkg_genchecksums() {
for i in $(get_filepath); do
[ -f "$i" ] || {
msgerr "File missing: $i"
err=1
}
done
md5sum $needupdatechecksum | sed -e 's| .*/| |' | sort -k 2
[ "$err" = 1 ] && abort 1
generatemdsum > .checksums
msg "Checksums updated."
}
checkmdsum() {
generatemdsum() {
for s in $(get_filepath); do
if [ -f $s ]; then
needupdatechecksum="$needupdatechecksum $s"
fi
done
if [ "$needupdatechecksum" ]; then
md5sum $needupdatechecksum | sed -e 's| .*/| |' | sort -k 2
else
echo SKIP
fi
}
pkg_checksum() {
TMPCHECKSUM=$WORK_DIR/checksumstmp.$$
ORICHECKSUM=$WORK_DIR/checksumsori.$$
DIFCHECKSUM=$WORK_DIR/checksumsdiff.$$
if [ ! -f .checksums ]; then
msg "Generating .checksums..."
generatemdsum > .checksums
pkg_genchecksums
else
msg "Checking checksums..."
generatemdsum > "$TMPCHECKSUM"
sort -k2 .checksums > "$ORICHECKSUM"
diff -w -t -U 0 "$ORICHECKSUM" "$TMPCHECKSUM" > "$DIFCHECKSUM"
if [ "$IGNORE_MDSUM" != "yes" ] && [ "$IGNORE_MDSUM" != 1 ]; then
msg "Checking checksums..."
generatemdsum > "$TMPCHECKSUM"
sort -k2 .checksums > "$ORICHECKSUM"
diff -w -t -U 0 "$ORICHECKSUM" "$TMPCHECKSUM" > "$DIFCHECKSUM"
fi
fi
[ -s "$DIFCHECKSUM" ] && {
@@ -89,48 +90,38 @@ checkmdsum() {
[ "$mismatch" = 1 ] && abort 1
}
download_src() {
for FILE in $source; do
if echo $FILE | grep -Eq '::(http|https|ftp)://'; then
FILENAME=$(echo $FILE | awk -F '::' '{print $1}')
SRCURL=$(echo $FILE | awk -F '::' '{print $2}')
else
FILENAME=$(basename $FILE)
SRCURL=$FILE
fi
case $DOWNLOAD_PROG in
curl) DLCMD="curl -C - -L --fail --ftp-pasv --retry 3 --retry-delay 3 -o $SOURCE_DIR/$FILENAME.partial $CURL_OPTS" ;;
wget) DLCMD="wget -c --passive-ftp --no-directories --tries=3 --waitretry=3 --output-document=$SOURCE_DIR/$FILENAME.partial $WGET_OPTS" ;;
get_filepath() {
for i in $source; do
case $i in
*::*) echo $SOURCE_DIR/${i%::*};;
*://*) echo $SOURCE_DIR/${i##*/};;
*) echo $PWD/$i;;
esac
if [ "$FILENAME" != "$FILE" ]; then
if [ ! -f "$SOURCE_DIR/$FILENAME" ] || [ "$REDOWNLOAD_SOURCE" ]; then
[ "$REDOWNLOAD_SOURCE" ] && rm -f "$SOURCE_DIR/$FILENAME.partial"
if [ -f "$SOURCE_DIR/$FILENAME.partial" ]; then
msg "Resuming '$SRCURL'."
else
msg "Downloading '$SRCURL'."
fi
$DLCMD $SRCURL
if [ $? = 0 ]; then
[ "$REDOWNLOAD_SOURCE" ] && rm -f "$SOURCE_DIR/$FILENAME"
mv $SOURCE_DIR/$FILENAME.partial $SOURCE_DIR/$FILENAME
else
msgerr "Failed downloading '$FILENAME'."
abort 1
fi
fi
else
if [ ! -f "$FILENAME" ]; then
msgerr "Source '$FILENAME' not found."
abort 1
fi
fi
done
}
prepare_src() {
[ "$IGNORE_MDSUM" -o "$CHECK_MDSUM" = 0 ] || checkmdsum
pkg_fetch() {
for i in $source; do
case $i in
*::*) filepath="$SOURCE_DIR/${i%::*}"; url=${i#*::};;
*://*) filepath="$SOURCE_DIR/${i##*/}"; url=$i;;
*) continue;;
esac
[ -f "$filepath" ] && {
msg "Source found: $filepath"
continue
}
[ -f "$filepath.partial" ] && COPT="-C -"
msg "Fetching: $i"
curl $COPT -L --fail --ftp-pasv --retry 3 --retry-delay 3 -o $filepath.partial $CURL_OPTS $url || {
msgerr "Fetching failed: $i"
abort 1
}
mv $filepath.partial $filepath
done
}
pkg_unpack() {
SRC=$WORK_DIR/$name/src
PKG=$WORK_DIR/$name/pkg
@@ -140,83 +131,84 @@ prepare_src() {
mkdir -p $SRC $PKG
if [ "$source" ]; then
for FILE in $source; do
if echo $FILE | grep -Eq '::(http|https|ftp)://'; then
FILENAME=$SOURCE_DIR/$(echo $FILE | awk -F '::' '{print $1}')
elif echo $FILE | grep -Eq '^(http|https|ftp)://'; then
FILENAME=$SOURCE_DIR/$(basename $FILE)
else
FILENAME=$PWD/$(basename $FILE)
fi
for NOEXT in $noextract; do
if [ "$NOEXT" = "$(basename $FILENAME)" ]; then
nxt=1
break
fi
done
if [ "$FILENAME" != "$FILE" ] && [ "$nxt" != 1 ]; then
case $FILENAME in
*.tar|*.tar.gz|*.tar.Z|*.tgz|*.tar.bz2|*.tbz2|*.tar.xz|*.txz|*.tar.lzma|*.zip|*.rpm)
if [ $(type -p bsdtar) ]; then
COMMAND="bsdtar -p -o -C $SRC -xf $FILENAME"
else
COMMAND="tar -p -o -C $SRC -xf $FILENAME"
fi
MODE="Unpacking" ;;
*)
COMMAND="cp $FILENAME $SRC"
MODE="Preparing" ;;
esac
msg "$MODE '$(basename $FILENAME)'..."
$COMMAND || {
msgerr "$MODE '$FILENAME' failed."
abort 1
}
else
MODE="Preparing"
msg "$MODE '$(basename $FILENAME)'..."
cp "$FILENAME" "$SRC" || {
msgerr "$MODE '$FILENAME' failed."
TAR=tar
[ $(command -v bsdtar) ] && TAR=bsdtar
for i in $(get_filepath); do
if [ ! -f "$i" ]; then
msgerr "Source missing: $i"
abort 1
fi
for n in $noextract; do
if [ ${i##*/} = $n ]; then
msg "Preparing: $i"
cp $i $SRC || {
msgerr "Preparing failed: $i"
abort 1
}
continue 2
fi
unset nxt
done
fi
case $i in
*.tar|*.tar.gz|*.tar.Z|*.tgz|*.tar.bz2|*.tar.lz|*.tbz2|*.tar.xz|*.txz|*.tar.lzma|*.zip|*.rpm)
msg "Unpacking: $i"
$TAR -p -o -C $SRC -xf $i;;
*)
msg "Preparing: $i"
cp $i $SRC;;
esac
[ $? = 0 ] || {
msgerr "Unpacking/Preparing failed: $i"
abort 1
}
done
}
run_build() {
pkg_build() {
[ "$(id -u)" = 0 ] || {
msgerr "You must build package as root, or use fakeroot."
abort 1
}
msg "Start build '$name-$version-$release'."
[ "$MAKE_FLAGS" = 1 ] && export MAKEFLAGS || unset MAKEFLAGS
[ "$BUILD_FLAGS" = 1 ] && export CFLAGS CXXFLAGS || unset CFLAGS CXXFLAGS
msg "Build start: $name-$version-$release"
cd $SRC >/dev/null
(set -e -x; build 2>&1)
if [ "$QUIET" ]; then
(set -e -x; build) 2> /dev/null
else
(set -e -x; build 2>&1)
fi
if [ $? != 0 ]; then
msgerr "Build '$name-$version-$release' failed."
msgerr "Build failed: $name-$version-$release"
abort 1
else
msg "Build '$name-$version-$release' success."
msg "Build success: $name-$version-$release"
fi
cd - >/dev/null
}
removeemptydirs() {
find . -type d -empty -delete
}
removelibtool() {
find . ! -type d -name "*.la" -delete
pkglint() {
linterror=0
# cant package empty PKG
if [ ! "$(find $PKG/* -maxdepth 1 -type d 2>/dev/null)" ]; then
msgerr "PKG is empty"
abort 1
fi
# check for backup file
for f in $backup; do
if [ ! -f $PKG/$f ]; then
msgerr "Backup file '$f' does not exist in PKG!"
linterror=1
fi
done
if [ "$linterror" = 1 ]; then
abort 1
fi
}
strip_files() {
@@ -232,20 +224,20 @@ strip_files() {
find . -type f -printf "%P\n" 2>/dev/null | $FILTER | while read -r binary ; do
case "$(file -bi "$binary")" in
*application/x-sharedlib*) # Libraries (.so)
strip --strip-unneeded "$binary" 2>/dev/null ;;
${CROSS_COMPILE}strip --strip-unneeded "$binary" 2>/dev/null ;;
*application/x-pie-executable*) # Libraries (.so)
strip --strip-unneeded "$binary" 2>/dev/null ;;
${CROSS_COMPILE}strip --strip-unneeded "$binary" 2>/dev/null ;;
*application/x-archive*) # Libraries (.a)
strip --strip-debug "$binary" 2>/dev/null ;;
${CROSS_COMPILE}strip --strip-debug "$binary" 2>/dev/null ;;
*application/x-object*)
case "$binary" in
*.ko) # Kernel module
strip --strip-unneeded "$binary" 2>/dev/null ;;
${CROSS_COMPILE}strip --strip-unneeded "$binary" 2>/dev/null ;;
*)
continue;;
esac;;
*application/x-executable*) # Binaries
strip --strip-all "$binary" 2>/dev/null ;;
${CROSS_COMPILE}strip --strip-all "$binary" 2>/dev/null ;;
*)
continue ;;
esac
@@ -253,12 +245,12 @@ strip_files() {
}
compressinfomanpages() {
find . -type f -path "*/man/man*/*" | while read -r file; do
find . -type f -path "*/share/man/*" | while read -r file; do
if [ "$file" = "${file%%.gz}" ]; then
gzip -9 -f "$file"
fi
done
find . -type l -path "*/man/man*/*" | while read -r file; do
find . -type l -path "*/share/man/*" | while read -r file; do
FILE="${file%%.gz}.gz"
TARGET="$(readlink $file)"
TARGET="${TARGET##*/}"
@@ -269,35 +261,16 @@ compressinfomanpages() {
ln -sf $TARGET $FILE
fi
done
if [ -d usr/share/info ]; then
(cd usr/share/info
for file in $(find . -type f); do
if [ "$file" = "${file%%.gz}" ]; then
gzip -9 "$file"
fi
done
)
fi
}
backupconf() {
for FILE in $backup; do
if [ ! -f $FILE ]; then
msgerr "File '$FILE' not exist!"
abort 1
else
mv $FILE $FILE.spkgnew
find . -type f -path "*/share/info/*" | while read -r file; do
if [ "$file" = "${file%%.gz}" ]; then
gzip -9 -f "$file"
fi
done
}
packaging() {
for FILE in $INCLUDEINPKG; do
if [ -f $FILE ]; then
install -m644 $FILE $PKG/.pkg$FILE
addtotar="$addtotar .pkg$FILE"
fi
done
pkg_package() {
# lint $PKG before packaging
pkglint
cd $PKG >/dev/null
@@ -309,16 +282,28 @@ packaging() {
find usr/share/fonts \( -name fonts.dir -o -name fonts.scale \) -delete
}
# remove pseudo directories
#rm -fr dev sys proc run tmp
if [ "$KEEP_LIBTOOL" = 0 ] || [ "$KEEP_LIBTOOL" = "no" ]; then
find . ! -type d -name "*.la" -delete
fi
[ "$KEEP_EMPTYDIR" = 0 ] && removeemptydirs
[ "$KEEP_LIBTOOL" = 0 ] && removelibtool
[ "$STRIP_BINARY" = 1 ] && strip_files
[ "$ZIP_MAN" = 1 ] && compressinfomanpages
if [ "$KEEP_LOCALE" = 0 ] || [ "$KEEP_LOCALE" = "no" ]; then
rm -fr usr/share/locale usr/locale usr/lib/locale
fi
if [ "${#backup[@]}" -gt 0 ]; then
backupconf
if [ "$KEEP_DOC" = 0 ] || [ "$KEEP_DOC" = "no" ]; then
rm -fr usr/share/doc usr/share/gtk-doc usr/doc usr/gtk-doc
fi
if [ "$NO_STRIP" = 0 ] || [ "$NO_STRIP" = "no" ]; then
strip_files
fi
compressinfomanpages
if [ "$backup" ]; then
for FILE in $backup; do
mv $FILE $FILE.spkgnew
done
fi
[ "$FORCE_REBUILD" ] && rm -f "$PACKAGE_DIR/$PKGNAME"
@@ -327,114 +312,80 @@ packaging() {
xz) COMPRESS="-J" ;;
gz) COMPRESS="-z" ;;
bz2) COMPRESS="-j" ;;
lz4) COMPRESS="--lz4" ;;
zstd) COMPRESS="--zstd" ;;
esac
tar -c $COMPRESS -f $PACKAGE_DIR/$PKGNAME * $addtotar || {
rm -f $PACKAGE_DIR/$PKGNAME
msgerr "Packaging '$PKGNAME' failed."
msgerr "Packaging failed: $PKGNAME"
abort 1
}
tar -tvf $PACKAGE_DIR/$PKGNAME | sort -k 6
msg "Successfully created package '$PKGNAME'. ($(ls -lh $PACKAGE_DIR/$PKGNAME | awk '{print $5}'))"
msg "Packaging success: $PKGNAME ($(ls -lh $PACKAGE_DIR/$PKGNAME | awk '{print $5}'))"
cd - >/dev/null
[ -f .pkgfiles ] || generate_pkgfiles
if [ ! -f .pkgfiles ] || [ "$(head -n1 .pkgfiles)" != "$name-$version-$release" ]; then
pkg_genpkgfiles
fi
}
generate_pkgfiles() {
pkg_genpkgfiles() {
[ -f "$PACKAGE_DIR/$PKGNAME" ] || {
msgerr "Package '$PKGNAME' not found."
msgerr "Package not found: $PKGNAME"
exit 1
}
for i in $INCLUDEINPKG; do
excludefile="$excludefile --exclude=.pkg$i"
done
echo "$name-$version-$release" > .pkgfiles
msg "Generating .pkgfiles..."
tar -tvf "$PACKAGE_DIR/$PKGNAME" $excludefile \
| awk '{print $1,$2,$6}' \
| sed "s,lib/modules/$(uname -r),lib/modules/<kernelversion>,g" \
| sort -k 3 > .pkgfiles
tar -tvf "$PACKAGE_DIR/$PKGNAME" \
| awk '{$3=$4=$5=""; print $0}' \
| sort -k 3 >> .pkgfiles
msg "Pkgfiles updated."
}
cleanup() {
pkg_clean() {
[ -e "$PACKAGE_DIR/$PKGNAME" ] && {
msg "Removing $PACKAGE_DIR/$PKGNAME"
rm -f "$PACKAGE_DIR/$PKGNAME"
msg "Package removed: $PACKAGE_DIR/$PKGNAME"
}
for src in $source; do
if echo $src | grep -qE "::(ftp|http|https)://"; then
FILENAME=$SOURCE_DIR/$(echo $src | awk -F '::' '{print $1}')
elif echo $src | grep -qE "^(ftp|http|https)://"; then
FILENAME=$SOURCE_DIR/$(basename $src)
else
FILENAME=$src
fi
if [ -e "$FILENAME" ] && [ "$FILENAME" != "$src" ]; then
msg "Removing $FILENAME"
rm -f "$FILENAME"
fi
for i in $(get_filepath); do
case $i in
$PWD/*) continue;;
esac
[ -e "$i" ] && {
rm -f "$i"
msg "File removed: $i"
}
[ -e "$i.partial" ] && {
rm -f "$i.partial"
msg "File removed: $i.partial"
}
done
}
check_buildscript() {
# check the required field in buildscript
if [ -z "$name" ]; then
msgerr "'name' is empty!"
exit 1
elif [ "$(basename $(pwd))" != "$name" ]; then
msgerr "Port name and Directory name is different!"
exit 1
elif [ -z "$version" ]; then
msgerr "'version' is empty!"
exit 1
elif [ -z "$release" ]; then
msgerr "'release' is empty!"
exit 1
elif [ "$(type -t build)" != "function" ]; then
msgerr "'build' function not exist!"
exit 1
elif echo "$version" | grep -q '-'; then
msgerr "'version' should not contain '-'."
exit 1
elif echo "$release" | grep -q '-'; then
msgerr "'release' should not contain '-'."
exit 1
elif [ -z "$description" ]; then
msgerr "'description' cant empty."
exit 1
fi
}
set_options() {
for OPT in $OPTIONS $options; do
case $OPT in
libtool) KEEP_LIBTOOL=1 ;;
!libtool) KEEP_LIBTOOL=0 ;;
emptydirs) KEEP_EMPTYDIR=1;;
!emptydirs) KEEP_EMPTYDIR=0;;
strip) STRIP_BINARY=1 ;;
!strip) STRIP_BINARY=0 ;;
zipman) ZIP_MAN=1 ;;
!zipman) ZIP_MAN=0 ;;
buildflags) BUILD_FLAGS=1 ;;
!buildflags) BUILD_FLAGS=0 ;;
makeflags) MAKE_FLAGS=1 ;;
!makeflags) MAKE_FLAGS=0 ;;
checksum) CHECK_MDSUM=1 ;;
!checksum) CHECK_MDSUM=0 ;;
esac
done
[ "$name" ] || { msgerr "'name' is empty!"; exit 1; }
case $name in
*[A-Z]*) msgerr "Capital letters for port name are not allowed!"; exit 1;;
esac
[ "$(basename $(pwd))" = "$name" ] || { msgerr "Port name and Directory name is different!"; exit 1; }
[ "$version" ] || { msgerr "'version' is empty!"; exit 1; }
[ "$release" ] || { msgerr "'release' is empty!"; exit 1; }
[ "$(command -v build)" ] || { msgerr "'build' function not exist!"; exit 1; }
[ "$(echo "$version" | grep '-')" ] && { msgerr "'version' should not contain '-'."; exit 1; }
[ "$(echo "$release" | grep '-')" ] && { msgerr "'release' should not contain '-'."; exit 1; }
[ "$description" ] || { msgerr "'description' is empty!"; exit 1; }
}
checkdir() {
for DIR in "$@"; do
if [ ! -d $DIR ]; then
msgerr "Directory '$DIR' not exist."
msgerr "Directory '$DIR' does not exist."
exit 1
elif [ ! -w $DIR ]; then
msgerr "Directory '$DIR' not writable."
@@ -446,10 +397,10 @@ checkdir() {
done
}
clearworkdir() {
pkg_cleanup() {
if [ ! "$KEEP_WORK" ]; then
if [ "$name" ]; then
rm -fr $WORK_DIR/$name
rm -fr "$WORK_DIR/$name"
fi
fi
}
@@ -461,13 +412,14 @@ interrupted() {
abort() {
rm -f "$LOCK_FILE"
clearworkdir
pkg_cleanup
exit $1
}
parse_opts() {
while [ "$1" ]; do
case $1 in
-q | --quiet) QUIET=yes ;;
-i | --install) INSTALL_PKG=yes ;;
-u | --upgrade) UPGRADE_PKG=yes; OPTS="$OPTS $1" ;;
-r | --reinstall) REINSTALL_PKG=yes; OPTS="$OPTS $1" ;;
@@ -482,13 +434,8 @@ parse_opts() {
-p | --pkgfiles) GENPKGFILES=yes ;;
-h | --help) SHOWHELP=yes ;;
--clean) CLEANUP=yes ;;
--root=*) OPTS="$OPTS $1" ;;
--no-preinstall) OPTS="$OPTS $1" ;;
--no-postinstall) OPTS="$OPTS $1" ;;
--no-preupgrade) OPTS="$OPTS $1" ;;
--no-postupgrade) OPTS="$OPTS $1" ;;
--no-backup) OPTS="$OPTS $1" ;;
--redownload) REDOWNLOAD_SOURCE=yes ;;
--root=*) OPTS="$OPTS $1" ;;
--config=*) PKGBUILD_CONF="${1#*=}" ;;
--srcdir=*) CUSTOM_SOURCE_DIR="${1#*=}" ;;
--pkgdir=*) CUSTOM_PACKAGE_DIR="${1#*=}" ;;
@@ -505,6 +452,7 @@ Usage:
$(basename $0) [ <options> <arguments> ]
Options:
-q --quiet show only status messages and errors
-i, --install install package into system
-u, --upgrade upgrade package
-r, --reinstall reinstall package
@@ -523,12 +471,7 @@ Options:
--srcdir=<path> override directory path for sources
--pkgdir=<path> override directory path for compiled package
--workdir=<path> override directory path for working dir
--no-preinstall skip preinstall script before install package
--no-postinstall skip postinstall script after install package
--no-preupgrade skip preupgrade script before upgrade package
--no-postupgrade skip postupgrade script after upgrade package
--no-backup skip backup configuration file when upgrading package
--redownload re-download source file
EOF
}
@@ -549,13 +492,13 @@ extract_opts() {
echo $opts
}
main() {
main() {
parse_opts $(extract_opts "$@")
if [ -f "$PKGBUILD_CONF" ]; then
. "$PKGBUILD_CONF"
else
msgerr "Config file not found ('$PKGBUILD_CONF')"
msgerr "Config file not found: $PKGBUILD_CONF"
exit 1
fi
@@ -573,49 +516,46 @@ main() {
if [ -f "$PKGBUILD_BSCRIPT" ]; then
description=$(grep "^# description[[:blank:]]*:" $PKGBUILD_BSCRIPT | sed 's/^# description[[:blank:]]*:[[:blank:]]*//')
. ./$PKGBUILD_BSCRIPT
. ./$PKGBUILD_BSCRIPT
else
msgerr "'$PKGBUILD_BSCRIPT' file not found."
exit 1
fi
check_buildscript
set_options
case $COMPRESSION_MODE in
gz|bz2|xz) PKGNAME="$name-$version-$release.spkg.tar.$COMPRESSION_MODE" ;;
*) msgerr "Invalid compression mode. ($COMPRESSION_MODE)"; exit 1 ;;
gz|bz2|xz|lz4|zstd) PKGNAME="$name-$version-$release.spkg.tar.$COMPRESSION_MODE" ;;
*) msgerr "Invalid compression mode: $COMPRESSION_MODE"; exit 1 ;;
esac
# generate .pkgfiles
[ "$GENPKGFILES" ] && {
generate_pkgfiles
pkg_genpkgfiles
exit 0
}
# download source only
[ "$DOWNLOAD_ONLY" ] && {
download_src
pkg_fetch
exit 0
}
# extract source only
[ "$EXTRACT_ONLY" ] && {
download_src
prepare_src
pkg_unpack
exit 0
}
# update md5sum
[ "$UPDATE_MDSUM" ] && {
download_src
updatemdsum
pkg_genchecksums
exit 0
}
# remove source and package
[ "$CLEANUP" ] && {
cleanup
pkg_clean
exit 0
}
@@ -623,29 +563,41 @@ main() {
# check for lock file
[ -f "$LOCK_FILE" ] && {
msgerr "Cant build same package simultaneously."
msgerr "Cannot build same package simultaneously."
msgerr "remove '$LOCK_FILE' if no build process for '$name'."
exit 1
}
# create lock file
touch "$LOCK_FILE" 2>/dev/null || {
msgerr "Cant create lock file in '$LOCK_FILE'."
msgerr "Cannot create lock file in '$LOCK_FILE'."
exit 1
}
# build package
if [ -f "$PACKAGE_DIR/$PKGNAME" ] && [ ! "$FORCE_REBUILD" ]; then
if [ ! "$INSTALL_PKG" ] && [ ! "$REINSTALL_PKG" ] && [ ! "$UPGRADE_PKG" ]; then
echo "Package '$PKGNAME' is up-to-date."
msg "Package is up-to-date: $PKGNAME"
abort 0
fi
else
download_src
prepare_src
run_build
packaging
clearworkdir
if [ "$QUIET" ]; then
msg "Building: $name-$version-$release"
pkg_fetch 2> /dev/null
pkg_checksum > /dev/null
pkg_unpack > /dev/null
pkg_build > /dev/null
pkg_package > /dev/null
pkg_cleanup > /dev/null
else
msg "Building: $name-$version-$release"
pkg_fetch
pkg_checksum
pkg_unpack
pkg_build
pkg_package
pkg_cleanup
fi
fi
# install package
@@ -666,11 +618,11 @@ PKGBUILD_BSCRIPT="spkgbuild"
SOURCE_DIR="/var/cache/scratchpkg/sources"
PACKAGE_DIR="/var/cache/scratchpkg/packages"
WORK_DIR="/var/cache/scratchpkg/work"
DOWNLOAD_PROG="wget"
COMPRESSION_MODE="xz"
OPTIONS="!libtool emptydirs strip zipman buildflags makeflags checksum"
INCLUDEINPKG="install readme mkdirs"
NO_STRIP="no"
IGNORE_MDSUM="no"
KEEP_LIBTOOL="no"
KEEP_LOCALE="no"
KEEP_DOC="no"
main "$@"

View File

@@ -1,88 +0,0 @@
." Man page for pkgbuild
."
.TH pkgbuild 8 "" ""
.SH NAME
pkgbuild - package creator
.SH SYNOPSIS
pkgbuild <options>
.SH DESCRIPTION
\fIpkgbuild\fP is a tool to build package from ports. Is will source \fIspkgbuild\fP
to get build information before creating package. Package is created into
\fI<name>-<version>-<release>.spkg.tar.xz\fP format. To build package, you need
change into port directory before run \fIpkgbuild\fP command.
.SH OPTIONS
.TP
.B "-i, --install"
install package into system
.TP
.B "-u, --upgrade"
upgrade package
.TP
.B "-r, --reinstall"
reinstall package
.TP
.B "-c, --ignore-conflict"
ignore conflict when installing package
.TP
.B "-v, --verbose"
verbose install process
.TP
.B "-f, --force-rebuild"
rebuild package
.TP
.B "-m, --skip-mdsum"
skip md5sum checking
.TP
.B "-g, --genmdsum"
generate md5sum
.TP
.B "-o, --download"
download only source file
.TP
.B "-x, --extract"
extract only source file
.TP
.B "-w, --keep-work"
keep working directory
.TP
.B "-s, --silent"
print install message in simple format
.TP
.B "-h, --help"
show this help message
.TP
.B "--srcdir=<path>"
override directory path for sources
.TP
.B "--pkgdir=<path>"
override directory path for compiled package
.TP
.B "--no-prebuild"
skip prebuild script before build package
.TP
.B "--no-preinstall"
skip preinstall script before install package
.TP
.B "--no-postinstall"
skip postinstall script after install package
.TP
.B "--no-preupgrade"
skip preupgrade script before upgrade package
.TP
.B "--no-postupgrade"
skip postupgrade script after upgrade package
.TP
.B "--no-backup"
skip backup configuration file when upgrading package
.TP
.B "--redownload"
re-download source file
.SH AUTHOR
Emmett1 <emmett1.2miligrams@gmail.com>
.SH SEE ALSO
pkgadd(8), pkgdel(8), revdep(8)

106
pkgdel
View File

@@ -36,11 +36,11 @@ msg2() {
}
msgerr() {
echo "==> ERROR: $1"
echo "==> ERROR: $1" >&2
}
msgwarn() {
echo "==> WARNING: $1"
echo "==> WARNING: $1" >&2
}
help() {
@@ -51,8 +51,6 @@ Usage:
Options:
-h, --help show this help message
-v, --verbose print removed files
--no-preremove don't run pre-remove script
--no-postremove don't run post-remove script
--root=<path> remove package from custom root directory
EOF
@@ -74,7 +72,7 @@ extract_opts() {
echo $opts
}
parse_opts() {
parse_opts() {
if [ -z "$1" ]; then
SHOWHELP=yes
else
@@ -82,63 +80,62 @@ parse_opts() {
case $1 in
-h | --help) SHOWHELP=yes ;;
-v | --verbose) VERBOSE_REMOVE="-v" ;;
--no-preremove) NO_PREREMOVE=yes ;;
--no-postremove) NO_POSTREMOVE=yes ;;
--root=*) ROOT_DIR="${1#*=}" ;;
-*) msg "Invalid option: ($1)"; exit 1 ;;
*) RMNAME=$1 ;;
--root=*) ROOT_DIR="${1#*=}" ;;
-*) msg "Invalid option: ($1)"; exit 1 ;;
*) RMNAME=$1 ;;
esac
shift
done
fi
fi
}
ret() {
# remove lock file on exit
rm -f "$LOCK_FILE" "$reserve" "$dirs" "$remove" "$files"
rm -f "$ROOT_DIR/$LOCK_FILE"
exit $1
}
isinstalled() {
if [ -s "$INDEX_DIR/$1/.pkginfo" ] && grep -q "$1" "$INDEX_DIR/$1/.pkginfo"; then
if [ -s "$ROOT_DIR/$PKGDB_DIR/$1" ]; then
return 0
else
return 1
fi
}
command -v pkgadd >/dev/null 2>&1 || {
msgerr "'pkgadd' not found in \$PATH!"
exit 1
}
parse_opts $(extract_opts "$@")
INDEX_DIR="$ROOT_DIR/var/lib/scratchpkg/index"
LOCK_FILE="$ROOT_DIR/var/lib/scratchpkg/spkg.lock"
PKGDB_DIR="$(pkgadd --print-dbdir)"
PKGDB_DIR="${PKGDB_DIR##/}" # remove leading /
PKGDBPERMS_DIR="$PKGDB_DIR.perms"
LOCK_FILE="var/lib/scratchpkg/spkg.lock"
# disable pre/post remove script when remove from custom root location
if [ "$ROOT_DIR" != "" ]; then
NO_PREREMOVE=yes
NO_POSTREMOVE=yes
fi
# show help page
[ "$SHOWHELP" ] || [ -z "$RMNAME" ] && {
help
ret 0
}
# check for root access, non-root only allowed if use custom --root= location
[ "$(id -u)" = "0" ] || [ "$ROOT_DIR" ] || {
# check for root access
[ "$(id -u)" = "0" ] || {
echo "Removing package need root access!"
ret 1
}
# check for lock file
[ -f "$LOCK_FILE" ] && {
msgerr "Cant install/remove package simultaneously."
msgerr "remove '$LOCK_FILE' if no install/remove package process running."
[ -f "$ROOT_DIR/$LOCK_FILE" ] && {
msgerr "Cannot install/remove package simultaneously."
msgerr "remove '$ROOT_DIR/$LOCK_FILE' if no install/remove package process running."
exit 1
}
touch "$LOCK_FILE" 2>/dev/null || {
msgerr "Cant create lock file in '$LOCK_FILE'"
touch "$ROOT_DIR/$LOCK_FILE" 2>/dev/null || {
msgerr "Cannot create lock file in '$ROOT_DIR/$LOCK_FILE'"
exit 1
}
@@ -147,52 +144,25 @@ if ! isinstalled "$RMNAME"; then
ret 1
fi
name=$(grep ^name $INDEX_DIR/$RMNAME/.pkginfo | cut -d " " -f3-)
version=$(grep ^version $INDEX_DIR/$RMNAME/.pkginfo | cut -d " " -f3-)
release=$(grep ^release $INDEX_DIR/$RMNAME/.pkginfo | cut -d " " -f3-)
name=$RMNAME
version=$(head -n1 $ROOT_DIR/$PKGDB_DIR/$name | awk '{print $1}')
release=$(head -n1 $ROOT_DIR/$PKGDB_DIR/$name | awk '{print $2}')
if [ -z $name ] && [ -z $version ] && [ -z $release ]; then
msgerr "Package '$RMNAME' not installed but exist in database."
if [ -z "$version" ] && [ -z "$release" ]; then
msgerr "Package '$RMNAME' is not installed but exists in database."
ret 1
fi
# create list for reserve and remove (dirs and files)
reserve="/tmp/.pkgdel_reserve.$$"
remove="/tmp/.pkgdel_remove.$$"
dirs="/tmp/.pkgdel_dirs.$$"
files="/tmp/.pkgdel_files.$$"
grep '/$' $INDEX_DIR/*/.files | grep -v "$INDEX_DIR/$name" | awk -F : '{print $2}' | sort | uniq > "$reserve"
grep '/$' "$INDEX_DIR/$name/.files" > "$remove"
grep -Fxv -f "$reserve" "$remove" | tac > "$dirs"
grep -v '/$' "$INDEX_DIR/$name/.files" | tac >> "$files"
echo "remove: $name-$version-$release..."
# pre-remove script
if [ ! "$NO_PREREMOVE" ] && [ -f "$INDEX_DIR/$name/.pkginstall" ]; then
(cd "$ROOT_DIR"/
sh "$INDEX_DIR/$name/.pkginstall" pre-remove "$version"
)
fi
# remove files and dirs
(cd "$ROOT_DIR"/
[ -s $files ] && xargs -a $files -d'\n' rm $VERBOSE_REMOVE
[ -s $dirs ] && xargs -a $dirs -d'\n' rmdir $VERBOSE_REMOVE
)
rm -f "$reserve" "$dirs" "$remove" "$files"
# post-remove script
if [ ! "$NO_POSTREMOVE" ] && [ -f "$INDEX_DIR/$name/.pkginstall" ]; then
(cd "$ROOT_DIR"/
sh "$INDEX_DIR/$name/.pkginstall" post-remove "$version"
)
fi
tail -n+2 "$ROOT_DIR/$PKGDB_DIR"/$name | tac | while read -r line; do
case $line in
*/) grep "^$line$" "$ROOT_DIR/$PKGDB_DIR"/* 2>/dev/null | grep -qv "$ROOT_DIR/$PKGDB_DIR"/$name: || rmdir $([ "$VERBOSE_REMOVE" ] && echo -v) "$ROOT_DIR/$line";;
*) rm $([ "$VERBOSE_REMOVE" ] && echo -v) "$ROOT_DIR/$line";;
esac
done
# remove from database
rm -rf "$INDEX_DIR/$name"
rm -f "$ROOT_DIR/$PKGDB_DIR/$name"
rm -f "$ROOT_DIR/$PKGDBPERMS_DIR/$name"
# running ldconfig
if [ -x "$ROOT_DIR"/sbin/ldconfig ]; then

72
pkgdepends Executable file
View File

@@ -0,0 +1,72 @@
#!/bin/sh
#
# scratchpkg
#
# Copyright (c) 2018 by Emmett1 (emmett1.2miligrams@gmail.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#
# script to check shared libraries dependencies
#
get_libpath() {
ldd $1 2>/dev/null | grep $2 | awk '{print $3}'
}
scratch files $1 | while read -r line; do
case $line in
usr/share/gir-1.0/*.gir) extra_dep="$extra_dep gobject-introspection";;
usr/share/vala/vapi/*.vapi) extra_dep="$extra_dep vala";;
esac
case $line in
*/) continue;;
esac
case "$(file -bi /$line)" in
*application/x-sharedlib* | *application/x-executable* | *application/x-pie-executable*)
for NEEDED in $(objdump -x /$line | grep NEEDED | awk '{print $2}'); do
case $NEEDED in
libc.so|libc.so.6) continue;;
esac
[ "$NEEDED" ] || continue
[ -f /"$line" ] || continue
libs=$(get_libpath /$line $NEEDED)
[ "$libs" ] || continue
if ! echo $all_libs | grep -qw $libs; then
pkg=$(scratch provide $libs$ | awk '{print $1}' | head -n1)
case $pkg in
$1|gcc|glibc|musl) continue;;
esac
[ "$pkg" ] || continue
if ! echo $all_pkgs | grep -qw $pkg; then
echo $pkg
all_pkgs="$all_pkgs $pkg"
unset pkg
fi
all_libs="$all_libs $libs"
unset libs
fi
done ;;
esac
[ "$extra_dep" ] && {
for e in $extra_dep; do
if ! echo $all_pkgs | grep -qw $e; then
echo $e
all_pkgs="$all_pkgs $e"
fi
done
}
done
exit 0

346
pkgquery
View File

@@ -1,346 +0,0 @@
#!/bin/sh
#
# scratchpkg
#
# Copyright (c) 2018 by Emmett1 (emmett1.2miligrams@gmail.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
msg() {
echo "==> $1"
}
msgerr() {
msg "ERROR: $*"
}
msgwarn() {
msg "WARNING: $*"
}
msginst() {
echo "[i] $1"
}
msgmiss() {
echo "[m] $1"
}
msgnoinst() {
echo "[-] $1"
}
needarg() {
[ "$*" ] || {
msgerr "This operation required an arguments!"
exit 1
}
}
isinstalled() {
if [ -s "$INDEX_DIR/$1/.pkginfo" ] && [ "$(grep $1 $INDEX_DIR/$1/.pkginfo)" ]; then
return 0
else
return 1
fi
}
allinstalled() {
grep ^name "$INDEX_DIR"/*/.pkginfo | awk '{print $3}'
}
installed_pkg_info() {
if isinstalled $1; then
grep ^$2 "$INDEX_DIR/$1/.pkginfo" | cut -d " " -f3-
fi
}
getdepends() {
ppath=$(getportpath $1) || return 0
grep "^# depends[[:blank:]]*:" $ppath/$BUILD_SCRIPT \
| sed 's/^# depends[[:blank:]]*:[[:blank:]]*//' \
| tr ' ' '\n' \
| awk '!a[$0]++' \
| sed 's/,//'
}
getportpath() {
for repo in $REPO; do
if [ -f $repo/$1/$BUILD_SCRIPT ]; then
dirname $repo/$1/$BUILD_SCRIPT
return 0
fi
done
return 1
}
pkg_dependent() {
needarg $@
if [ "$(getportpath $1)" ]; then
grep -R "# depends[[:blank:]]*:" $REPO \
| sed "s,:# depends[[:blank:]]*:[[:blank:]]*,#|,;s, ,|,g;s,$,|,g" \
| grep "|$1|" \
| awk -F "#" '{print $1}' \
| rev \
| awk -F / '{print $2}' \
| rev
else
msgerr "Port '$1' not exist."
return 1
fi
}
pkg_orphan() {
tmpallpkg="/tmp/.pkgquery_allpkg.$$"
tmpalldep="/tmp/.pkgquery_alldep.$$"
for pkg in $(allinstalled); do
echo $pkg >> $tmpallpkg
dep="$dep $(getdepends $pkg)"
done
echo $dep | tr ' ' '\n' | sort | uniq > "$tmpalldep"
grep -xvF -f "$tmpalldep" "$tmpallpkg"
rm "$tmpalldep" "$tmpallpkg"
}
pkg_dup() {
dup=$(find $REPO -type d -print | grep -Exv "($(echo $REPO | tr ' ' '|'))" | \
rev | cut -d '/' -f1 | rev | sort | uniq -d)
if [ "$dup" ]; then
for dp in $dup; do
for repo in $REPO; do
[ -d $repo/$dp ] && echo "$repo/$dp"
done
done
else
msg "No duplicate ports found."
fi
}
pkg_foreign() {
for pkg in $(allinstalled); do
if ! getportpath $pkg >/dev/null; then
iname=$(installed_pkg_info $pkg name)
iversion=$(installed_pkg_info $pkg version)
irelease=$(installed_pkg_info $pkg release)
echo "$iname $iversion-$irelease"
fi
unset iname iversion irelease
done
}
pkg_search() {
needarg $@
arg=$*
for repo in $REPO; do
out=$(grep -R "# description" $repo | grep $BUILD_SCRIPT | grep "$arg" | awk -F : '{print $1}')
[ "$out" ] || continue
for line in $out; do
repo=$(echo $line | rev | awk -F / '{print $3}' | rev)
desc=$(grep "^# description[[:blank:]]*:" $line | sed 's/^# description[[:blank:]]*:[[:blank:]]*//')
name=$(grep "^name=" $line | awk -F = '{print $2}')
version=$(grep "^version=" $line | awk -F = '{print $2}')
release=$(grep "^release=" $line | awk -F = '{print $2}')
echo "($repo) $name $version-$release: $desc"
unset repo desc name version release
done
unset out
done
}
pkg_locked() {
for pkg in $(allinstalled); do
[ -f "$INDEX_DIR/$pkg/.lock" ] && echo "$pkg"
done
}
pkg_installed() {
for all in $(allinstalled); do
printf "%s" "$all "
grep -e ^version -e ^release $INDEX_DIR/$all/.pkginfo | awk '{print $3}' | tr '\n' '-' | sed 's:\-$::'
echo
done
}
pkg_missingdep() {
for pkg in $(allinstalled); do
if getportpath "$pkg" >/dev/null; then
depends=$(getdepends $pkg)
fi
if [ "$depends" ]; then
for d in $depends; do
if ! isinstalled $d; then
if [ -z "$msd" ]; then
msd="$d"
else
msd="$msd $d"
fi
fi
done
fi
[ "$msd" ] && echo "$pkg: $msd"
unset depends msd
done
}
pkg_info() {
needarg $@
ppath=$(getportpath $1) || return 1
. $ppath/$BUILD_SCRIPT
desc=$(grep "^# description[[:blank:]]*:" $ppath/$BUILD_SCRIPT | sed 's/^# description[[:blank:]]*:[[:blank:]]*//')
url=$(grep "^# homepage[[:blank:]]*:" $ppath/$BUILD_SCRIPT | sed 's/^# homepage[[:blank:]]*:[[:blank:]]*//')
maint=$(grep "^# maintainer[[:blank:]]*:" $ppath/$BUILD_SCRIPT | sed 's/^# maintainer[[:blank:]]*:[[:blank:]]*//')
deps=$(getdepends $1 | tr '\n' ' ')
echo "Name: $1"
echo "Path: $ppath"
echo "Version: $version"
echo "Release: $release"
echo "Description: $desc"
echo "Homepage: $url"
echo "Maintainer: $maint"
echo "Dependencies: $deps"
}
pkg_depends() {
needarg $@
if getportpath "$1" >/dev/null; then
depends=$(getdepends $1)
else
msgerr "Port '$1' not exist."
return 1
fi
for dep in $depends; do
if isinstalled $dep; then
msginst "$dep"
elif getportpath $dep >/dev/null; then
msgnoinst "$dep"
else
msgmiss "$dep"
fi
done
}
pkg_path() {
needarg $@
if PPATH=$(getportpath "$1"); then
echo "$PPATH"
else
msgerr "Port '$1' not exist."
return 1
fi
}
pkg_provide() {
needarg $@
arg=$(echo $1 | sed "s/^\///")
grep -R "$arg" $INDEX_DIR/*/.files \
| sed "s:$INDEX_DIR/::" \
| sed "s:/.files::" \
| tr : " " \
| column -t
}
pkg_readme() {
needarg $@
if PPATH=$(getportpath "$1"); then
if [ -f "$PPATH/readme" ]; then
cat "$PPATH/readme"
else
msgerr "Port '$1' does not have readme."
fi
else
msgerr "Port '$1' not exist."
exit 1
fi
}
pkg_files() {
needarg $@
if isinstalled $1; then
cat "$INDEX_DIR/$1/.files"
else
msg "Package '$1' not installed."
fi
}
pkg_cat() {
needarg $@
if PPATH=$(getportpath "$1"); then
cat "$PPATH/$BUILD_SCRIPT"
else
msgerr "Port '$1' not exist."
return 1
fi
}
pkg_help() {
cat << EOF
Usage:
$(basename $0) <options> [<arg>]
Options:
search <pattern> find ports in repo
cat <port> print spkgbuild
depends <port> print dependencies
dependent <port> print dependent
path <port> print path in repo
provide <files> print port's provided files
readme <port> print readme file, if exist
files <port> print files installed
info <port> print information
dup print duplicate ports in repo
installed print all installed ports
locked print loacked ports
missingdep print missing dependencies
orphan print orphan installed ports
foreign print foreign ports
help print this help msg
EOF
}
print_runhelp_msg() {
echo "Run '$(basename $0) help' to see available options."
exit 2
}
BUILD_SCRIPT="spkgbuild"
INDEX_DIR="/var/lib/scratchpkg/index"
REPO_FILE="/etc/scratchpkg.repo"
if [ -f "$REPO_FILE" ]; then
for repodir in $(grep -Ev '^(#|$)' "$REPO_FILE" | awk '{print $1}'); do
REPO="$REPO $repodir"
done
fi
opts=$1
if [ -z "$opts" ]; then
print_runhelp_msg
fi
shift
if [ $(type -t pkg_$opts) ]; then
pkg_$opts "$@"
else
print_runhelp_msg
fi
exit $?

51
pkgrebuild Executable file
View File

@@ -0,0 +1,51 @@
#!/bin/sh
#
# scratchpkg
#
# Copyright (c) 2018 by Emmett1 (emmett1.2miligrams@gmail.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#
# script to rebuild base packages in right toolchain order
#
LIST="/tmp/$(basename $0)-list"
touch $LIST
TOOLCHAIN="linux-api-headers glibc-pass1 binutils-pass1 gcc binutils glibc"
#scratch sync || exit 1
for tc in $TOOLCHAIN; do
if [ ! $(grep -x $tc $LIST) ]; then
pkgname="$(echo $tc | sed 's/-pass1//')"
scratch build -f $pkgname || exit 1
echo $tc >> $LIST
scratch install -r $pkgname --no-backup || exit 1
fi
done
for pkg in $(scratch deplist base | awk '{print $2}'); do
case $pkg in
linux-api-headers|musl|gcc|binutils|glibc) continue;;
esac
if [ ! $(grep -x $pkg $LIST) ]; then
scratch build -f $pkg || exit 1
echo $pkg >> $LIST
scratch install -r $pkg --no-backup || exit 1
fi
done
exit 0

46
portcreate Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/sh
#
# scratchpkg
#
# Copyright (c) 2018 by Emmett1 (emmett1.2miligrams@gmail.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
if [ -d "$1" ]; then
echo "ERROR: Directory '$1' already exist!"
exit 1
else
mkdir "$1"
echo "# description :
# homepage :
# depends :
name=$1
version=
release=1
noextract=\"\"
backup=\"\"
source=\"\"
build() {
cd \$name-\$version
./configure --prefix=/usr
make
make DESTDIR=\$PKG install
}" > "$1"/spkgbuild
echo "Template port have created for '$1'."
fi
exit 0

129
portsync Executable file
View File

@@ -0,0 +1,129 @@
#!/bin/sh
#
# scratchpkg
#
# Copyright (c) 2018 by Emmett1 (emmett1.2miligrams@gmail.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
cmp_copy() {
# usage:
# cmp_copy <source dir> <target dir>
#
reponame=${2##*/}
for p in $1/*; do
[ -d $p ] || continue
pname=${p##*/}
if [ ! -d $2/$pname ]; then
mkdir -p $2/$pname
for f in $p/* $p/.pkgfiles $p/.checksums; do
[ -f $f ] || continue
case $f in
*/update) continue;;
esac
fname=${f##*/}
echo "+ $reponame/$pname/$fname"
cp $f $2/$pname/$fname
done
else
for f in $p/* $p/.pkgfiles $p/.checksums; do
[ -f $f ] || continue
case $f in
*/update) continue;;
esac
fname=${f##*/}
cmp -s $f $2/$pname/$fname || {
echo "* $reponame/$pname/$fname"
cp $f $2/$pname/$fname
}
done
fi
done
for p in $2/*; do
[ -d $p ] || continue
pname=${p##*/}
for f in $p/* $p/.pkgfiles $p/.checksums; do
[ -f $f ] || continue
fname=${f##*/}
if [ ! -f $1/$pname/$fname ]; then
echo "- $reponame/$pname/$fname"
rm $2/$pname/$fname
fi
done
if [ ! -d $1/$pname ]; then
rmdir $2/$pname
fi
done
}
sync_repo() {
# usage:
# sync_repo <repo url> <ports dir>
#
url=$(echo $1 | cut -d / -f -5)
portdir=$2
case $1 in
*github.com/*)
branch=$(echo $1 | cut -d / -f 7)
repodir=$(echo $1 | cut -d / -f 8-);;
*gitlab.com/*)
branch=$(echo $1 | cut -d / -f 8)
repodir=$(echo $1 | cut -d / -f 9-);;
*) # will add more git service
branch=$(echo $1 | cut -d / -f 8)
repodir=$(echo $1 | cut -d / -f 9-);;
esac
# if branch not in the url, assume it master branch
[ "$branch" ] || branch=master
echo "fetching ports: $1"
# cloning ports repository
git clone -q -b $branch $url $tmprepo || {
echo " failed sync repo"
exit 1
}
# copying ports to port directory by comparing
cmp_copy $tmprepo/$repodir $portdir
# cleanup tmp cloned repo
rm -fr $tmprepo
echo "ports synced: $2"
}
tmprepo=/tmp/tmprepo
repo_file=/etc/scratchpkg.repo
if [ ! -e "$repo_file" ]; then
echo "missing repo file: $repo_file"
exit 1
fi
if [ "$(id -u)" != 0 ]; then
echo "this operation need root access."
exit 1
fi
grep -Ev '^(#|$)' "$repo_file" | awk '{print $1,$2}' | while read -r repodir repourl; do
if [ "$repodir" ] && [ "$repourl" ]; then
sync_repo $repourl $repodir
fi
done
exit 0

72
revdep
View File

@@ -114,7 +114,7 @@ rebuild() {
confirm "Continue rebuild & reinstall broken packages?" "Operation cancelled."
fi
for p in $order; do
scratch build -f $p && scratch install -r $p || { cleanup; exit 1; }
scratch install -fr $p || { cleanup; exit 1; }
done
fi
}
@@ -161,10 +161,43 @@ rev_exclude() {
EXCLUDED_LIBS=$(echo $EXCLUDE_LIBS | tr ' ' '\n' | sort | uniq)
}
check_pythonmodules() {
command -v python3 >/dev/null || return
pylibpath=$(python3 -c "import sys; print(':'.join(x for x in sys.path if x))" | tr ':' '\n' | sort | head -n1)
for i in /usr/lib/python3.*; do
[ -d "$i" ] || continue
[ "$i" = "$pylibpath" ] && continue
brokenpkg="$brokenpkg $(scratch provide $i/$ | awk '{print $1}')"
done
}
check_perlmodules() {
command -v perl >/dev/null || return
perlpath=$(dirname $(perl -V:sitearch | grep -o "'.*'" | sed "s/'//g"))
for i in $(dirname $perlpath)/*; do
[ "$perlpath" = "$i" ] && continue
brokenpkg="$brokenpkg $(scratch provide $i/$ | awk '{print $1}')"
done
}
check_rubygem() {
command -v gem >/dev/null || return
gempath=$(gem env gemdir)
for i in $(dirname $gempath)/*; do
[ "$gempath" = "$i" ] && continue
brokenpkg="$brokenpkg $(scratch provide $i/$ | awk '{print $1}')"
done
}
trap "interrupted" 1 2 3 15
command -v pkgadd >/dev/null 2>&1 || {
echo "'pkgadd' not found in \$PATH!"
exit 1
}
# package database directory
INDEX_DIR="/var/lib/scratchpkg/index"
PKGDB_DIR="$(pkgadd --print-dbdir)"
SEARCH_DIRS="/bin /usr/bin /sbin /usr/sbin /lib /usr/lib /lib64 /usr/lib64 /usr/libexec"
parse_opt $(extract_opts "$@")
@@ -174,7 +207,7 @@ if [ "$(id -u)" != 0 ] && [ "$REBUILD" = 1 ]; then
exit 1
fi
if [ "$PKG" ] && [ ! -f "$INDEX_DIR/$PKG/.files" ]; then
if [ "$PKG" ] && [ ! -f "$PKGDB_DIR/$PKG" ]; then
echo "ERROR: Package '$PKG' not installed"
cleanup
exit 1
@@ -249,7 +282,7 @@ if [ "$PKG" ]; then
filterdir=cat
fi
printf "Find '$PKG' files... "
sed 's/^/\//' $INDEX_DIR/$PKG/.files | grep $gx | $filterfile | $filterdir > $FILE_LIST
tail -n +2 $PKGDB_DIR/$PKG | sed 's/^/\//' | grep $gx | $filterfile | $filterdir > $FILE_LIST
else
printf "Find all files... "
find $SEARCH_DIRS $EXCLUDED_DIRS $EXCLUDED_FILES -type f \( -perm /+u+x -o -name '*.so' -o -name '*.so.*' \) -print 2> /dev/null | sort -u > $FILE_LIST
@@ -264,7 +297,7 @@ echo "Checking for broken linkage..."
while read -r line; do
count=$(( count + 1 ))
libname=$(basename "$line")
libname=${line##*/}
printf " $(( 100*count/total ))%% $libname\033[0K\r"
case "$(file -bi "$line")" in
*application/x-sharedlib* | *application/x-executable* | *application/x-pie-executable*)
@@ -275,13 +308,12 @@ while read -r line; do
NEW_LIB_NAME="$NEW_LIB_NAME $l"
fi
done
[ "$NEW_LIB_NAME" ] || continue
LIB_NAME=$NEW_LIB_NAME
[ "$LIB_NAME" ] || continue
PKG_NAME=$(echo $line | sed 's#^/##')
PKG_NAME=$(grep -Rx $PKG_NAME "$INDEX_DIR"/*/.files | cut -d : -f1)
PKG_NAME=${line#?} # remove leading slash
PKG_NAME=$(grep -Rx $PKG_NAME "$PKGDB_DIR"/* | awk -F : '{print $1}')
[ "$PKG_NAME" ] || continue
PKG_NAME=$(dirname $PKG_NAME)
PKG_NAME=$(basename $PKG_NAME)
PKG_NAME=${PKG_NAME##*/}
echo $expkg | tr ' ' '\n' | grep -qx $PKG_NAME && continue
REQ_LIB=$(objdump -p $line 2>/dev/null | grep NEEDED | awk '{print $2}' | tr '\n' ' ')
for i in $LIB_NAME; do
@@ -302,6 +334,24 @@ while read -r line; do
done < $FILE_LIST
printf "\033[0K"
[ "$PKG" ] || {
echo
echo "Checking for broken packages..."
check_pythonmodules
check_perlmodules
check_rubygem
}
if [ "$brokenpkg" ]; then
for i in $brokenpkg; do
if echo "$ALLPKG" | tr ' ' '\n' | grep -qx "$i"; then
continue
else
ALLPKG="$ALLPKG $i"
fi
done
fi
if [ "$ALLPKG" ]; then
echo
@@ -313,7 +363,7 @@ if [ "$ALLPKG" ]; then
rebuild
fi
else
echo "All packages is doing fine."
echo "All packages are doing fine."
fi
cleanup

942
scratch

File diff suppressed because it is too large Load Diff

9
scratchpkg.alias Normal file
View File

@@ -0,0 +1,9 @@
#
# /etc/scratchpkg.alias : scratchpkg alias file
#
# format:
# <real package> <aliased package>
#
# example:
# openssl libressl
#

View File

@@ -2,30 +2,17 @@
# Configuration file for scratchpkg
#
CFLAGS="-O2 -march=x86-64 -pipe"
CXXFLAGS="${CFLAGS}"
MAKEFLAGS="-j$(nproc)"
# export CFLAGS="-O2 -march=x86-64 -pipe"
# export CXXFLAGS="${CFLAGS}"
# export MAKEFLAGS="-j$(nproc)"
# SOURCE_DIR="/var/cache/scratchpkg/sources"
# PACKAGE_DIR="/var/cache/scratchpkg/packages"
# WORK_DIR="/var/cache/scratchpkg/work"
# DOWNLOAD_PROG="wget"
# WGET_OPTS=""
# CURL_OPTS=""
# COMPRESSION_MODE="xz"
#
# GLOBAL PACKAGE OPTIONS
#
# -- libtool: Keep libtool file (*.la) in packages
# -- emptydirs: Keep empty directories in packages
# -- strip: Strip symbols from binaries/libraries
# -- zipman: Compress manual (man and info) pages in MAN_DIRS with gzip
# -- buildflags: Enable buildflags (CFLAGS and CXXFLAGS)
# -- makeflags: Enable makeflags (MAKEFLAGS)
# -- checksum: Enable checking checksum
#
# -- These are default values for the options="" settings
# -- add '!' in front of this option to disable it
#
# OPTIONS="!libtool emptydirs strip zipman buildflags makeflags checksum"
# NO_STRIP="no"
# IGNORE_MDSUM="no"
# KEEP_LIBTOOL="no"
# KEEP_LOCALE="no"
# KEEP_DOC="no"

3
scratchpkg.mask Normal file
View File

@@ -0,0 +1,3 @@
#
# /etc/scratchpkg.mask : exclude packages from sysup
#

View File

@@ -20,8 +20,8 @@
EDITOR=${EDITOR:-vi}
type -p $EDITOR >/dev/null || {
echo "Editor '$EDITOR' not exist..."
command -v $EDITOR >/dev/null || {
echo "Editor '$EDITOR' not exist. Append 'EDITOR=<your editor>' to ${0##*/}."
exit 2
}

100
xchroot Executable file
View File

@@ -0,0 +1,100 @@
#!/bin/sh
#
# script to enter chroot
#
printhelp() {
cat << EOF
Usage:
$(basename $0) <chroot-dir> [command]
If 'command' is unspecified, ${0##*/} will launch /bin/sh.
EOF
}
msgerr() {
echo "ERROR: $*"
}
unmount() {
while true; do
mountpoint -q $1 || break
umount $1 2>/dev/null
done
}
[ "$(id -u)" = "0" ] || {
msgerr "$(basename $0) need root access!"
printhelp
exit 1
}
TARGET=$1
[ "$1" ] || {
msgerr "Please set directory for chroot!"
printhelp
exit 1
}
[ -d "$TARGET" ] || {
msgerr "Directory '$TARGET' not exist!"
printhelp
exit 1
}
shift
if [ ! "$1" ]; then
CMD="/bin/sh"
else
CMD=$*
fi
if [ -e /sys/firmware/efi/systab ]; then
EFI_SYSTEM=1
fi
mount --bind /dev $TARGET/dev
mount -t devpts devpts $TARGET/dev/pts -o gid=5,mode=620
mount -t proc proc $TARGET/proc
mount -t sysfs sysfs $TARGET/sys
if [ -n "$EFI_SYSTEM" ]; then
mount --bind /sys/firmware/efi/efivars $TARGET/sys/firmware/efi/efivars
fi
mount -t tmpfs tmpfs $TARGET/run
if [ -h $TARGET/dev/shm ]; then
mkdir -p $TARGET/$(readlink $TARGET/dev/shm)
fi
[ -f $TARGET/etc/resolv.conf ] && {
backupresolvconf=1
mv $TARGET/etc/resolv.conf $TARGET/etc/resolv.conf.tmp
}
cp -L /etc/resolv.conf $TARGET/etc
chroot "$TARGET" /usr/bin/env -i \
HOME=/root \
TERM="$TERM" \
PS1='\u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin $CMD
retval=$?
[ "$backupresolvconf" = 1 ] && {
mv $TARGET/etc/resolv.conf.tmp $TARGET/etc/resolv.conf
}
unmount $TARGET/dev/pts
unmount $TARGET/dev
unmount $TARGET/run
unmount $TARGET/proc
if [ -n "$EFI_SYSTEM" ]; then
unmount $TARGET/sys/firmware/efi/efivars
fi
unmount $TARGET/sys
exit $retval