mklni: Add update

This commit is contained in:
timoxa0 2024-11-02 23:41:18 +05:00
parent d8b2eb7f19
commit e209d0d746

39
mklni
View file

@ -70,12 +70,17 @@ arguments() {
chroot_into chroot_into
break 2 ;; break 2 ;;
update)
update
break 2 ;;
-r | -c | --cleanraw | --cleanup) -r | -c | --cleanraw | --cleanup)
run_makelni "$opt" run_makelni "$opt"
break ;; break 2 ;;
-h | -help | --help) -h | -help | --help)
usage ;; usage
break 2 ;;
*) *)
log "Unknown option: $opt" error log "Unknown option: $opt" error
@ -318,6 +323,7 @@ build()
cp "$lni" "$CHROOTDIR/tmp/lnibuild" cp "$lni" "$CHROOTDIR/tmp/lnibuild"
log "Entering build chroot"
prepare_chroot || { prepare_chroot || {
log "Failed to setup chroot" error log "Failed to setup chroot" error
exit 1 exit 1
@ -327,6 +333,7 @@ build()
local exitcode=$? local exitcode=$?
rm "$CHROOTDIR/tmp/lnibuild" rm "$CHROOTDIR/tmp/lnibuild"
log "Exiting build chroot"
detach_chroot || { detach_chroot || {
log "Failed to detach chroot" error log "Failed to detach chroot" error
exit 1 exit 1
@ -372,6 +379,34 @@ run_makelni()
return "$exitcode" return "$exitcode"
} }
update()
{
[ ! -d "$CHROOTDIR" ] && {
log "Chroot not installed" error
exit 1
}
prepare_chroot || {
log "Failed to setup chroot" error
exit 1
}
log "Updating makelni"
chroot "$CHROOTDIR" /bin/bash -c "cd /makelni && git pull"
local exitcode=$?
detach_chroot || {
log "Failed to detach chroot" error
exit 1
}
[ "$exitcode" -eq "0" ] || {
log "Failed to update makelni" error
}
return "$exitcode"
}
if [ "$(id -u)" != "0" ]; then if [ "$(id -u)" != "0" ]; then
log "$0 must be run as root" log "$0 must be run as root"
exit 3 exit 3