alphainst.sh

Post your comments, questions, bug reports or suggest new features for alphaOS
Aspi
Advanced
Posts: 40
Joined: 21 Apr 2014, 11:32

alphainst.sh

Postby Aspi » 22 Apr 2014, 22:28

alphainst.sh 0.19
https://rof.li/p/1432

Installer for alphaOS, using GPT, FAT32 and SYSLINUX. It is not compatible with Windows <8, but why would you be here if it should? :)
Feel free to hack it any way you'd like, it's released under the GPL.

if the paste site should go down:

Code: Select all

#!/usr/bin/bash

# -------------------------------
# ----------- License -----------
# -------------------------------
# @licstart
# Copyright (C) 2014  Free Software Foundation, Inc
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
#
# 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 may have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# @licend
# -------------------------------
# ----------- License -----------
# -------------------------------

# -------------------------------
# ------------ TODO -------------
# -------------------------------
# - implement UEFI booting
# - os probing (os-prober http://anonscm.debian.org/gitweb/?p=d-i/os-prober.git;a=blob_plain;f=README;hb=HEAD)
# - create drop-down field (yad --text-info --tail --listen) showing console output (`script`)
# - uuidgen for sgdisk? so one is certain about the UUID the newly created partition has been assigned
# - make partition selection dialog only contain partitions of selected disk
#   must be dynamic. ie. when one changes install disk choice, available partitions must be updated
#     compatible with loop devs?
# - validate more shizz
# - maybe make it more suited to install to UEFI without cleaning disk
# - maybe move to UUIDs?
# - would be nice to migrate yad lists to --list. but it seems yad supports opnly one list per dialog.
# - aesthetics :)
# -------------------------------
# ------------ TODO -------------
# -------------------------------

# -------------------------------
# ------------ Init -------------
# -------------------------------
# read local functions
. /etc/rc.d/functions
. /etc/os-release
# -------------------------------
# ------------ Init -------------
# -------------------------------

# -------------------------------
# ---------- Variables ----------
# -------------------------------
version='0.19'
# format: 'package:file-to-test-for another-package:file-tested-with-which-command'
dependencies='gptfdisk:sgdisk syslinux:syslinux dosfstools:mkfs.fat mtools:mtools'

installDisk=
rootMount='/mnt/inst'
rootPart=
alphaOSDir='/alphaos.usb'
alphaOSInstPath="${rootMount}${alphaOSDir}"
biosPart=
ESPMount='/mnt/boot/efi'
ESP=
syslinuxCfgDir='/boot/syslinux'
syslinuxCfgPath="${rootMount}${syslinuxCfgDir}"
syslinuxCfgFile="${syslinuxCfgPath}/syslinux.cfg"

alphaOSSrcDir='/mnt/live/memory/data/alphaos'
if [ ! -d "${alphaOSSrcDir}" ]; then
    alphaOSSrcDir='/mnt/home/alphaos'
fi
# try drastic methods to find alphaOS files
if [ ! -d "${alphaOSSrcDir}" ]; then
    findOut="$(find /mnt/live/memory/data/ -name alpha_${VERSION}.sb | head -n 1)"
    if [ -n "${findOut}" ]; then
        alphaOSSrcDir="${findOut%/*}"
    fi
fi
# 4 required files, and empty modules dir
alphaOSFiles=("/alpha_${VERSION}.sb" "/extra_${VERSION}.sb" '/boot/initrfs.img' '/boot/vmlinuz' '/modules/')

# dialog
dialog="$(which yad)"
# YAD
dtitle="--title=${0##*/}"
# need to run fixed, as YAD behaves weirdly, adding lots of newlines.
dsettings='--center --fixed --borders=8 --always-print-result --selectable-labels --window-icon=drive-harddisk'
dialog="${dialog} ${dtitle} ${dsettings}"
dyescode=90
dyes="--button=gtk-yes:${dyescode}"
dnocode=91
dno="--button=gtk-no:${dnocode}"
dokcode=92
dok="--button=gtk-ok:${dokcode}"
dhomecode=98
dhome="--button=gtk-home:${dhomecode}"
dquitcode=99
dquit="--button=gtk-quit:${dquitcode}"
# -------------------------------
# ---------- Variables ----------
# -------------------------------

# -------------------------------
# ---------- Functions ----------
# -------------------------------

# console echo functions
# $1 = msgtype, see below
# $2 = msg
cinform () {
    # process msgtype
    local prefixColour
    case ${1} in
        header) prefixColour=${BGreen};;
        info) prefixColour=${BWhite};;
        warning) prefixColour=${BYellow};;
        error) prefixColour=${BRed};;
        *) prefixColour=${BWhite};;
    esac
   
    echo -e ${prefixColour}'==> '${BWhite}"${2}"${Color_Off}
}

# dialog functions
# $@ = msg[ additional parameters]
dinform () {
    ${dialog} ${dok} --text="${1}"
    return ${?}
}

# $@ = msg[ additional parameters]
dwarn () {
    ${dialog} --image='dialog-warning' ${dok} --text="${@}"
}

# $@ = msg[ additional parameters]
derror () {
    ${dialog} --image='dialog-error' ${dok} --text="${@}"
}

# $@ = [warn ]msg[ additional parameters]
dask () {   
    # will we warn, respectively?
    local img
    local btnParams
    # default to just ask
    img='dialog-question'
    btnParams="${dyes} ${dno}"
    if [ "${1}" = 'warn' ]; then
        img='dialog-warning'
        btnParams="${dno} ${dyes}"
        shift
    fi
   
    ${dialog} --image=${img} ${btnParams} --text="${@}"
    return ${?}
}

priv_check () {
if [ ${EUID} -ne 0 ]; then
    cinform error "This script must be run as root. Type in 'su -c ${0}' to run it as root."
    if [ -n "${dialog}" ]; then
        dinform "This script must be run as root.\nType 'su -c ${0}' in a terminal to run it as root."
    fi
    exit 1
fi
}

escape_for_sed () {
#~ # sed it like a boss \/
#~ echo $(echo ${1} | sed -e 's/\//\\\\\//g')
# sed it like a pro -.- ~https://stackoverflow.com/questions/407523/escape-a-string-for-a-sed-replace-pattern
echo $(echo ${1} | sed -e 's|[/&]|\\&|g')
}

dep_ensure () {
cinform header 'checking dependencies'

pkg=
prog=
pkgToInstall='BOGUS-START-VALUE'

# cannot proceed as long as dependencies are not met
while [ -n "${pkgToInstall}" ]; do
    # check if dependencies are met
    pkgToInstall=
    for dep in ${dependencies}; do
        pkg=$(echo ${dep} | cut -d ':' -f 1)
        prog=$(echo ${dep} | cut -d ':' -f 2)
       
        which ${prog} > /dev/null
        if [ "${?}" = 1 ]; then
            pkgToInstall+=" ${pkg}"
        fi
    done
   
    # install if anything to install
    if [ -n "${pkgToInstall}" ]; then
        cinform warning "missing${pkgToInstall}"
        # update pacman cache if we have to
        if [ ! -f /var/lib/pacman/sync/community.db ]; then
            pacman -Sy
        fi
        pacman -S ${pkgToInstall}
       
        # quit if user declined installation
        if [ ${?} == 1 ]; then
            cinform error 'cannot run without all dependencies'
            exit
        fi
    fi
done

cinform header 'all dependencies met'
}

