aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xspm48
1 files changed, 26 insertions, 22 deletions
diff --git a/spm b/spm
index 6fcaf5c..672d819 100755
--- a/spm
+++ b/spm
@@ -89,20 +89,27 @@ spm_install() {
done
printf "\033[0K"
- touch "$SPMDIR/install.lock"
+ touch "$SPMDIR/install.lock"
+ rm -f "$SPMDIR"/*.list
# check if package is corrupt
msg "Verify package..."
tar -tvf "$1" > $SPMDIR/files.list 2>/dev/null || {
msg "Package '$1' is corrupted. Aborted."
- rm -f "$SPMDIR/files.list" "$SPMDIR/install.lock"
+ rm -f "$SPMDIR"/*.list "$SPMDIR/install.lock"
exit 1
}
# check conflicting files
msg "Checking for conflicts..."
- rm -f $SPMDIR/conflict.list
- awk '{print $6}' $SPMDIR/files.list | while read -r line; do
+ if [ "$upgrade" ]; then
+ tail -n+2 $PKGDB/$name > $SPMDIR/installed.list
+ awk '{print $6}' $SPMDIR/files.list | sed 's/\.new$//g' > $SPMDIR/files2.list
+ grep -Fxv -f $SPMDIR/installed.list $SPMDIR/files2.list > $SPMDIR/newfiles.list
+ else
+ awk '{print $6}' $SPMDIR/files.list | sed 's/\.new$//g' > $SPMDIR/newfiles.list
+ fi
+ cat $SPMDIR/newfiles.list | while read -r line; do
[ "$line" = "${line%.new}.new" ] && line=${line%.new}
# instant conflict if cross, mean file to directory and vice versa
case $line in
@@ -116,11 +123,7 @@ spm_install() {
esac
if [ -e "${SPM_ROOT%/}"/"$line" ]; then
case $line in */) continue;; esac # if directory not conflict
- if [ "$upgrade" ] && grep -qx "$line" $PKGDB/$name; then
- continue # if upgrade and exist in previous version then not conflict
- else
- echo "$line" >> $SPMDIR/conflict.list
- fi
+ echo "$line" >> $SPMDIR/conflict.list
fi
done
@@ -131,12 +134,11 @@ spm_install() {
echo "${p:-(none)}: $line"
done
msg "File conflict found. Enable 'SPM_FORCEINSTALL' env to force install."
- rm -f "$SPMDIR/conflict.list" "$SPMDIR/install.lock"
+ rm -f "$SPMDIR"/*.list "$SPMDIR/install.lock"
exit 1
fi
msg "$([ $upgrade ] && echo Upgrading || echo Installing) package..."
- rm -f $SPMDIR/install.list
tar -xvhpf "$1" -C "${SPM_ROOT%/}"/ | while read -r line; do
if [ "$line" = "${line%.new}.new" ]; then
line=${line%.new}
@@ -155,11 +157,10 @@ spm_install() {
tail -n+2 $name > $SPMDIR/old.list
grep -Fxv -f $SPMDIR/install.list $SPMDIR/old.list | tac | while read -r line; do
case $line in
- */) grep -x "$line" * | grep -v $name: >/dev/null || rmdir $([ "$SPM_VERBOSE" ] && echo '-v') "${SPM_ROOT%/}"/"$line";;
- *) rm $([ "$SPM_VERBOSE" ] && echo '-v') "${SPM_ROOT%/}"/"$line";;
+ */) grep -x "$line" * | grep -v $name: >/dev/null || rmdir $VERBOSE "${SPM_ROOT%/}"/"$line";;
+ *) rm $VERBOSE "${SPM_ROOT%/}"/"$line";;
esac
done
- rm -f "$SPMDIR/old.list"
cd - >/dev/null
fi
@@ -167,29 +168,29 @@ spm_install() {
mkdir -p $PKGDB
echo "$version-$release" > $PKGDB/$name
cat $SPMDIR/install.list >> $PKGDB/$name
- rm -f "$SPMDIR/install.list"
# permission
mkdir -p $PERMDIR $OWNDIR
rm -f "$PERMDIR/$name" "$OWNDIR/$name"
grep ^d $SPMDIR/files.list | awk '{print $1,$2,$6}' | while read -r perms owner dir; do
- [ "$perms" = "drwxr-xr-x" ] || echo "$(cvperms $perms) $dir" >> $PERMDIR/$name
+ if [ "$perms" != "drwxr-xr-x" ] && [ "$perms" != "drwxrwxr-x" ]; then
+ echo "$(cvperms $perms) $dir" >> $PERMDIR/$name
+ fi
[ "$owner" = "root/root" ] || echo "$owner $dir" | sed 's,/,:,' >> $OWNDIR/$name
done
- rm -f "$SPMDIR/files.list"
# correct dir permission
[ "$(ls -1 $PERMDIR)" ] && {
cat $PERMDIR/* | while read -r perms dir; do
[ -d "${SPM_ROOT%/}"/"$dir" ] || continue
- chmod $([ "$SPM_VERBOSE" ] && echo '-v') "$perms" "${SPM_ROOT%/}"/"$dir"
+ chmod "$perms" "${SPM_ROOT%/}"/"$dir"
done
}
# correct dir ownership
[ "$(ls -1 $OWNDIR)" ] && {
cat $OWNDIR/* | while read -r owner dir; do
[ -d "${SPM_ROOT%/}"/"$dir" ] || continue
- chown $([ "$SPM_VERBOSE" ] && echo '-v') "$owner" "${SPM_ROOT%/}"/"$dir"
+ chown "$owner" "${SPM_ROOT%/}"/"$dir"
done
}
@@ -197,7 +198,8 @@ spm_install() {
msg "Package '${pkgname%.spm}' $([ $upgrade ] && echo upgraded. || echo installed.)"
- rm -f "$SPMDIR/install.lock"
+ # remove lock file & temporary list files
+ rm -f "$SPMDIR/install.lock" "$SPMDIR"/*.list
exit 0
}
@@ -243,8 +245,8 @@ spm_remove() {
cd $PKGDB
tail -n+2 $1 | tac | while read -r line; do
case $line in
- */) grep -x "$line" * | grep -v $1: >/dev/null || rmdir $([ "$SPM_VERBOSE" ] && echo '-v') "${SPM_ROOT%/}"/"$line";;
- *) rm $([ "$SPM_VERBOSE" ] && echo '-v') "${SPM_ROOT%/}"/"$line";;
+ */) grep -x "$line" * | grep -v $1: >/dev/null || rmdir $VERBOSE "${SPM_ROOT%/}"/"$line";;
+ *) rm $VERBOSE "${SPM_ROOT%/}"/"$line";;
esac
done
@@ -305,6 +307,8 @@ if [ "$SPM_ROOT" ]; then
SPM_ROOT=$(realpath $SPM_ROOT)
fi
+[ "$SPM_VERBOSE" ] && VERBOSE=-v
+
HERE=$PWD
SPMDIR=$SPM_ROOT/var/lib/spm
PKGDB=$SPMDIR/db