alterator-grub-0.9.8/000075500000000000000000000000001227025106700144625ustar00rootroot00000000000000alterator-grub-0.9.8/Makefile000064400000000000000000000010611227025106700161200ustar00rootroot00000000000000NAME=grub SHELL_LIBS=grub-disk grub-raid-boot grub-bootable grub-md-list CPPFLAGS = -std=gnu99 -Wall CFLAGS = -pipe -Wall -O2 LDLIBS = -ldevmapper bin_TARGETS = bin/devmap_name_grub TARGETS = $(bin_TARGETS) all: $(TARGETS) clean: install: install-module install-data install-lib include /usr/share/alterator/build/module.mak install-data: install -d $(libexecdir)/alterator/hooks/grub.d install-lib: for i in $(SHELL_LIBS);do install -Dpm644 bin/$$i $(bindir)/$$i; done cp -a -- $(bin_TARGETS) $(bindir); bin/devmap_name_grub: bin/devmap_name_grub.c alterator-grub-0.9.8/applications/000075500000000000000000000000001227025106700171505ustar00rootroot00000000000000alterator-grub-0.9.8/applications/grub.desktop000064400000000000000000000003541227025106700215040ustar00rootroot00000000000000[Desktop Entry] Type=Application Categories=X-Alterator-System Terminal=false Name=Grub Icon=grub X-Alterator-URI=/grub X-Alterator-Weight=20 X-Alterator-Help=grub Name[ru]=Загрузчик Grub Name[uk]=Завантажувач Grub alterator-grub-0.9.8/backend3/000075500000000000000000000000001227025106700161345ustar00rootroot00000000000000alterator-grub-0.9.8/backend3/grub000075500000000000000000000056641227025106700170340ustar00rootroot00000000000000#!/bin/sh alterator_api_version=1 . alterator-sh-functions . shell-config . grub-raid-boot . grub-disk . grub-bootable . grub-md-list # effects grub menu l18n if [ -n "$in_language" ]; then LANG="$in_language" else if [ -s /etc/sysconfig/i18n ]; then . /etc/sysconfig/i18n fi fi export LANG efi_dir="/boot/efi" gruboutput= make_gruboutput() { gruboutput=`mktemp --tmpdir grub.XXXXXXXXXX` \ || (write_error "$(_ "Can't create tempfile ")$gruboutput!"; return 1) if [ -z "$gruboutput" ] || [ ! -e "$gruboutput" ]; then write_error "$(_ "Can't create tempfile ")$gruboutput!" return 1 fi } make_grubcfg() { if ! grub-mkconfig -o /boot/grub/grub.cfg > $gruboutput 2>&1; then write_error "Can't create grub menu :`cat $gruboutput`" return 1 fi [ -f /_NEW_SYSTEM_ ] && cp -ab $gruboutput /tmp/grub.log ||: } write_efi() { make_gruboutput || return 1 if ! grub-install --uefi-secure-boot --recheck >> $gruboutput 2>&1; then write_error "$(_ "Can't install grub into $efi_dir: ")`cat $gruboutput`" return 1 fi make_grubcfg } read_device() { if [ -d "/sys/firmware/efi" -a -d "$efi_dir" ]; then write_enum_item "efi" "$(_ "EFI")" fi list_bootloader_places write_enum_item "none" "$(_ "Skip bootloader install")" } write_device() { make_gruboutput || return 1 # fallback: BIOS bootloader installation when booted in EFI mode if [ -d "/sys/firmware/efi" ]; then target="--target=i386-pc" fi bootdev="`readlink -e $1`" if [ -z "$bootdev" ]; then write_error "$(_ "No device for install given!")" return 1 fi raid_members=$(grub_md_list "${bootdev#/dev/}" 2>/dev/null) [ -z "$raid_members" ] || bootdev=$raid_members tout=`mktemp` GRUB_FORCE="no" GRUB_DEV= for dev in $bootdev; do GRUB_DEV="$dev $GRUB_DEV" grub-install $target "$dev" >> $gruboutput 2>&1 if [ $? -ne 0 ]; then if grep blocklists $gruboutput; then GRUB_FORCE="yes" grub-install $target "$dev" --force >> $gruboutput 2>&1 if [ $? -ne 0 ]; then write_error "$(_ "Can't install grub on ")$dev$(_ " even using blocklists :")`cat $gruboutput`" return 1 fi else write_error "$(_ "Can't install grub on ")$dev :`cat $gruboutput`" return 1 fi fi set_bootable_flag "$dev" done if ! grep "^GRUB_AUTOUPDATE_DEVICE=" /etc/sysconfig/grub2 > /dev/null 2>&1; then echo "GRUB_AUTOUPDATE_DEVICE='$GRUB_DEV'" >> /etc/sysconfig/grub2 else sed -i "s|GRUB_AUTOUPDATE_DEVICE=.*|GRUB_AUTOUPDATE_DEVICE='$GRUB_DEV'|" /etc/sysconfig/grub2 fi if ! grep "^GRUB_AUTOUPDATE_FORCE=" /etc/sysconfig/grub2 > /dev/null 2>&1; then echo "GRUB_AUTOUPDATE_FORCE='$GRUB_FORCE'" >> /etc/sysconfig/grub2 else sed -i "s|GRUB_AUTOUPDATE_FORCE=.*|GRUB_AUTOUPDATE_FORCE='$GRUB_FORCE'|" /etc/sysconfig/grub2 fi make_grubcfg } on_message() { case "$in_action" in read) read_device ;; write) case "$in_device" in "none") ;; "efi") write_efi ;; *) write_device "$in_device" "$in_runhooks" ;; esac esac } message_loop alterator-grub-0.9.8/bin/000075500000000000000000000000001227025106700152325ustar00rootroot00000000000000alterator-grub-0.9.8/bin/devmap_name_grub.c000064400000000000000000000067631227025106700207050ustar00rootroot00000000000000/* * Copyright (c) 2004, 2005 Christophe Varoqui * Copyright (C) 2007 Alexey Gladkov */ #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #define setprogname(pn) extern const char *__progname; static int quiet = 0; static int verbose = 0; /* rc = 0 - OK rc = 1 - ERROR rc = 2 - not block device rc = 3 - not devmapper device */ static void __attribute__((__format__(printf,1,2))) message(const char *fmt, ...) { va_list ap; if (quiet) return; va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); } static void __attribute__((noreturn)) print_help(int ret) { printf("Usage: %s [OPTIONS] (DEVICE|MAJOR:MINOR)...\n", __progname); printf("\n"); printf("Convert devmapper device names to real device names.\n"); printf("Normally, exit status is 0 and greater than 0 otherwise.\n"); printf("\n"); printf("Options:\n"); printf(" -t, --target=TYPE .\n"); printf(" -v, --verbose explain what is being done.\n"); printf(" -V, --version print program version and exit.\n"); printf(" -h, --help output a brief help message.\n"); printf("\n"); exit(ret); } static int dm_target_type(int major, int minor, char *type) { struct dm_task *dmt; void *next = NULL; uint64_t start, length; char *target_type = NULL, *params; int r = EXIT_FAILURE; if (!(dmt = dm_task_create(DM_DEVICE_STATUS))) return EXIT_FAILURE; if (!dm_task_set_major(dmt, major) || !dm_task_set_minor(dmt, minor)) goto bad; dm_task_no_open_count(dmt); if (!dm_task_run(dmt)) goto bad; if (!type) goto good; do { next = dm_get_next_target(dmt, next, &start, &length, &target_type, ¶ms); if (target_type && strcmp(target_type, type)) goto bad; } while (next); good: printf("%s\n", dm_task_get_name(dmt)); r = EXIT_SUCCESS; bad: dm_task_destroy(dmt); return r; } int main(int argc, char **argv) { int c; int rc = EXIT_SUCCESS; char *type = NULL; static struct option long_options[] = { {"target", 1, 0, 't'}, {"help", 0, 0, 'h'}, {"version", 0, 0, 'V'}, {"verbose", 0, 0, 'v'}, {"quiet", 0, 0, 'q'}, {0, 0, 0, 0} }; setprogname(argv[0]); while (1) { int option_index = 0; c = getopt_long (argc, argv, "qvht:", long_options, &option_index); if (c == -1) break; switch (c) { case 't': type = optarg; break; case 'q': quiet = 1; break; case 'v': verbose = 1; break; default: case 'h': print_help(EXIT_SUCCESS); break; } } if (optind == argc) { fprintf (stderr, "Fatal: more arguments required\n"); print_help(EXIT_FAILURE); } while (optind < argc) { int trc; uint32_t major = 0, minor = 0; char *arg = argv[optind++]; struct stat st; if (!stat(arg, &st)) { if (!S_ISBLK(st.st_mode)) { message("%s: %s: not block device\n", __progname, arg); rc = 2; continue; } major = major(st.st_rdev); minor = minor(st.st_rdev); } else if (2 != sscanf(arg, "%i:%i", &major, &minor)) print_help(EXIT_FAILURE); if (!major && !minor) print_help(EXIT_FAILURE); if (!dm_is_dm_major(major)) { message("%s: %s: not devmapper device\n", __progname, arg); rc = 3; continue; } if ((trc = dm_target_type((int) major, (int) minor, type)) != EXIT_SUCCESS) rc = trc; } return rc; } alterator-grub-0.9.8/bin/grub-bootable000064400000000000000000000023261227025106700177040ustar00rootroot00000000000000# Print device name of partition on specified disk with bootable flag set. # If there is no partitions marked as bootable on this disk - print "" get_bootable_flag(){ local disk=$1 local dev= local boot= local x= /sbin/sfdisk -l 2>/dev/null | grep '^/dev' | \ while read dev boot x; do [ "$boot" = "*" -a "${dev#$disk}" != "$dev" ] && echo $dev done } # Set bootable flags of partitions for the bootloader on specified device. # - if device is a primary partition and there is no partitions # marked as bootable on this disk -- this partition will be marked bootable # - if device is a disk and and there is no partitions marked as # bootable on this disk -- the first partition of the disk will be marked # bootable # - if device is raid -- above steps will be done for each raid member. set_bootable_flag() { local bootdev="$1" local dev= for dev in $bootdev; do local disk=${dev%%[0-9]*} local num=${dev##*[^0-9]} # do nothing if bootable flag is already set somewere in this disk [ -z "$(get_bootable_flag $disk)" ] || continue # if boot device is disk or extended partition - set bootable flag # for first partition [ -n "$num" -a "$((num < 5))" = 1 ] || num=1 /sbin/sfdisk $disk -A$num done } alterator-grub-0.9.8/bin/grub-disk000064400000000000000000000037201227025106700170460ustar00rootroot00000000000000#!/bin/bash # functions for getting hardware information for alterator-lilo # * places for bootloader (list_bootloader_places, get_default_boot_dev) # * ... # for localized lists set # dec_pt=$(LC_NUMERIC="$in_language" locale decimal_point) . alterator-sh-functions . alterator-hw-functions . grub-raid-boot quote_udevadm_out='s|^\([^=]\+\)=\(.*\)|\1="\2"|' LILO_DESTDIR="${LILO_DESTDIR:-}" list_bootloader_places(){ detect_raidroot if [ -n "${raidboot:-}" ]; then write_enum_item "$raidboot" "$(_ "RAID") (${raidboot#/dev/})" return 0 fi for i in $(disk_list); do ! disk_is_root "$i" || continue ! disk_is_virtual "$i" || continue ! [ -z `echo "$i" | sed -e 's/^sr[0-9]*//'` ] || continue ! [ -z `echo "$i" | sed -e 's/^fd[0-9]*//'` ] || continue local info="$(disk_info "$i")" unset DEVNAME eval $(/sbin/udevadm info --name=$i --query=env 2>/dev/null | sed -e "$quote_udevadm_out") local size="$(disk_size "$i")" size="$(human_readable_size "$size")" DEVNAME="${DEVNAME:-/dev/$i}" # on 2.6.24 udevadm will fail local sym="$(blockdev_get_symlink "${DEVNAME:-/dev/$i}")" write_enum_item "$sym" "$(_ "Hard drive") ${DEVNAME##*/}${info:+, $info}${size:+, $size}" done local bootdev="$(get_part_with_mntpt "/boot")" local rootdev="$(get_part_with_mntpt "/")" local dev=${bootdev:-$rootdev} [ -z "$dev" ] || write_enum_item "$(blockdev_get_symlink $dev)" "$(_ "Linux partition") (${dev#/dev/})" } get_part_with_mntpt(){ local target="$1" local dev mntpt type opts n1 n2 while read dev mntpt type opts n1 n2; do [ "$dev" = "${dev#\#}" ] || continue [ "$mntpt" = "$target" ] || continue [ "$type" != "rootfs" -a "$type" != "squashfs" ] || continue if [ "${dev%UUID=*}" != "$dev" ]; then for d in $(/sbin/blkid -t "$dev" -s UUID | cut -d' ' -f1); do d="${d%:}" ! disk_is_virtual "${d#/dev/}" || [ -z "${d##/dev/md*}" ] || continue dev="$d" break done fi readlink -f "$dev" done < "$LILO_DESTDIR/etc/fstab" } alterator-grub-0.9.8/bin/grub-md-list000064400000000000000000000026141227025106700174660ustar00rootroot00000000000000#!/bin/sh -eu # ***** BEGIN LICENSE BLOCK ***** # * Copyright (C) 2007 Alexey Gladkov # * # * 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 2 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, write to the Free Software # * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. # ***** END LICENSE BLOCK ***** . shell-error grub_md_list(){ md_device="${1#/dev/}" [ -d "/sys/block/$md_device" ] || return [ -d "/sys/block/$md_device/md" ] || return cd "/sys/block/$md_device/md" for devname in dev-*; do [ -d "$devname" ] || break dev="/dev/${devname#dev-}" if realdev="/dev/$(devmap_name_grub -q "$dev")"; then if [ ! -b "$realdev" ]; then printf 'Error: %s: not block device\n' "$realdev" >&2 continue fi printf %s\\n "${realdev%%[0-9]*}" else rc=$? [ "$rc" -ne 3 ] || printf %s\\n "${dev%%[0-9]*}" fi done } alterator-grub-0.9.8/bin/grub-raid-boot000064400000000000000000000031351227025106700177740ustar00rootroot00000000000000# ***** BEGIN LICENSE BLOCK ***** # * Copyright (C) 2007 Alexey Gladkov # * # * 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 2 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, write to the Free Software # * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. # ***** END LICENSE BLOCK ***** raidtypes= raidboot= detect_raidroot() { local raid_list= bootdev= md= mddev= uuid= boot_uuid= raidtypes="$(sed -ne 's/^md.* \<\(raid[[:alnum:]]\+\)\>.*/\1/p' /proc/mdstat|sort -u)" [ -n "$raidtypes" ] || return 0 raid_list="$(sed -ne 's,^\(md[^[:space:]]\+\) :.*,\1,p' /proc/mdstat |sort)" [ -n "$raid_list" ] || return 0 bootdev=$(get_part_with_mntpt "/") [ -n "$bootdev" ] || return 0 boot_uuid="$(blkid -c /dev/null -w /dev/null -o value -s UUID "$bootdev" 2>/dev/null)" || return 0 for md in $raid_list; do [ -e "/dev/$md" ] && uuid="$(blkid -c /dev/null -w /dev/null -o value -s UUID "/dev/$md" 2>/dev/null)" && [ "$boot_uuid" = "$uuid" ] || continue mddev="$md" done if [ -n "$mddev" ]; then raidboot="/dev/$mddev" fi } alterator-grub-0.9.8/steps/000075500000000000000000000000001227025106700156205ustar00rootroot00000000000000alterator-grub-0.9.8/steps/grub.desktop000064400000000000000000000003601227025106700201510ustar00rootroot00000000000000[Desktop Entry] Type=Application Terminal=false Icon=steps/lilo Name=Bootloader setup Name[ru]=Установка загрузчика Name[uk]=Встановлення завантажувача X-Alterator-URI=/grub X-Alterator-Help=grub alterator-grub-0.9.8/ui/000075500000000000000000000000001227025106700150775ustar00rootroot00000000000000alterator-grub-0.9.8/ui/grub/000075500000000000000000000000001227025106700160365ustar00rootroot00000000000000alterator-grub-0.9.8/ui/grub/ajax.scm000064400000000000000000000006711227025106700174710ustar00rootroot00000000000000(define-module (ui grub ajax) :use-module (alterator ajax) :use-module (alterator woo) :export (init)) (define (ui-read) (form-update-enum "device" (woo-read "/grub"))) (define (ui-write) (catch/message (lambda() (woo-write "/grub" 'language (form-value "language") 'device (form-value "device"))))) (define (init) (ui-read) (form-bind "submit" "click" ui-write) (form-bind "reset" "click" ui-read)) alterator-grub-0.9.8/ui/grub/index.html000064400000000000000000000011741227025106700200360ustar00rootroot00000000000000
 
Device:
 
   
alterator-grub-0.9.8/ui/grub/index.scm000064400000000000000000000020161227025106700176500ustar00rootroot00000000000000(document:surround "/std/frame") (define (ui-init) (ui-read) (or (global 'frame:next) (form-bind "submit" "click" ui-write)) (or (global 'frame:next) (form-bind "reset" "click" ui-read))) (define (ui-read) (form-update-enum "device" (woo-read "/grub"))) (define (ui-write) (catch/message (lambda() (woo-write "/grub" 'language (form-value "language") 'device (form-value "device"))))) (gridbox columns "0;100" margin 20 (label name "device" align "right" text (_ "Device:")) (combobox name "device" focus #t) (label colspan "2") (spacer) (hbox align "left" (if (global 'frame:next) (spacer) (button name "submit" text (_ "Install"))) (label text " ") (if (global 'frame:next) (spacer) (button name "reset" text (_ "Reset"))))) (frame:on-back (thunk (or (ui-write) 'cancel))) (frame:on-next (thunk (or (ui-write) 'cancel))) (document:root (when loaded (ui-init) (and (global 'frame:next) (frame:back-activity #f))))