get_dev_path () {
lsblk --noheadings --raw --paths --output NAME ${1}
}

get_part_by_partlabel () {
# yeah, it's getting rough. please, enlighten me the right way to do stuff :D
lsblk --noheadings --raw --paths --output NAME,PARTLABEL | sed 's/\\x20/ /g' | grep "${1}" | cut -d ' ' -f 1
}

# $1 = sgdisk output
get_partnum_from_sgdiskoutput () {
# process sgdisk output, looking for 'partNum is n', where we get n.
# sgdisk counts from 0, whereas Linux counts from 1
sgp=$(echo "${1}" | grep --ignore-case --only-matching --extended-regexp 'partNum is [0-9]+' | awk '{print $3}')
sgp=$(( ${sgp} + 1 ))
echo ${sgp}
}

# $1 = mount point
# $2 = partition path
mount_part () {
cinform info "mounting ${1} on ${2}"
mkdir -p ${2}
mount ${1} ${2}
}

unmount_dir () {
sync
cinform info "unmounting ${1}"
umount ${1}
rmdir ${1}
}

# $1 = space separated dev list
# $2 = item to pre-select
process_devlist_for_yad () {
# get all devices, in format 'devpath (size)!devpath (size)!^prechosendevpath!et cetera'

devs="${1}"
devList=

if [ -n "${devs}" ]; then
    for dev in ${devs}; do
        # add device and it's size
        # yad delimiter is "!"
        devList="${devList}!${dev} ($(lsblk --nodeps --noheadings --raw --output SIZE ${dev}))"
    done
    #~ # cut first (blank) entry
    #~ devList=$(echo ${devList} | cut -d '!' -f 2-)
    # mark pre-chosen disk, if exists
    if [ -n "${2}" ]; then
        devList=$(echo ${devList} | sed "s/\($(escape_for_sed ${2})\)/\^\1/")
    fi
fi

echo ${devList}
}

get_disks () {
#~ devs=$(ls /dev/disk/by-uuid)
#~ devs=$(ls /dev/disk/by-id)
devs=$(lsblk --nodeps --noheadings --paths --raw --output NAME,TYPE | grep 'disk' | cut -d ' ' -f 1)

process_devlist_for_yad "${devs}" "${installDisk}"
}

get_partitions () {
devs=

# if install disk is chosen, only get partitions of install disk
# else, get all partitions, and exclude ones with irrelevant type. (disk, etc.)
#   this lines up well in a one-liner, as ${installDisk} will be an empty string if not set
#~ devs=$(lsblk --noheadings --paths --raw --output NAME,TYPE ${installDisk} | grep -E -v 'disk|rom' | cut -d ' ' -f 1)
devs=$(lsblk --noheadings --paths --raw --output NAME,TYPE ${installDisk} | grep 'part' | cut -d ' ' -f 1)

process_devlist_for_yad "${devs}" "${rootPart}"
}

get_ESPs () {
# try and get all EF00 parititons
# is Linux supposed to be this hacky? 8D
disks=$(lsblk --nodeps --noheadings --paths --raw --output NAME,TYPE | grep 'disk' | cut -d ' ' -f 1)
esps=

for disk in ${disks}; do
    for esp in $(sgdisk -p ${disk} | grep -i 'EF00' | awk '{print $1}'); do
        esps+="${disk}${esp}"
    done
done

process_devlist_for_yad "${esps}" "${ESP}"
}

install_disk_check  () {
if [ -z "${installDisk}" ]; then
    dinform 'you have to choose an install disk first'
    return 1
fi
}

install_part_check () {
if [ -z "${rootPart}" ]; then
    dinform 'you have to choose a partition for the alphaOS system files first'
    return 1
fi
}

uefi_part_check () {
if [ -z "${ESP}" ]; then
    dinform 'you have to choose an EFI System Partition for the UEFI files first'
    return 1
fi
}

prepare_disk () {
install_disk_check || return

dask warn "will now clean and format ${installDisk}\nALL DATA ON THIS DISK WILL BE ERASED\nare you sure you want to continue?"
if [ ${?} -eq ${dnocode} ]; then
    return
fi

# we use GPT. MBR belongs to the past.
# go for sgdisk
# ~ http://rodsbooks.com/gdisk/sgdisk-walkthrough.html
# clean disk
cinform header "cleaning ${installDisk} using sgdisk"
sgdisk --zap-all ${installDisk}

# this was needed for GRUB
if false; then
    # create BIOS boot partition
    dask 'would you like to create a BIOS boot partition,\nto be able to boot GRUB from BIOS systems?'
    if [ ${?} -eq ${dyescode} ]; then
        # 1007K value retrieved from Arch wiki
        biosPartSize='1007K'
        biosPartLabel='BIOS boot partition'
       
        cinform header "creating ${biosPartSize} BIOS boot partition on ${installDisk}"
       
        # capture stdout, to get the partNum of the created partition
        # create a fd, which just redirects to stdout
        exec 5>&1
        sgdiskOut=$(sgdisk --new=0:0:+${biosPartSize} --change-name=0:"${biosPartLabel}" --typecode=0:ef02 ${installDisk} | tee >(cat - >&5))
        exec 5>&-
       
        # record BIOS boot partition
        # is it always analogous to ${installDisk}(${partNum}+1)?
        biosPart=${installDisk}$(get_partnum_from_sgdiskoutput "${sgdiskOut}")
        #~ biosPart=$(get_part_by_partlabel "${biosPartLabel}")
       
        sync
    fi
fi

# create EFI System Partition
dask 'would you like to create an EFI System Partition,
to be able to boot from UEFI systems?

note: UEFI Secure Boot is not supported by alphainst.sh as of today.'
if [ ${?} -eq ${dyescode} ]; then
    ESPLabel='EFI System Partition'
    # recommended size is 512M, but how low can we go?
    #~ efiPartSize='512M'
    # 32MB is minimum size for FAT, go just above
    efiPartSize='33M'
   
    cinform header "creating ${efiPartSize} EFI System Partition on ${installDisk}"
   
    exec 5>&1
    sgdiskOut=$(sgdisk --new=0:0:+${efiPartSize} --change-name=0:"${ESPLabel}" --typecode=0:ef00 ${installDisk} | tee >(cat - >&5))
    exec 5<&-
   
    ESP=${installDisk}$(get_partnum_from_sgdiskoutput "${sgdiskOut}")
   
    sync
   
    cinform header "formatting EFI System Partition (${ESP}) as FAT32"
    mkfs.fat -F 32 ${ESP}
    sync
   
    # inform that there is no automatic install for this as of today
    dinform 'alphainst.sh does not currently install UEFI booting for you,\nyou can install it manually'
fi

# create data partition
dask "would you like to create a data partition,\nto store, amongst whatever you'd like, alphaOS system files?"
if [ ${?} -eq ${dyescode} ]; then
    rootPartLabel='data'
   
    cinform header "creating data partition of remaining space on ${installDisk}"
   
    exec 5>&1
    sgdiskOut=$(sgdisk --new=0:0:0 --change-name=0:"${rootPartLabel}" --typecode=0:8300 ${installDisk} | tee >(cat - >&5))
    exec 5<&-

    # record root partition
    rootPart=${installDisk}$(get_partnum_from_sgdiskoutput "${sgdiskOut}")
   
    sync

    cinform header "formatting data partition (${rootPart}) as FAT32"
    mkfs.fat -F 32 ${rootPart}
    sync
fi
}

