Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › Chroot in a script.
New Posts  All Forums:Forum Nav:

Chroot in a script.

post #1 of 8
Thread Starter 
In my neverending obsession with install scripts I got a bright idea for one for Arch. I found this and was wondering if I can have it all a single script and invoke a function to run inside the chroot? Or does it have to be done with 2 scripts, one copied into the chroot location?

*EDIT* I have little free time and this is what I do with it... I don't know why.
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
post #2 of 8
Thread Starter 
Have gotten a ways in. Still working on how to execute a script inside of a chroot.
What I have so far... (Click to show)
Code:
#!/bin/bash

## variables - packages ##

INSTSW="base base-devel dialog dosfstools efibootmgr iw wpa_actiond wpa_supplicant"

BASESW="alsa-plugins alsa-oss alsa-utils avahi cifs-utils cronie cups hplip jre8-openjdk lib32-alsa-plugins lib32-libpulse libcups openbsd-netcat openssh pulseaudio pulseaudio-alsa samba vim xf86-video-intel xorg-apps xorg-server xorg-server-utils "

PKGSW="blender chromium gimp libreoffice-fresh playonlinux virt-manager virtualbox virtualbox-guest-iso"

DESW="amarok bluedevil kcm-touchpad kdebase kdemultimedia-kmix kdepim kdeplasma-addons kdesdk-kate kdeutils-print-manager libcanberra-pulse vlc yakuake"

## variables - system ##

GRUBCFG="-o /boot/grub/grub.cfg"
GRUBINST="--target=x86_64-efi --efi-directory=/boot --bootloader-id=arch_grub --recheck"
HSTNAME=sylvermane # hostname
LOCALE1="en_US.UTF-8"
LOCALE2="en_US ISO-8859-1"
ROOTDPW=simpsons # root dummy password
USRDPW=simpsons # user dummy password

## variables - wifi ##

WIFIID=$(ip link | grep wlp | awk '{print $2}' | awk -F: '{print $1}')

##### begin script #####

## initial installation functions