alpha_inst () {
install_part_check || return

# copy alphaOS files
if [ ! -d "${alphaOSSrcDir}" ]; then
    cinform error "could not find alphaOS system files\n    please copy them manually to ${alphaOSInstPath}"
    derror "could not find alphaOS system files\nplease copy them manually to ${alphaOSInstPath}"
    return 1
fi

${dialog} --text="do you want to copy all files from ${alphaOSSrcDir},\nor create a fresh install?" \
--button={'all files:2','fresh install:3'} ${dhome}
retVal=${?}

# mount root partition
mount_part ${rootPart} ${rootMount}

case ${retVal} in
2)
    cinform header "copying ${alphaOSSrcDir} to ${alphaOSInstPath}"
    cp -fvR ${alphaOSSrcDir} "${alphaOSInstPath}"
    ;;
3)
    cinform header "copying base system files from ${alphaOSSrcDir} to ${alphaOSInstPath}"
    len=${#alphaOSFiles[@]}
    file=
   
    for (( i=0; i < ${len}; i++ )); do
        file=${alphaOSFiles[${i}]}
       
        # must create directory of file first
        fileDir="$(echo "${alphaOSInstPath}${file}" | sed -r 's/\/[^\/]+$//')"
        mkdir -pv "${fileDir}"
        cp -fv {"${alphaOSSrcDir}","${alphaOSInstPath}"}"${file}"
    done
    ;;
${dhomecode})
    return
    ;;
esac

# clean up
unmount_dir ${rootMount}
}

syslinux_bios_inst () {
# check ArchWiki#SYSLINUX for docs
install_disk_check || return
install_part_check || return

dask warn "will now install SYSLINUX for BIOS at ${installDisk} and data files at ${rootPart}\nALL BOOT LOADER DATA ON THIS DISK WILL BE ERASED\n   (probably not so scary ;)\nare you affirmative you want to continue?"
if [ ${?} -eq ${dnocode} ]; then
    return
fi

cinform header 'installing SYSLINUX for BIOS'

mount_part ${rootPart} ${rootMount}

syslinuxLib='/usr/lib/syslinux/bios'
syslinuxMbr="${syslinuxLib}/gptmbr.bin"

mkdir -p ${syslinuxCfgPath}
cinform header "copying SYSLINUX Comboot modules (*.c32) to ${syslinuxCfgPath}"
cp ${syslinuxLib}/*.c32 ${syslinuxCfgPath}
sync

cinform header "installing SYSLINUX to ${syslinuxCfgPath} of ${rootPart}"
syslinux --install --directory ${syslinuxCfgDir} ${rootPart}

cinform header "marking ${rootPart} as active (legacy_boot GPT flag)"
rootPartNum=$(echo "${rootPart}" | grep -o '[0-9]\+$')
sgdisk ${installDisk} --attributes=${rootPartNum}:set:2
sgdisk ${installDisk} --attributes=${rootPartNum}:show

cinform header "dd'ing ${syslinuxMbr} MBR to ${installDisk}"
dd bs=440 count=1 conv=notrunc if=${syslinuxMbr} of=${installDisk}

unmount_dir ${rootMount}

dinform 'remember to configure SYSLINUX :)'
}

syslinux_uefi_inst () {
# no support yet
# the challenge is yours :)

dinform 'UEFI support is not implemented yet.
the challenge is yours! :D

following is a sample dialog.
there is lots of information in the code!'

# following is sample code
# TODO: remove bogus above

# early support, syslinux UEFI support is itself preliminary, no guarantees

# -- UEFI
# ~Wikipedia: UEFI, EFI System Partition
# ~Arch Wiki: Syslinux#UEFI
# ~Arch Wiki: GRUB#UEFI
# ~https://wiki.gentoo.org/wiki/GRUB2#UEFI.2FGPT
# ~https://www.gnu.org/software/grub/manual/grub.html
# -- Secure Boot
# ~http://www.rodsbooks.com/efi-bootloaders/secureboot.html
# ~https://www.suse.com/communities/conversations/uefi-secure-boot-details/
# ~http://www.zdnet.com/torvalds-clarifies-linuxs-windows-8-secure-boot-position-7000011918/
# ~http://www.zdnet.com/shimming-your-way-to-linux-on-windows-8-pcs-7000008246/
# ~https://wiki.ubuntu.com/SecurityTeam/SecureBoot

uefi_part_check || return
install_part_check || return

echo \
'http://www.rodsbooks.com/efi-bootloaders/secureboot.html
https://fsf.org/campaigns/secure-boot-vs-restricted-boot/
http://www.zdnet.com/torvalds-clarifies-linuxs-windows-8-secure-boot-position-7000011918/
https://wiki.ubuntu.com/SecurityTeam/SecureBoot' | \
dask warn \
"UEFI Secure Boot is not supported by alpha_inst.sh as of today.
this has been chosen as a user should not be forced to trust anyone
in order to boot their programs.

meanwhile, regular UEFI booting is definitely supported :)
you just need to disable Secure Boot in your firmware,
or look up other means to boot alphaOS if you require Secure Boot.
look it up in any case.

will now install SYSLINUX for UEFI at ESP ${ESP} and data files at ${rootPart}
is your mind set about continuing?

the web is full of details. exempli gratia:" --text-info --show-uri
if [ ${?} -eq ${dnocode} ]; then
    return
fi

# we need to return for now
return

cinform header 'installing SYSLINUX for UEFI'

# at least, need ESP for UEFI files
mount_part ${ESP} ${ESPMount}

# TODO

# TODO

unmount_dir ${ESPMount}

dinform 'remember to configure SYSLINUX :)'
}

grub_uefi_inst () {
# the earlier GRUB install, you can look here if you really need UEFI booting
# if so, have a look at the doc mentioned in syslinux_uefi_inst
cinform header 'installing GRUB for UEFI'

# need ESP for UEFI files and root partition for /boot folder
mount_part ${ESP} ${ESPMount}
mount_part ${rootPart} ${rootMount}

cinform header 'installing GRUB --target=x86_64-efi to EFI directory ${ESPMount} and data files to ${rootMount}'
# preload GPT, fat and video modules. consulting Arch Wiki#GRUB can be an idea for possible fixes
preloadEfiModules="part_gpt part_msdos fat all_video"
grub-install --target=x86_64-efi --efi-directory=${ESPMount} --bootloader-id=grub \
--root-directory=${rootMount} --recheck --removable --modules="${preloadEfiModules}"
sync

unmount_dir ${rootMount}
unmount_dir ${ESPMount}

dinform 'remember to configure GRUB :)'
}

syslinux_cfg () {
install_part_check || return

mount_part ${rootPart} ${rootMount}

# get UUID of root partition
rootPartUUID=`lsblk --noheadings --output UUID ${rootPart}`

dask warn "will now (over)write ${syslinuxCfgFile}\nare you in no doubt you want to continue?"
if [ ${?} -eq ${dnocode} ]; then
    unmount_dir ${rootMount}
    return
fi

cinform header 'configuring SYSLINUX'

cinform header "writing built-in SYSLINUX config to ${syslinuxCfgFile}"
cat << __SYSLINUXCFG__ > ${syslinuxCfgFile}
# SYSLINUX config. suit yourself
# https://wiki.archlinux.org/index.php/Syslinux
# http://www.syslinux.org/wiki/index.php/SYSLINUX#How_do_I_Configure_SYSLINUX.3F

PROMPT 0
TIMEOUT 16
# instant booting, unless Alt or Shift (ironically, doesn't work sometimes) is pressed
#MENU SHIFTKEY
# activate on hotkey press
MENU IMMEDIATE

UI menu.c32
#UI vesamenu.c32

MENU TITLE alphaOS
#MENU BACKGROUND bootsplash.png
# menu colors borrowed from Arch, thanks
MENU COLOR border       30;44   #40ffffff #a0000000 std
MENU COLOR title        1;36;44 #9033ccff #a0000000 std
MENU COLOR sel          7;37;40 #e0ffffff #20ffffff all
MENU COLOR unsel        37;44   #50ffffff #a0000000 std
MENU COLOR help         37;40   #c0ffffff #a0000000 std
MENU COLOR timeout_msg  37;40   #80ffffff #00000000 std
MENU COLOR timeout      1;37;40 #c0ffffff #00000000 std
MENU COLOR msg07        37;40   #90ffffff #a0000000 std
MENU COLOR tabmsg       31;40   #30ffffff #00000000 std

# what is booted when time runs out
DEFAULT alphausb

# of course, re-arrange these as you prefer
# and, of more course, mix and match kernel parameters as you'd like

LABEL alphausb
    MENU LABEL alphaOS GNU/Linux ^usbmode
    LINUX ${alphaOSDir}/boot/vmlinuz from=${alphaOSDir} fsck usbmode
    APPEND root=UUID=${rootPartUUID} rw
    INITRD ${alphaOSDir}/boot/initrfs.img

LABEL alpha
    MENU LABEL ^alphaOS GNU/Linux
    LINUX ${alphaOSDir}/boot/vmlinuz from=${alphaOSDir} fsck
    APPEND root=UUID=${rootPartUUID} rw
    INITRD ${alphaOSDir}/boot/initrfs.img

LABEL alphatoram
    MENU LABEL alphaOS GNU/Linux usbmode ^toram
    LINUX ${alphaOSDir}/boot/vmlinuz from=${alphaOSDir} fsck usbmode toram
    APPEND root=UUID=${rootPartUUID} rw
    INITRD ${alphaOSDir}/boot/initrfs.img

LABEL alphanoxorg
    MENU LABEL alphaOS GNU/Linux usbmode no^xorg
    LINUX ${alphaOSDir}/boot/vmlinuz from=${alphaOSDir} fsck usbmode noxorg
    APPEND root=UUID=${rootPartUUID} rw
    INITRD ${alphaOSDir}/boot/initrfs.img

LABEL alphadbg
    MENU LABEL alphaOS GNU/Linux usbmode ^debug
    LINUX ${alphaOSDir}/boot/vmlinuz from=${alphaOSDir} usbmode debug
    APPEND root=UUID=${rootPartUUID} rw
    INITRD ${alphaOSDir}/boot/initrfs.img

LABEL alphafresh
    MENU LABEL alphaOS GNU/Linux ^fresh
    LINUX ${alphaOSDir}/boot/vmlinuz from=${alphaOSDir} fresh
    APPEND root=UUID=${rootPartUUID} rw
    INITRD ${alphaOSDir}/boot/initrfs.img

MENU SEPARATOR

LABEL hd0
    MENU LABEL ^Continue to first hard disk
    COM32 chain.c32
    APPEND hd0

MENU SEPARATOR

LABEL hdt
    MENU LABEL ^HDT (Hardware Detection Tool)
    COM32 hdt.c32

LABEL reboot
    MENU LABEL ^Reboot
    COM32 reboot.c32

LABEL poweroff
    MENU LABEL ^Poweroff
    COM32 poweroff.c32
__SYSLINUXCFG__
sync

# open in text editor for interactivity and transparency
if [ -n "${EDITOR}" ]; then
    ${EDITOR} ${syslinuxCfgFile}
fi

unmount_dir ${rootMount}
}

syslinux_menu () {
# check if already installed
installedForBIOS='idk'
if [ -n "${installDisk}" ]; then
    # MBR is the first 512 bytes in MBR disks. need to grep --text, as output of dd is binary
    syslinuxMbrSum=$(sha1sum -b /usr/lib/syslinux/bios/gptmbr.bin)
    installedMbrSum=$(dd if=${installDisk} bs=440 count=1 2>/dev/null | sha1sum -b)
    if [ "${syslinuxMbrSum% *}" = "${installedMbrSum% *}" ]; then
        installedForBIOS='YES'
    else
        installedForBIOS='NO'
    fi
fi
installedForUEFI='idk'
if [ -n "${ESP}" ]; then
    mount_part ${ESP} ${ESPMount}
    bootEfiApp="${ESPMount}/EFI/BOOT/BOOTX64.EFI"
    if [ -e "${bootEfiApp}" ] && [ -n "$(cat "${bootEfiApp}" | grep 'GRUB')" ]; then
        installedForUEFI='YES'
    else
        installedForUEFI='NO'
    fi
    unmount_dir ${ESPMount}
fi
configFileExists='idk'
if [ -e "${rootPart}" ]; then
    mount_part ${rootPart} ${rootMount}
    if [ -e "${syslinuxCfgFile}" ]; then
        configFileExists='YES'
    else
        configFileExists='NO'
    fi
    unmount_dir ${rootMount}
fi

# SYSLINUX dialog
${dialog} --text="SYSLINUX

chosen install disk: ${installDisk}
chosen data partition: ${rootPart}
chosen EFI System Partition: ${ESP}

installed for BIOS on ${installDisk}: ${installedForBIOS}
installed for UEFI on ${ESP}: ${installedForUEFI}
config file exists at ${syslinuxCfgFile}: ${configFileExists}" \
--button={'install for BIOS:2','install for UEFI:3','configure SYSLINUX:4'} ${dhome}
case ${?} in
2)
    syslinux_bios_inst
    ;;
3)
    syslinux_uefi_inst
    ;;
4)
    syslinux_cfg
    ;;
${dhomecode})
    return
    ;;
esac

syslinux_menu
}

menu () {
retChoices=$(${dialog} --text-align="CENTER" \
--text="welcome!\nyou are expected to have read the alphaOS readmes at Right-click -> Readme. that's about it :)\n" \
--form --align=right \
--field="install to disk:CB" "$(get_disks)" \
--field="copy alphaOS files to partition:CB" "$(get_partitions)" \
--field="(EFI System Partition):CB" "$(get_ESPs)" \
--button={"clean and format disk:2","copy alphaOS files:3","set up boot loader:4"} \
${dquit})

retVal=${?}

# process choices
# if the dialog had no choice, '(null)' is returned. we substitute that with ''
retChoices=$(echo "${retChoices}" | sed 's/(null)//g')
installDisk=$(echo "${retChoices}" | cut -d '|' -f 1 | cut -d ' ' -f 1)
rootPart=$(echo "${retChoices}" | cut -d '|' -f 2 | cut -d ' ' -f 1)
ESP=$(echo "${retChoices}" | cut -d '|' -f 3 | cut -d ' ' -f 1)

case ${retVal} in
2)
    prepare_disk
    ;;
3)
    alpha_inst
    ;;
4)
    syslinux_menu
    ;;
${dquitcode})
    exit 0
    ;;
esac

menu
}
# -------------------------------
# ---------- Functions ----------
# -------------------------------

# -------------------------------
# ---------- Execution ----------
# -------------------------------

# are we root?
priv_check

# ensure dependencies are met
dep_ensure

# show menu
menu

# -------------------------------
# ---------- Execution ----------
# -------------------------------


Original post:
So, I'm testing out a little installer script. It's currently only installing to USB, I'll be using it that way. How do you use it?
Ideas for how automatic it should be? Wiping whole disk, partition names, etc. Perhaps I'll embed both an automatic and a fairly manual mode.

Does anyone have experience with grub2 installation? I managed to get it installed, but both grub-mkconfig and grub-install complained about aufs, because grub-probe has problems with probing an aufs device. Similar to this: http://www.murga-linux.com/puppy/viewtopic.php?p=739408&sid=d60b995a18eec3a4eb4c3fc11b547d25 I borrowed that solution, but it's not pretty.

I've never done UEFI either. I think the Arch ISO has both UEFI and BIOS support, but that's the only one I can think of. Experience with implementing this?

I also thought about creating yad dialogs, is that the preferred way? Over gtkdialog for example? I've never done this stuff, glad for advice.
(is ncurses acceptable? :) )

Also, as somebody asked for a GUI grub customizer, I'll share something I stumbled upon. GTK3, it seems. Never tried it. [AUR] grub-customizer
Last edited by Aspi on 31 Jul 2014, 10:00, edited 3 times in total.

efgee
Expert
Posts: 115
Joined: 29 Dec 2013, 20:58

Re: Move to GRUB

Postby efgee » 23 Apr 2014, 07:06

Using grub2 and loading alphaOS 15 with and without os-probing.
(On a SSD not on USB memory though)

Not quite sure about the validity of os-probing because it only works with proper UUID.
And it works without it.

Aspi
Advanced
Posts: 40
Joined: 21 Apr 2014, 11:32

Re: Move to GRUB

Postby Aspi » 23 Apr 2014, 11:23

By os-probing, you mean?

I'm using UUIDs, much more fit for a portable USB. Maybe you mean the

Code: Select all

search --fs-uuid
?

It's been working fine so far, and is how GRUB rolls.

Did you use grub-mkconfig, or did you write the config file from scratch? I use a modded grub-mkconfig, as noted.

Scooby
Site Admin
Posts: 826
Joined: 09 Sep 2013, 16:52

Re: Move to GRUB

Postby Scooby » 23 Apr 2014, 17:37

Aspi wrote:So, I'm testing out a little installer script. It's currently only installing to USB, I'll be using it that way. How do you use it?

the same way, grub2 on USB.

Aspi wrote:Ideas for how automatic it should be? Wiping whole disk, partition names, etc. Perhaps I'll embed both an automatic and a fairly manual mode.

I like the idea of anvanced mode and a fully automatic one. As for what to use gtk,yad or ncurses I'm not
sure, Sim can be a little fickle and stuff like yad can disappear between releases. Me I would use vala
and gtk.


Aspi wrote:I've never done UEFI either. I think the Arch ISO has both UEFI and BIOS support, but that's the only one I can think of. Experience with implementing this?

ndrancs and sim has been working on a UEFI bootable alphaos iso. I don't know if the effort stalled or work is in progress.
ndrancs I think has solid knowledge in UEFI and probably could be asked for help.

Aspi
Advanced
Posts: 40
Joined: 21 Apr 2014, 11:32

alphainst.sh

Postby Aspi » 28 Apr 2014, 16:58

Okay, so I have been writing a little on and off on this. Quickly had stuff up and running, but I had forgotten how tidyi GUI writing can be. Quick, big words; less results. Sorry to fall in that pit hole. From now on, I'll work on stuff if and only if I feel like it.
Also, this is one of my first >200 line shell script. I still have to look up case switches. Please guide for the mistakes you find. Don't fall for bikeshedding! ;)

Image

I'm prompting for testers. Any ideas, please post them. Any bugs, please post them. And, please, fork it, mod it, rewind it; as long as it's within the GPL, do whatever you want with it! :D
Also, this is streamlined for cleaning disks and then installing GRUB to it (maybe I'll add support for other boot loaders as well? though, GRUB is pretty GRand and Unified ...). Target is my personal USB install, so not much thought has gone into compatibility with eg. an install to a disk already embedding something. Is there demand for this?
I'm not writing this in Vala, at least not for now. Does not make sense, imo. Should I rely on yad, gtkdialog, dialog or something else similar?
Also, welcoming any UEFI explanation. I've made room for it, but not implemented it yet. I figure VirtualBox has UEFI support, but I'm still glad if someone has intel and/or experience with it.

Dependencies so far: yad grub gptfdisk

Code: Select all

#!/usr/bin/bash

# -------------------------------
# ----------- License -----------
# -------------------------------
# @licstart
# Copyright (C) 2014  Free Software Foundation, Inc
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
#
# 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 may have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# @licend
# -------------------------------
# ----------- License -----------
# -------------------------------

# -------------------------------
# -------- Version 0.01 ---------
# -------------------------------

# -------------------------------
# ------------ TODO -------------
# -------------------------------
# - create drop-down field showing console output
# - make GRUB dialog detect if GRUB is installed (file -s dev?)
# - make partition selection dialog only contain partitions of selected disk
#   must be dynamic. ie. when one changes install disk choice, available partitions must be updated
#     compatible with loop devs?
# - make UEFI compatible
#   idk if [grub-install --target=*-pc] destroys [grub-install --target=*-efi], or vice versa. needs testing
# - validate more shizz
# - maybe make it more suited to install without cleaning disk
# - yad has a --image "gnome-shutdown" for shutdown dialogs
# - aesthetics :)
# -------------------------------
# ------------ TODO -------------
# -------------------------------

# -------------------------------
# ---------- Variables ----------
# -------------------------------
version='0.01'

installDisk=''
rootMount='/mnt/inst'
rootPart=''
rootPartUUID=''
alphaOSDir=''
alphaOSPath=''
biosPart=''
biosPartUUID=''
efiMount=''
efiPart=''
efiPartUUID=''

# dialog
dialog="$(which yad)"
# YAD
dtitle='--title=alphainst.sh'
dsettings='--center --borders=8 --always-print-result'
dialog="${dialog} ${dtitle} ${dsettings}"
dyescode=90
dyes="--button=gtk-yes:${dyescode}"
dnocode=91
dno="--button=gtk-no:${dnocode}"
dokcode=98
dok="--button=gtk-ok:${dokcode}"
dquitcode=99
dquit="--button=gtk-quit:${dquitcode}"
# -------------------------------
# ---------- Variables ----------
# -------------------------------

# -------------------------------
# ---------- Functions ----------
# -------------------------------

privcheck () {
if (( ${EUID} != 0 )); then
   echo "This script must be run as root. Type in 'sudo ${0}' to run it as root."
   if [ "${dialog}" != '' ]; then
      ${dialog} ${dok} --text="This script must be run as root.\nType 'sudo ${0}' in a terminal to run it as root."
   fi
   exit 1
fi
}

escapeforsed () {
#~ # sed it like a boss \/
#~ echo $(echo ${1} | sed -e 's/\//\\\\\//g')
# sed it like a pro -.- ~https://stackoverflow.com/questions/407523/escape-a-string-for-a-sed-replace-pattern
echo $(echo ${1} | sed -e 's/[\/&]/\\&/g')
}

getdevpath () {
lsblk --noheadings --raw --paths --output NAME ${1}
}

# 1 = mount point, 2 = partition path
mountpart () {
echo "-- mounting ${1} on ${2}"
mkdir -p ${2}
mount ${1} ${2}
}

unmountdir () {
sync
echo "-- unmounting ${1}"
umount ${1}
rmdir ${1}
}

getdisks () {
# get all disks, in format 'diskpath (size)!diskpath (size)!et cetera'
devs=''
#~ devs=$(ls /dev/disk/by-uuid)
#~ devs=$(ls /dev/disk/by-id)
devs=$(lsblk --nodeps --noheadings --paths --raw --output NAME)
devList=''
if [ "${devs}" != '' ]; then
   for dev in ${devs}; do
      # add device and it's size
      # yad delimiter is "!"
      devList="${devList}!${dev} ($(lsblk --nodeps --noheadings --raw --output SIZE ${dev}))"
   done
   # cut first (blank) entry
   devList=$(echo ${devList} | cut -d '!' -f 2-)
   # mark pre-chosen disk, if exists
   if [ "${installDisk}" != '' ]; then
      devList=$(echo ${devList} | sed "s/\($(escapeforsed ${installDisk})\)/\^\1/")
   fi
fi

echo ${devList}
}

getpartitions () {
# get all partitions, in format 'partpath (size)!partpath (size)!^prechosenpartpath!et cetera'
devs=''
# if install disk is chosen, only get partitions of install disk
# else, get all partitions, and exclude ones with irrelevant type. (disk, etc.)
#   this lines up well in a one-liner, as ${installDisk} will be an empty string if not set
devs=$(lsblk --noheadings --paths --raw --output NAME,TYPE ${installDisk} | grep -E -v 'disk|rom' | cut -d ' ' -f 1)
devList=''
if [ "${devs}" != '' ]; then
   for dev in ${devs}; do
      # add device and it's size
      # yad delimiter is "!"
      devList="${devList}!${dev} ($(lsblk --nodeps --noheadings --raw --output SIZE ${dev}))"
   done
   # cut first (blank) entry
   devList=$(echo ${devList} | cut -d '!' -f 2-)
   # mark pre-chosen partition, if exists
   if [ "${rootPart}" != '' ]; then
      devList=$(echo ${devList} | sed "s/\($(escapeforsed ${rootPart})\)/\^\1/")
   fi
fi

echo ${devList}
}

installdiskcheck  () {
if [ "${installDisk}" = '' ]; then
   ${dialog} --text="you have to choose an install disk first" --button="OK"
   return
fi
return 1
}

installpartcheck () {
if [ "${rootPart}" = '' ]; then
   ${dialog} --text="you have to choose a partition for the alphaOS files first" --button="OK"
   return
fi
return 1
}

formatdisk () {
installdiskcheck && return

${dialog} --image "dialog-warning" ${dno} ${dyes} --text="will now clean and format ${installDisk}\nALL DATA ON THIS DISK WILL BE ERASED\nare you sure you want to continue?"
if [ ${?} = ${dnocode} ]; then
   return
fi

# we use GPT. MBR belongs to the past.
# go for sgdisk
# ~ http://rodsbooks.com/gdisk/sgdisk-walkthrough.html
# clean disk
echo "-- cleaning ${installDisk} using sgdisk"
sgdisk --zap-all ${installDisk}

# create BIOS boot partition
echo "-- creating BIOS boot partition on ${installDisk}"
biosPartLabel='BIOS boot partition'
sgdisk --new=0:0:+1007K --change-name=0:"${biosPartLabel}" --typecode=0:ef02 ${installDisk}
sync
sleep 1

# record BIOS boot partition
biosPart=$(getdevpath /dev/disk/by-partlabel/${biosPartLabel})

#~ # create EFI System Partition
#~ echo "-- creating EFI System Partition on ${installDisk}"
#~ efiPartLabel='EFI System Partition'
#~ sgdisk --new=0:0:+200M --change-name=0:"${efiPartLabel}" --typecode=0:ef00 ${installDisk}
#~ sync
#~ sleep 1
#~ echo "-- formatting EFI System Partition as vfat"
#~ mkfs.vfat /dev/disk/by-partlabel/"${efiPartLabel}"
#~ sync
#~
#~ efiPart=$(getdevpath /dev/disk/by-partlabel/${efiPartLabel})

# create data partition
echo "-- creating data partition on ${installDisk}"
rootPartLabel='data'
sgdisk --new=0:0:0 --change-name=0:"${rootPartLabel}" --typecode=0:8300 ${installDisk}
# must be fixed, why not working?
sync
sleep 1


# record root partition
rootPart=$(getdevpath /dev/disk/by-partlabel/${rootPartLabel})


echo "-- formatting data partition (${rootPart}) as ext4"
mkfs.ext4 ${rootPart}
sync
}

alphainst () {
installpartcheck && return

# mount root partition
mountpart ${rootPart} ${rootMount}

# copy alphaOS files
# mark it's USBness
alphaOSDir='/alphaos.usb'
alphaOSPath="${rootMount}${alphaOSDir}"
echo "-- copying /mnt/home/alphaos to ${alphaOSPath}"
cp -R /mnt/home/alphaos ${alphaOSPath}

# clean up
unmountdir ${rootMount}
}

grubbiosinst () {
echo "-- installing GRUB for BIOS"

# need to specify root directory, else GRUB will complain about aufs
echo "-- installing GRUB --target=i386-pc to ${installDisk} and data files to ${rootMount}"
grub-install --target=i386-pc --root-directory=${rootMount} --recheck ${installDisk}
}

grubuefiinst () {
echo "-- installing GRUB for UEFI"

# untested!
efiMount='/mnt/efi'

mountpart ${efiPart} ${efiMount}

echo "-- installing GRUB --target=x86_64-efi to EFI directory ${efiMount} and data files to ${rootMount}"
grub-install --target=x86_64-efi --efi-directory=${efiMount} --bootloader-id=grub --root-directory=${rootMount} --recheck

unmountdir ${efiMount}
}

grubinst () {
installdiskcheck && return
installpartcheck && return

${dialog} --image "dialog-warning" ${dno} ${dyes} --text="will now install GRUB at ${installDisk}\nALL BOOT LOADER DATA ON THIS DISK WILL BE ERASED\n   (probably not so scary ;)\nare you affirmative you want to continue?"
if [ ${?} = ${dnocode} ]; then
   return
fi

mountpart ${rootPart} ${rootMount}

# BIOS
grubbiosinst

#~ # UEFI - untested!
#~ grubuefiinst

unmountdir ${rootMount}
}

grubcfg () {
echo "-- configuring GRUB"

installpartcheck && return

mountpart ${rootPart} ${rootMount}

# just create the grub.cfg ourselves :D
#   https://www.gnu.org/software/grub/manual/html_node/Multi_002dboot-manual-config.html
#   https://wiki.archlinux.org/index.php/Grub#Manually_creating_grub.cfg

# get UUID of root partition
rootPartUUID=`lsblk --output UUID --noheadings ${rootPart}`

grubcfgfile="${rootMount}/boot/grub/grub.cfg"

${dialog} --image "dialog-warning" ${dno} ${dyes} --text="will now overwrite ${grubcfgfile}\nare you in no doubt you want to continue?"
if [ ${?} = ${dnocode} ]; then
   return
fi

echo "-- writing built-in GRUB config to ${grubcfgfile}"
cat << __GRUBCFG__ > ${grubcfgfile}
# GRUB config. suit yourself
set rootPartUUID=${rootPartUUID}
set alphaOSDir=${alphaOSDir}

menuentry "alphaOS GNU/Linux usbmode" {
   insmod part_gpt
   insmod ext2
   insmod search_fs_uuid
   
   search --fs-uuid --no-floppy --set=root \${rootPartUUID}
   
   echo 'Loading alphaOS GNU/Linux kernel ...'
   linux \${alphaOSDir}/boot/vmlinuz from=\${alphaOSDir} fsck usbmode
   echo 'Loading alphaOS GNU/Linux kernel initrd ...'
   initrd \${alphaOSDir}/boot/initrfs.img
}

menuentry "alphaOS GNU/Linux" {
   insmod part_gpt
   insmod ext2
   insmod search_fs_uuid
   
   search --fs-uuid --no-floppy --set=root \${rootPartUUID}
   
   echo 'Loading alphaOS GNU/Linux kernel ...'
   linux \${alphaOSDir}/boot/vmlinuz from=\${alphaOSDir} fsck
   echo 'Loading alphaOS GNU/Linux kernel initrd ...'
   initrd \${alphaOSDir}/boot/initrfs.img
}

menuentry "alphaOS GNU/Linux usbmode toram" {
   insmod part_gpt
   insmod ext2
   insmod search_fs_uuid
   
   search --fs-uuid --no-floppy --set=root \${rootPartUUID}
   
   echo 'Loading alphaOS GNU/Linux kernel ...'
   linux \${alphaOSDir}/boot/vmlinuz from=\${alphaOSDir} fsck usbmode toram
   echo 'Loading alphaOS GNU/Linux kernel initrd ...'
   initrd \${alphaOSDir}/boot/initrfs.img
}

menuentry "alphaOS GNU/Linux debug" {
   insmod part_gpt
   insmod ext2
   insmod search_fs_uuid
   
   search --fs-uuid --no-floppy --set=root \${rootPartUUID}
   
   echo 'Loading alphaOS GNU/Linux kernel ...'
   linux \${alphaOSDir}/boot/vmlinuz from=\${alphaOSDir} usbmode debug
   echo 'Loading alphaOS GNU/Linux kernel initrd ...'
   initrd \${alphaOSDir}/boot/initrfs.img
}

menuentry "alphaOS GNU/Linux fresh" {
   insmod part_gpt
   insmod ext2
   insmod search_fs_uuid
   
   search --fs-uuid --no-floppy --set=root \${rootPartUUID}
   
   echo 'Loading alphaOS GNU/Linux kernel ...'
   linux \${alphaOSDir}/boot/vmlinuz from=\${alphaOSDir} fresh
   echo 'Loading alphaOS GNU/Linux kernel initrd ...'
   initrd \${alphaOSDir}/boot/initrfs.img
}
__GRUBCFG__

# open in text editor for interactivity
if [ "${EDITOR}" != '' ]; then
    ${EDITOR} ${grubcfgfile}
fi

unmountdir ${rootMount}
}

menu () {
retChoices=$(${dialog} --form --align=right --field={"install to disk:CB","copy alphaOS files to partition:CB"} "$(getdisks)" "$(getpartitions)" --button={"clean and format disk:0","copy alphaOS files:1","install GRUB:2","configure GRUB:3"} ${dquit})
retVal=${?}

# process choices
installDisk=$(echo ${retChoices} | cut -d '|' -f 1 | cut -d ' ' -f 1)
rootPart=$(echo ${retChoices} | cut -d '|' -f 2 | cut -d ' ' -f 1)

case ${retVal} in
0)
   formatdisk
   ;;
1)
   alphainst
   ;;
2)
   grubinst
   ;;
3)
   grubcfg
   ;;
${dquitcode})
   exit 0
   ;;
esac

menu
}
# -------------------------------
# ---------- Functions ----------
# -------------------------------

# -------------------------------
# ---------- Execution ----------
# -------------------------------

# are we root?
privcheck

# show menu
menu

# -------------------------------
# ---------- Execution ----------
# -------------------------------
Last edited by Aspi on 28 Apr 2014, 21:49, edited 1 time in total.

Scooby
Site Admin
Posts: 826
Joined: 09 Sep 2013, 16:52

Re: Move to GRUB

Postby Scooby » 28 Apr 2014, 18:30

For now I will review code, on the weekend I will test install on USB

What is the workflow, Hit buttons from left to right?

The "copy alphaOS files" makes me wonder about what is required.
is it

1. Can only be run from alphaos, not for instance puppy-linux?

2. Cannot be used when alphaos is booted with "toram"?

is there any problems to run all the parts from one button?

Aspi wrote:but I had forgotten how tidyi GUI writing can be

Yepp, GUI programming is pretty boring.


Aspi wrote:welcoming any UEFI explanation. I've made room for it, but not implemented it yet

UEFI would be great. I recommend you to pm ndrancs, and collaborate on UEFI.


Is this an old comment on line nbr 229?
# must be fixed, why not working?

Aspi wrote:I'm not writing this in Vala

If this turns out good and UEFI is added I might do a vala GUI for it.
your bash code looks good and commented. I think it would be easy to separate
out yad-dialogs and call bash from vala GUI. 14 lines with yad(dialog) in script and
all but main window is warnings or errors which I would just convert to echo's

I don't think vala would add much( but separation of gui and workhorse code which I think
is easier to read and maintain) yad is just fine


Aspi wrote:Dependencies so far: yad grub gptfdisk

I saw this in script (line 90 and 92)

Code: Select all

${dialog} ${dok} --text="This script must be run as root.\nType 'sudo ${0}' in a terminal to run it as root."

This would require sudo to be installed and correctly configured in alphaos, Which I tried once and could not solve in 10 min
so I gave up. I like running as root anyway,

Maybe this could be offered as an arch AUR package, then dependencies would be
automatically handled.

Aspi wrote:From now on, I'll work on stuff if and only if I feel like it.

thanks for your hard work.
Yeah, it should be fun to develop. I'm looking forward to some future projects of your own choosing.

Aspi
Advanced
Posts: 40
Joined: 21 Apr 2014, 11:32

Re: Move to GRUB

Postby Aspi » 28 Apr 2014, 20:34

Thanks a lot, Scooby! :D

Scooby wrote:What is the workflow, Hit buttons from left to right?

Yep, pretty much. Though, you're welcome to think through what you need for an install. Eg. at least later on, but prolly now as well, one can skip cleaning disk, just copying alphaOS files to a partition of own choice, installing GRUB to the same or another disk, then configure GRUB to boot from the partition you placed alphaOS on. I tried to make it possible to have custom scenarios, not just one grande auto-cruncher.

When I come to think of it, this script kind of requires that one has read the "Install alphaOS" text file shipped with the OS. That should prolly be outlined somewhere.

Scooby wrote:The "copy alphaOS files" makes me wonder about what is required.
is it

1. Can only be run from alphaos, not for instance puppy-linux?

It's alphaOS only. I don't know how puppy installs work, and don't really intend to find out now.
The only thing that button really does is cp -R /mnt/home/alphaos to /mnt/inst/alphaos.usb. (should I rather copy from /mnt/live/memory/ btw?)
So for Puppy portability, one would need to change what files are copied in the "copy alphaOS files" procedure, and change the GRUB config to boot puppy vmlinuz and initrd instead of (in addition to?) alphaOS.

Scooby wrote:2. Cannot be used when alphaos is booted with "toram"?

I actually didn't test that yet. I tested now, and it works. It is the same procedure as normally, just copying to /alphaos.usb, so no difference.

Scooby wrote:is there any problems to run all the parts from one button?

I could add the auto-mode I talked about earlier, but I figure it's nice that people know a little under the hood about how the installation works. You know, like much of Arch Linux usage encourages.

Scooby wrote:Is this an old comment on line nbr 229?
# must be fixed, why not working?

No, that's actually a problem. I have to `sleep 1`, which I do not like. Even the sync did not make up for it, I could not do anything with the partitions before `sleep 1` had been executed, guess something needs to refresh. There's got to be a better way though. Very glad for enlightenment here!

The privcheck is really just something I embed with scripts needing to run as root. alphaOS runs as root for puppy reasons, so it won't trigger any default installs. I'll change it to `su`, that's available everywhere there's Linux, no?

Maybe AUR. I can just write a quick "deptest" function though. Good enough? Pseudo:

Code: Select all

pacToInstall=''
which grub-install
if $? == 1; then
pacToInstall+=" grub"
fi
which sgdisk
if $? == 1; then
pacToInstall+=" gptfdisk"
fi
if pacToInstall != ''; then
pacman -Sy pacToInstall
fi

Hopefully UEFI. I'll PM some time.

Why so enthusiastic about Vala? The largest reason I'm not so enthusiastic is that it results in compiled code; it's much harder to mod, and harder to learn. Less portable, I guess. But again, I come from scripting world. If you can convince me it's better, I guess there's nothing in the way for migrating to Vala. I intentionally made the GUI bit easy to port.
Will a potential Vala GUI contain the bash code, or merely just call a bash script?

Also, this is pretty lame, but does anyone know how to make the buttons appear on one line each in yad? I can't make anything but all buttons on one line work :roll:

Scooby
Site Admin
Posts: 826
Joined: 09 Sep 2013, 16:52

Re: Move to GRUB

Postby Scooby » 29 Apr 2014, 17:14

Aspi wrote:When I come to think of it, this script kind of requires that one has read the "Install alphaOS" text file shipped with the OS. That should prolly be outlined somewhere.

maybe output a edited version with alphainst.sh -h ?

Aspi wrote:It's alphaOS only. I don't know how puppy installs work, and don't really intend to find out now.
The only thing that button really does is cp -R /mnt/home/alphaos to /mnt/inst/alphaos.usb. (should I rather copy from /mnt/live/memory/ btw?)
So for Puppy portability, one would need to change what files are copied in the "copy alphaOS files" procedure, and change the GRUB config to boot puppy vmlinuz and initrd instead of (in addition to?) alphaOS.

I don't know if I was clear but I meant cross install. Use your script on a puppy linux to install alphaos to USB.

You could possibly get install files from ISO? I'm thinking of users that are new to alphaOS.

What is your thoughts on a first time user. What scenario are you envisioning?

Scooby wrote:2. Cannot be used when alphaos is booted with "toram"?

What about "toram" without savefile, Then /mnt/home would not be set.


Aspi wrote:No, that's actually a problem. I have to `sleep 1`, which I do not like. Even the sync did not make up for it, I could not do anything with the partitions before `sleep 1` had been executed, guess something needs to refresh. There's got to be a better way though. Very glad for enlightenment here!

Sorry I dunnow any good solution. Sometimes you have to do "sleep".

Aspi wrote:Maybe AUR. I can just write a quick "deptest" function though. Good enough? Pseudo:

Code: Select all

pacToInstall=''
which grub-install
if $? == 1; then
pacToInstall+=" grub"
fi
which sgdisk
if $? == 1; then
pacToInstall+=" gptfdisk"
fi
if pacToInstall != ''; then
pacman -Sy pacToInstall
fi


This would work as well


Aspi wrote:Why so enthusiastic about Vala? The largest reason I'm not so enthusiastic is that it results in compiled code; it's much harder to mod, and harder to learn. Less portable, I guess. But again, I come from scripting world. If you can convince me it's better, I guess there's nothing in the way for migrating to Vala. I intentionally made the GUI bit easy to port.
Will a potential Vala GUI contain the bash code, or merely just call a bash script?

I don't want to convince you, It's fine now. No reason really.

I think its easiest with a vala GUI calling a bash script if one would want to do it.
If you ever decide to do it, tell me first, I have some sample code.

Aspi wrote:Also, this is pretty lame, but does anyone know how to make the buttons appear on one line each in yad? I can't make anything but all buttons on one line work :roll:

Will check if I find a way :D

Scooby
Site Admin
Posts: 826
Joined: 09 Sep 2013, 16:52

Re: Move to GRUB

Postby Scooby » 29 Apr 2014, 20:54

Scooby wrote: Aspi wrote:Also, this is pretty lame, but does anyone know how to make the buttons appear on one line each in yad? I can't make anything but all buttons on one line work :roll:


Will check if I find a way :D


I checked and couldn't find how to do that with yad.

You will probably have to write the gtk+ code it-self if you want to do it.

And this I don't like, mixing bash and gtk, Which will end in a script that
by contrast to yours is very hard to read.

I grovelled through some of those scripts for puppy linux and swore to never use it me-self.

I know how to do it in vala though :D
And that is what I like about Vala/bash. Using vala mainly for GUI operation.

Your yad version is probably the best :!:
If you can live with buttons on the same line.

Aspi
Advanced
Posts: 40
Joined: 21 Apr 2014, 11:32

Re: Move to GRUB

Postby Aspi » 30 Apr 2014, 15:47

Scooby wrote:I don't know if I was clear but I meant cross install. Use your script on a puppy linux to install alphaos to USB.
You could possibly get install files from ISO? I'm thinking of users that are new to alphaOS.
What is your thoughts on a first time user. What scenario are you envisioning?

Ah, I got it wrong. I was hoping Sim would possibly consider bundling it with the alphaOS ISO :) I was thinking about making something alike the "Setup Savefile..." dialog, just "Install alphaOS".
So, cross install could be possible, but I really think the easiest way would be to boot the ISO and install from there. I thought of this as unnatural earlier, so maybe I'll think of some way to cross install. But alphaOS lacks a native installer, and that is what I'm trying to address here.

Then, I also understand your Vala points; YAD is not supported everywhere. I was thinking about embedding with the alphaOS ISO.

Scooby wrote:What about "toram" without savefile, Then /mnt/home would not be set.

Again, I got it wrong. No, vmlinuz and initrd is not available when booting "toram". Thus, one must copy the files manually. The installer can't go around and mount every device, lurking for possible alphaOS files in each. The script will inform that this has to be done manually.
It should be alright; this OS expects the user to have a fair amount of Linux knowledge, no? I would be lost, had I not been Arching for a while.

Thanks for checking yad, I'll have to minimize buttons then. Just create a new menu for GRUB install, showing BIOS and UEFI options, etc.
We'll think about Vala :P I'll librarize it more if I get in the mood, somehow. Functionality first now :)

*edit*
Just had success installing to UEFI. Really not much harder than BIOS, thanks to awesome GNU folks creating GRUB :D
A 0.02 release will possibly be out soon.
Last edited by Aspi on 30 Apr 2014, 18:11, edited 2 times in total.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 10 guests

cron