cachecopy() { # $1 is source cache directory | $2 is target cache directory
    if [[ -d "$1" ]] ; then
        if [[ ! -d "$2" ]] ; then
            mkdir -p "$2"
            for file in "$1"/* 
            do
                cp "$file" "$2"
            done
        fi
    fi
}

osinstall() { # $1 is mirrorlist i.e. /etc/pacman.d/mirrorlist
    mv "$1" "$1".orig
    tac "$1".orig | grep -A 1 "United States" > "$1"
    sed -i '/--/d' "$1"    
    pacstrap /mnt $INSTSW
    genfstab -p -U /mnt >> /mnt/etc/fstab
}

## post installation functions

swinstall() {
    echo "
##### my additions #####
    
[multilib]
Include = /etc/pacman.d/mirrorlist" >> /etc/pacman.conf    
     pacman -Syu
#    pacman -S $BASESW $PKGSW $DESW
}

adminusr() { # create user
    useradd -m -g users -G wheel,games,uucp,rfkill -s /bin/bash "$1"
    # give proper sudo rights
    echo "
##### my additions #####

 %wheel ALL=(ALL) ALL
$1 $HSTNAME =NOPASSWD:/usr/bin/systemctl suspend" >> /etc/sudoers
    # password for user
    echo -e "$USRDPW\n$USRDPW" | passwd "$1"
}

sysdstuff() { #check for package and enable service
    # avahi
    if [[ "$BASESW" == *avahi* ]] ; then
        systemctl enable avahi-daemon
    fi
    # bluetooth
    if [[ "$DESW" == *blue* ]] ; then
        systemctl enable bluetooth
    fi
    # cron
    if [[ "$BASESW" == *cronie* ]] ; then
        systemctl enable cronie
    fi
    # cups
    if [[ "$BASESW" == *cups* ]] ; then
        systemctl enable cups
    fi
    # wifi
    if [[ "$WIFIID" ]] ; then
        systemctl enable netctl-auto@"$WIFIID".service
    fi
}

specialsw() { # certain software requires certain configs done
    if [ "$PKGSW" == *virtualbox* ] ; then
        echo "vboxdrv
vboxnetflt
vboxnetadp
vboxpci" > /etc/modules-load.d/virtualbox.conf
        usermod -aG vboxusers "$1"
    fi
} 

finalinfo() { # print important info
    echo "user '$1' password set to '$USRDPW' - change it to something more secure!"
}

case "$1" in
    install)
        cachecopy /media/data/Linux/cache /mnt/var/cache/pacman/pkg # works
        osinstall /etc/pacman.d/mirrorlist # works
        ;;
    post)
        swinstall # works
        sysdstuff # works
        specialsw $admusr1 # works
        clear && read -p "would you like to create an admin user? (y / n) --> " admusr0 # works
        if [[ "$admusr0" == [Yy] ]] ; then # works
            clear && read -p "enter admin username --> " admusr1 # works
            adminusr $admusr1 # works
            finalinfo $admusr1 # works
        fi
        ;;
    *)
        echo "usage: $0 {install | post}"
        exit 0
        ;;
esac
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
post #3 of 8
Quote:
Originally Posted by Tadaen Sylvermane View Post

Have gotten a ways in. Still working on how to execute a script inside of a chroot.

Have you looked at the chroot man page:
Code:
 chroot [OPTION] NEWROOT [COMMAND [ARG]...]
So that would be something like this:
Code:
chroot /path echo "hello world"
post #4 of 8
That answer was in the link he posted... not sure if he realized that tongue.gif
post #5 of 8
Thread Starter 
Yes I had read the man page a few times. I was doing it right the whole time, just calling the script with the wrong path. /mnt/path/to/script instead of /path/to/script... in effect calling it from the live environment instead of inside the chroot. I didn't notice my error till a half hour ago or so. Once that hit me it was just a few bug squashes and here it is. All works. Sloppy, fairly useless. But it gave me something to do.

Direct from the wiki This is what I ended up with (Click to show)
Code:
#!/bin/bash

## variables - packages ##

INSTSW="base base-devel cifs-utils dialog dosfstools efibootmgr grub iw wpa_actiond wpa_supplicant"
BASESW="alsa-plugins alsa-oss alsa-utils avahi cronie cups hplip jre8-openjdk lib32-alsa-plugins lib32-libpulse libcups openbsd-netcat openssh pulseaudio pulseaudio-alsa samba vim xf86-video-intel xorg-apps xorg-server xorg-server-utils "
PKGSW="blender chromium gimp libreoffice-fresh playonlinux virt-manager virtualbox virtualbox-guest-iso"
DESW="amarok bluedevil kcm-touchpad kdebase kdemultimedia-kmix kdepim kdeplasma-addons kdesdk-kate kdeutils-print-manager libcanberra-pulse vlc yakuake"

## variables - system ##

COUNTRY=America
CITY=Phoenix
GRUBCFG="-o /boot/grub/grub.cfg"
#GRUBINST="--target=x86_64-efi --efi-directory=/boot --bootloader-id=arch_grub --recheck"
GRUBINST="--target=i386-pc --recheck /dev/sda"
HSTNAME=sylvermane # hostname
LOCALE1="en_US.UTF-8"
LOCALE2="en_US ISO-8859-1"
ROOTDPW=simpsons # root dummy password
USRDPW=simpsons # user dummy password

## variables - wifi ##

WIFIID=$(ip link | grep wlp | awk '{print $2}' | awk -F: '{print $1}')

##### begin script #####

## initial installation functions

cachecopy() { # $1 is source cache directory | $2 is target cache directory - works
    if [[ -d "$1" ]] ; then
        if [[ ! -d "$2" ]] ; then
            mkdir -p "$2"
            for file in "$1"/* 
            do
                cp "$file" "$2"
            done
        fi
    fi
}

osinstall() { # $1 is mirrorlist i.e. /etc/pacman.d/mirrorlist - works
    mv "$1" "$1".orig
    tac "$1".orig | grep -A 1 "United States" > "$1"
    sed -i '/--/d' "$1"    
    pacstrap /mnt $INSTSW
    genfstab -p -U /mnt >> /mnt/etc/fstab
}

chroottasks() {
    if [[ ! -d /mnt/root/bin ]] ; then
        mkdir -p /mnt/root/bin
        echo "#!/bin/bash

# set hostname

echo $HSTNAME > /etc/hostname

# set locale & timezone

ln -sf /usr/share/zoneinfo/$COUNTRY/$CITY /etc/localtime
sed -i 's/\#$LOCALE1/$LOCALE1/' /etc/locale.gen
sed -i 's/\#$LOCALE2/$LOCALE2/' /etc/locale.gen
locale-gen
echo 'LANG=$LOCALE1' > /etc/locale.conf

# finalize it

mkinitcpio -p linux
echo -e '$ROOTDPW\n$ROOTDPW' | passwd

# bootloader

grub-install $GRUBINST

if [[ -d /boot/EFI/arch_grub ]] ; then
    if [[ ! -d /boot/EFI/boot ]] ; then
        mkdir -p /boot/EFI/boot
        cp /boot/arch_grub/grubx64.efi /boot/EFI/boot/bootx64.efi
    fi
fi

grub-mkconfig $GRUBCFG


exit" > /mnt/root/bin/script
        chmod 755 /mnt/root/bin/script
        arch-chroot /mnt bash -c /root/bin/script
        rm /mnt/root/bin/script
        umount -R /mnt
        clear
        echo "root password is set to '$ROOTDPW' - change it to something more secure!"
        echo "reboot when ready!"
    fi
}

## post installation functions

swinstall() { # install software - works
    echo "
##### my additions #####
    
[multilib]
Include = /etc/pacman.d/mirrorlist" >> /etc/pacman.conf    
     pacman -Syu
     pacman -S $BASESW $PKGSW $DESW
}

adminusr() { # create user - works
    useradd -m -g users -G wheel,games,uucp,rfkill -s /bin/bash "$1"
    # give proper sudo rights
    echo "
##### my additions #####

 %wheel ALL=(ALL) ALL
$1 $HSTNAME =NOPASSWD:/usr/bin/systemctl suspend" >> /etc/sudoers
    # password for user
    echo -e "$USRDPW\n$USRDPW" | passwd "$1"
}

sysdstuff() { #check for package and enable service - works
    # avahi
    if [[ "$BASESW" == *avahi* ]] ; then
        systemctl enable avahi-daemon
    fi
    # bluetooth
    if [[ "$DESW" == *blue* ]] ; then
        systemctl enable bluetooth
    fi
    # cron
    if [[ "$BASESW" == *cronie* ]] ; then
        systemctl enable cronie
    fi
    # cups
    if [[ "$BASESW" == *cups* ]] ; then
        systemctl enable cups
    fi
    # wifi
    if [[ "$WIFIID" ]] ; then
        systemctl enable netctl-auto@"$WIFIID".service
    fi
}

specialsw() { # certain software requires certain configs done - works
    if [ "$PKGSW" == *virtualbox* ] ; then
        echo "vboxdrv
vboxnetflt
vboxnetadp
vboxpci" > /etc/modules-load.d/virtualbox.conf
        usermod -aG vboxusers "$1"
    fi
} 

finalinfo() { # print important info - works
    echo "user '$1' password set to '$USRDPW' - change it to something more secure!"
}

case "$1" in
    install)
        cachecopy /media/data/Linux/cache /mnt/var/cache/pacman/pkg # works
        osinstall /etc/pacman.d/mirrorlist # works
        chroottasks # works
        ;;
    post)
        swinstall # works
        sysdstuff # works
        specialsw $admusr1 # works
        clear && read -p "would you like to create an admin user? (y / n) --> " admusr0 # works
        if [[ "$admusr0" == [Yy] ]] ; then # works
            clear && read -p "enter admin username --> " admusr1 # works
            adminusr $admusr1 # works
            finalinfo $admusr1 # works
        fi
        ;;
    *)
        echo "usage: $0 {install | post}" # works
        exit 0
        ;;
esac

Edited by Tadaen Sylvermane - 10/19/14 at 5:31pm
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
post #6 of 8
Ah yes. So it was. Edit: that was in reply to Shrak

As for having everything in one script, the obvious way would be to have flags set:
Code:
#!pseudo code
if $flag == "chroot" {
    chrootFunc()
} else {
    hostFunc()
}

Func hostFunc() {
    # create chroot dir
    chroot /path $me chroot
    # script forks itself
    echo welcome back
}

Func chrootFunc() {
    # do stuff in chroot
}

Edited by Plan9 - 10/19/14 at 5:28pm
post #7 of 8
Thread Starter 
Polished it up. Final version. Use it at will.
Cleaned and commented. Straight from the wiki guides (Click to show)
Code:
#!/bin/bash
# Tadaen Sylvermane
# Arch Installer

##### variables #####

# initial installation packages
ARCHSW1="base base-devel cifs-utils dialog dosfstools efibootmgr grub iw wpa_actiond wpa_supplicant"
# post installation base packages
ARCHSW2="alsa-plugins alsa-oss alsa-utils avahi bluez bluez-utils cronie cups gstreamer0.10-plugins jre8-openjdk hplip lib32-alsa-plugins lib32-libpulse libcups openbsd-netcat openssh pulseaudio pulseaudio-alsa rsync samba vim xf86-input-synaptics xf86-video-intel xorg-apps xorg-server xorg-server-utils xorg-xinit"
# user packages
ARCHSW3="blender chromium filezilla gimp libreoffice-fresh net-tools playonlinux transmission-cli virt-manager virtualbox virtualbox-guest-iso vlc"
# country for mirrorlist
MIRRORCTRY="United States"
# variables for chroot
COUNTRY=America
CITY=Phoenix
HOSTNM=failboxvm # hostname
LOCALE1="en_US.UTF-8"
LOCALE2="en_US ISO-8859-1"
# dummy password for root & created user
DUMMYPW=1981
#wifi interface
WIFIID=$(ip link | grep wlp | awk '{print $2}' | awk -F: '{print $1}')
# temp file for post install
if [[ -f /installer ]] ; then
        TEMPFILE=$(cat /installer)
fi

##### begin script #####

## control and final variable assignment functions ##

rootmenu() { # options for root user
        rootmenu0() { # edit this function to adjust what is done
                swinstall
                sysdstuff
                specialsw
                addausr mkusr
                sudostuff
                usrgroup
                addausr usrinfo
                themes "$TEMPFILE"/icons/"$1" /usr/share/icons
                themes "$TEMPFILE"/themes/"$1" /usr/share/themes
                themes "$TEMPFILE"/fonts /usr/share/fonts
                rm /installer
        }    
        case "$1" in
                install)
                        # sets grub install depending on if in virtualbox or not
                        if lsusb | grep -i virtualbox ; then
                                GRUBINST="--target=i386-pc --recheck /dev/sda"
                        else
                                GRUBINST="--target=x86_64-efi --efi-directory=/boot --bootloader-id=arch_grub --recheck"
                        fi
                        osinstall /etc/pacman.d/mirrorlist
                        ;;
                post)
                        case "$2" in
                                gnome) # packages for gnome de
                                        ARCHSW4="evolution gedit gedit-plugins gnome gnome-tweak-tool gnome-weather rhythmbox tilda"
                                        rootmenu0 "$2"
                                        ;;
                                kde) # packages for kde de
                                        ARCHSW4="amarok bluedevil kcm-touchpad kdebase kdemultimedia-kmix kdepim kdeplasma-addons kdesdk-kate kdeutils-ark ksshaskpass libcanberra-pulse yakuake"
                                        rootmenu0 "$2"
                                        ;;
                *)
                    echo "usage $0 post {gnome | kde}"
                    exit 0
                    ;;
                        esac
                        ;;
                testing)
                        exit 0
                        ;;
                *)
                        echo "usage $0 {install | post}"
                        ;;
        esac
}

usermenu() {
        case "$1" in
                minecraft) # set up minecraft for $USER. shouldn't be run as root
                        minecraft
                        ;;
                *)
                        echo "usage $0 {minecraft}"
                        ;;
        esac
}

## root functions for software management and installation ##    

osinstall() { # $1 is mirrorlist | works 2014/12/17 - 1005
        cachecopy() { # $1 is target cache directory
                clear && read -p "enter source folder path --> " cachecopyopt0
                if [[ -d "$cachecopyopt0" ]] ; then
                        clear && echo "copying cache from source folder. standby"
                        echo "$cachecopyopt0" >> "$osinstallopt0"/installer
                        if [[ ! -d "$1" ]] ; then
                                mkdir -p "$1"
                        fi
                        # source/archcache is a folder in my source directory. change this line as needed
                        for file in "$cachecopyopt0"/archcache/*.xz ; do
                                cp "$file" "$1"
                        done
                else
                        clear && read -p "folder doesn't exist. try again (y / n) --> " cachecopyopt1
                        if [[ "$cachecopyopt1" == [yY] ]] ; then
                                cachecopy
                        else
                                echo "continuing without source folder"
                                sleep 2
                        fi
                fi
        }
        chroottasks() { # chroot stuff
                if [[ ! -d "$osinstallopt0"/root/bin ]] ; then
                        mkdir -p "$osinstallopt0"/root/bin
                echo "#!/bin/bash

# set hostname

echo $HOSTNM > /etc/hostname

# set locale & timezone

ln -sf /usr/share/zoneinfo/$COUNTRY/$CITY /etc/localtime
sed -i 's/\#$LOCALE1/$LOCALE1/' /etc/locale.gen
sed -i 's/\#$LOCALE2/$LOCALE2/' /etc/locale.gen
locale-gen
echo 'LANG=$LOCALE1' > /etc/locale.conf

# finalize it

mkinitcpio -p linux
echo -e '$DUMMYPW\n$DUMMYPW' | passwd

# bootloader

grub-install $GRUBINST

if [[ -d /boot/EFI/arch_grub ]] ; then
    if [[ ! -d /boot/EFI/boot ]] ; then
        mkdir -p /boot/EFI/boot
        cp /boot/EFI/arch_grub/grubx64.efi /boot/EFI/boot/bootx64.efi
    fi
fi

grub-mkconfig -o /boot/grub/grub.cfg


exit" > "$osinstallopt0"/root/bin/script
                        chmod 755 "$osinstallopt0"/root/bin/script
                        arch-chroot "$osinstallopt0" bash -c /root/bin/script
                        rm -r "$osinstallopt0"/root/bin
                        echo
                        echo "root password is set to '$DUMMYPW' - change it to something more secure!"
                        echo "reboot when ready!"
                fi
        }
        clear && read -p "enter mountpoint for / --> " osinstallopt0
        if mountpoint -q "$osinstallopt0" ; then
                # cleans up the /etc/pacman.d/mirrorlist
                mv "$1" "$1".orig
                cat "$1".orig | grep -A 1 "$MIRRORCTRY" > "$1"
                sed -i '/--/d' "$1"
                # copies backed up cache into place to save download time
                cachecopy "$osinstallopt0"/var/cache/pacman/pkg  
                pacstrap "$osinstallopt0" $ARCHSW1
                genfstab -p -U "$osinstallopt0" >> "$osinstallopt0"/etc/fstab
                chroottasks
        else
                clear && echo "that is not a mountpoint. check mountpoint and try again"
                sleep 1
                exit 0
        fi
}

## post installation functions ##

swinstall() { # install software | works 2014/12/16 - 2156
        if ! tail -n 5 /etc/pacman.conf | grep -iq multilib ; then
                echo "
##### my additions #####
    
[multilib]
Include = /etc/pacman.d/mirrorlist" >> /etc/pacman.conf
        fi
        pacman -Syu
        pacman -S $ARCHSW2 $ARCHSW3 $ARCHSW4
}

sysdstuff() { #check for package and enable service | works 2014/12/16 - 2156
    # avahi
        if [[ "$ARCHSW2" == *avahi* ]] ; then
                systemctl enable avahi-daemon
        fi
    # bluetooth
        if [[ "$ARCHSW2" == *blue* ]] ; then
                systemctl enable bluetooth
        fi
    # cron
        if [[ "$ARCHSW2" == *cronie* ]] ; then
                systemctl enable cronie
        fi
    # cups
        if [[ "$ARCHSW2" == *cups* ]] ; then
                systemctl enable cupsd
        fi
    # wifi
    if [[ "$WIFIID" ]] ; then
        systemctl enable netctl-auto@"$WIFIID"
    fi
    # display manager
    if [[ "$ARCHSW4" == *gnome* ]] ; then
        systemctl enable gdm
    elif [[ "$ARCHSW4" == *kde* ]] ; then
        systemctl enable kdm
        fi
}

specialsw() { # certain software requires certain configs done | works 2014/12/16 - 2157
        # if vm inside of virtualbox
        if lsusb | grep -i virtualbox ; then
                pacman -Syu
                pacman -S virtualbox-guest-utils virtualbox-guest-modules
                echo "vboxguest
vboxsf
vboxvideo" > /etc/modules-load.d/virtualboxvm.conf
        fi
        # virtualbox package
        if [[ "$ARCHSW3" == *virtualbox* ]] ; then
                echo "vboxdrv
vboxnetflt
vboxnetadp
vboxpci" > /etc/modules-load.d/virtualbox.conf
        fi
}

addausr() { # works 2014/12/16 - 2202
        case "$1" in
                mkusr)
                        clear && read -p "enter admin username --> " addausropt0
                        useradd -m -g users -G wheel,rfkill,uucp,games -s /bin/bash "$addausropt0"
                        echo -e "$DUMMYPW\n$DUMMYPW" | passwd "$addausropt0"
                        if [[ ! -f /etc/sudoers.d/customrules ]] ; then
                                echo " %wheel ALL=(ALL) ALL" >> /etc/sudoers.d/customrules
                        fi
                        ;;
                usrinfo)
                        echo "username $addausropt0 password is '$DUMMYPW'. change it to be secure!"
                        ;;
        esac
}

sudostuff() { # make some sudo commands usable without password | works 2014/12/16 - 2202
        nopasswdsudo() { # workhorse
        clear && read -p "enter terminal command to use without a password --> " nopasswdsudo0
        TCOMMAND=$(whereis "$nopasswdsudo0" | awk '{print $2}')
        HSTNAME=$(hostname)
        if [[ "$TCOMMAND" ]] ; then
                echo "$1 $HSTNAME =NOPASSWD:$TCOMMAND" >> /etc/sudoers.d/customrules
        else
                clear && echo "command not found"
                sleep 2
        fi
        sudostuff
        }
        if [[ -f /etc/sudoers.d/customrules ]] ; then
        clear && echo "you have added these sudo rules" && cat /etc/sudoers.d/customrules
        echo && read -p "would you like to add another? (y / n) --> " sudostuff0
        else
        clear && read -p "would you like to add commands for passwordless sudo use? (y / n) --> " sudostuff0
        fi
        if [[ "$sudostuff0" == [yY] ]] ; then
        clear && read -p "enter username to modify --> " sudostuff1
        if grep -q "$sudostuff1" /etc/passwd ; then
                nopasswdsudo "$sudostuff1"
        else
                clear && read -p "user not found. try again? (y / n) --> " sudostuff2
                if [[ "$sudostuff" == [yY] ]] ; then
                                sudostuff
                fi
        fi
        fi
}

usrgroup() { # list created groups and add selected user to new groups
        usrgroup0() { # workhorse
        echo && read -p "enter the group name --> " usrgroup0opt0
        if grep -iw "$usrgroup0opt0" /etc/group ; then
                echo && read -p "enter user name --> " usrgroup0opt1
                if grep -iw "$usrgroup0opt1" /etc/passwd ; then
                                usermod -aG "$usrgroup0opt0" "$usrgroup0opt1"
                                echo "added user $usrgroup0opt1 to $usrgroup0opt0" >> /tmp/group2
                                usrgroup
                else
                                echo && read -p "user doesn't exist. try again? (y / n) --> " usrgroup0opt2
                                if [[ "$usrgroup0opt2" == [Yy] ]] ; then
                                        usrgroup
                                fi
                fi
        else
                echo && read -p "group doesn't exist. try again? (y / n) --> " usrgroup0opt3
                if [[ "$usrgroup0opt3" == [yY] ]] ; then
                                usrgroup
                fi      
        fi
        }
        clear && echo "groups added to the system..."
        echo
        if [[ ! -f /tmp/group1 ]] ; then
        journalctl -r | grep -i "/etc/group" | awk '{print $10}' | awk -F= '{print $2}' | awk -F, '{print $1}' >> /tmp/group1
        fi
        cat /tmp/group1
        if [[ -f /tmp/group2 ]] ; then
        echo && echo "groups you have added your user to already..."
        echo && cat /tmp/group2
        fi
        echo && read -p "do you want to add a user to a group? (y / n) --> " usrgroupopt0
        if [[ "$usrgroupopt0" == [yY] ]] ; then
        usrgroup0
        fi
        # removes both temp files when done
        if [[ -f /tmp/group1 ]] ; then
        rm /tmp/group1
        fi
        if [[ -f /tmp/group2 ]] ; then
        rm /tmp/group2
        fi
}

themes() {
        if [[ -d "$1" ]] ; then
                find "$1" -iname '*.tar.gz' -exec tar -xf {} -C "$2" \;
        fi
}

## user functions ##

minecraft() { # setup minecraft | works 2014/12/16 - 2207
        clear && read -p "enter path to minecraft source folder..." mcopt1
        if [[ -d "$mcopt1" ]] ; then
    # make shortcut for menus
                if [[ ! -d "/home/$USER/.local/share/applications" ]] ; then
                        mkdir -p "/home/$USER/.local/share/applications"
                fi
                if [[ -f "$mcopt1/Minecraft.desktop" ]] ; then
                        cd "/home/$USER/.local/share/applications" && ln -s "$mcopt1/Minecraft.desktop"
                fi
        # link resource packs
                if [[ ! -d "/home/$USER/.minecraft" ]] ; then
                        mkdir -p "/home/$USER/.minecraft"
                fi
                if [[ -d "$mcopt1/resourcepacks" ]] ; then
                        cd /home/$USER/.minecraft && ln -s "$mcopt1/resourcepacks"
                fi
        # link saves folder
                if [[ -d "$mcopt1/saves" ]] ; then
                        cd /home/$USER/.minecraft && ln -s "$mcopt1/saves"
                fi      
        else        
                read -p "folder doesn't exist. try again? ( y / n )"  mcopt2
                if [[ "$mcopt2" == [Yy] ]] ; then
                        minecraft
                fi
        fi
}

## execution ##

if [[ "$USER" == root ]] ; then
        rootmenu "$1" "$2" 
else
        usermenu "$1" "$2"
fi

##### end script #####

Doubt anyone will find it but updated 2014/12/17 @ 1200 Works 100% in all my vm tests so far. I hope someone can use it.
Edited by Tadaen Sylvermane - 12/17/14 at 11:00am
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
post #8 of 8
I demand you take that script down...I claim infringement or close copying of my idea to name a Linux install host "fail". tongue.gif

Looks like something to try next summer when I finally have enough time to do something like a new install.
     
CPUGraphicsRAMHard Drive
Intel Core m3-6Y30 Intel HD515 8GB 1866DDR3L Micron M600 MTFDDAV256MBF M.2, 256 GB 
CoolingOSOSMonitor
Fanless Win10 Home x64 Kubuntu 16.04 (requires Linux kernel 4.5/4.6) 13.3 inch 16:9, 1920x1080 pixel, AU Optronics A... 
CPUMotherboardGraphicsRAM
AthlonIIX4 640 3.62GHz (250x14.5) 2.5GHz NB Asus M4A785TD-M EVO MSI GTX275 (Stock 666) 8GBs of GSkill 1600 
RAMHard DriveHard DriveHard Drive
4GBs of Adata 1333 Kingston HyperX 3k 120GB WD Caviar Black 500GB Hitachi Deskstar 1TB 
Optical DriveCoolingOSOS
LG 8X BDR (WHL08S20) Cooler Master Hyper 212+ Kubuntu x64 Windows 7 x64 
OSMonitorPowerCase
Bodhi Linux x64 Acer G215H (1920x1080) Seasonic 520 HAF912 
CPUMotherboardGraphicsRAM
N450 1.8GHz AC and 1.66GHz batt ASUS proprietary for 1001P GMA3150 (can play bluray now!?) 1GB DDR2 
Hard DriveOptical DriveOSOS
160GB LGLHDLBDRE32X Bodhi Linux Fedora LXDE 
OSOSMonitorKeyboard
Kubuntu SLAX 1280x600 + Dell 15inch Excellent! 
PowerCase
6 cells=6-12hrs and a charger 1001P MU17 Black 
  hide details  
Reply
     
CPUGraphicsRAMHard Drive
Intel Core m3-6Y30 Intel HD515 8GB 1866DDR3L Micron M600 MTFDDAV256MBF M.2, 256 GB 
CoolingOSOSMonitor
Fanless Win10 Home x64 Kubuntu 16.04 (requires Linux kernel 4.5/4.6) 13.3 inch 16:9, 1920x1080 pixel, AU Optronics A... 
CPUMotherboardGraphicsRAM
AthlonIIX4 640 3.62GHz (250x14.5) 2.5GHz NB Asus M4A785TD-M EVO MSI GTX275 (Stock 666) 8GBs of GSkill 1600 
RAMHard DriveHard DriveHard Drive
4GBs of Adata 1333 Kingston HyperX 3k 120GB WD Caviar Black 500GB Hitachi Deskstar 1TB 
Optical DriveCoolingOSOS
LG 8X BDR (WHL08S20) Cooler Master Hyper 212+ Kubuntu x64 Windows 7 x64 
OSMonitorPowerCase
Bodhi Linux x64 Acer G215H (1920x1080) Seasonic 520 HAF912 
CPUMotherboardGraphicsRAM
N450 1.8GHz AC and 1.66GHz batt ASUS proprietary for 1001P GMA3150 (can play bluray now!?) 1GB DDR2 
Hard DriveOptical DriveOSOS
160GB LGLHDLBDRE32X Bodhi Linux Fedora LXDE 
OSOSMonitorKeyboard
Kubuntu SLAX 1280x600 + Dell 15inch Excellent! 
PowerCase
6 cells=6-12hrs and a charger 1001P MU17 Black 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix
Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › Chroot in a script.