#1 04.02.2018 17:53:14

LinLin
Mitglied

naad.sh version0.2(beta)config helper - Bitte fertigstellen

Ist immernoch in der Beta-Phase.

Wenn wir es verkaufen wollen sollten wir die Beta verlassen wink


Und hier die neuste Version:

naad.sh configures some files for arch linux.
usage: naad.sh [option] [argument]
-a                      About naad.sh.
-h                      Display this help message.
-k <ll>             Set-x11-keymap <language> code
-l <ll_CC>        Set <language_COUNTRY> code in locale files
-m <myhost>  Set hostname
-s                      Show configurations
-t <timezone> Set timezone
-v <keymap>  Set vconsole keymap
Examples:
./naad.sh -k fr -l fr_CA -m mon-pc -t Canada/Atlantic -v fr-latin1
./naad.sh -k de -l de_DE -m mein-pc -t Europe/Berlin -v de-latin1-nodeadkeys
Terminal commands you may need:
To search language_COUNTRY codes do 'cat /etc/locale.gen'.
To search timezone do 'find /usr/share/zoneinfo -type f | less'.

#!/bin/bash
#naad.sh version 0.2 (beta) is a configuration helper for arch linux.
#
#From tuxnix with no garanty at all.
#Thanks drcux for good suggestions.

# start as root?
if [ $UID -ne 0 ];  then
    sudo bash -c "$0 $*"; exit $?
fi

# exittrap
trap cleanupandexit 1 2 3 15

cleanupandexit()
{
exit 1
}

#about naad
about()
{
cat << EOF

About some configurtion related aspects with naad.sh

About naad.sh :
This script is a configurtion helper to get most common settings done. Read Arch Wiki if you need help!

Keyboard - option -k :
It's possible to choose language/layout settings with option -k. As a default model=pc105, variant=nodeadkeys and options=caps:numlock are preselectet. These values will fit to most cases. Edit the skript sektion #keyboard if you want to change this values. To search for values use the following commands: 'localectl list-x11-keymap-models |less' 'localectl list-x11-keymap-variants |less' localectl list-x11-keymap-options |less.

Locale - /etc/locale.conf - /etc/locale.gen - option l :
Both files /etc/locale.conf and /etc/locale.gen are configred with the language_COUNTRY code <ll__CC>
To aktivate LC_COLLATE=C (first all little than all big letters) collation behaviour decommend this line in '/etc/locale.conf' file afer you used the -l option.

Show your configurations - option -s :
Will display all configuration settings.

Virtual Console - /etc/vconsole.conf - option -v :
Fonts for virtual console will allways be configerd with 'FONT=lat9w-16' to search for other fonts do 'find /usr/share/kbd/consolefonts -type f | less'. Edit the vconsole.conf section in this script.

EOF
}

# help message
usage()
{
cat << EOF
naad.sh configures some files for arch linux.

usage: $0 [option] [argument]
 -a            About naad.sh.
 -h            Display this help message.
 -k <ll>       Set-x11-keymap <language> code
 -l <ll_CC>    Set <language_COUNTRY> code in locale files
 -m <myhost>   Set hostname
 -s            Show configurations
 -t <timezone> Set timezone
 -v <keymap>   Set vconsole keymap

Examples:
./naad.sh -k fr -l fr_CA -m mon-pc -t Canada/Atlantic -v fr-latin1
./naad.sh -k de -l de_DE -m mein-pc -t Europe/Berlin -v de-latin1-nodeadkeys

Terminal commands you may need to search for arguments:
k) localectl list-x11-keymap-layouts | less
l) cat /etc/locale.gen
t) find /usr/share/zoneinfo -type f | less
v) find /usr/share/kbd/keymaps/i386/ -type f | grep <search string>

EOF
}

# show configurationes
sconf()
{
echo ""
echo "----------------------------"
echo "Display some configurations:"
echo "----------------------------"
#echo "Show - 'cat /etc/hostname':"
echo Show "'cat - /etc/hostname':"
cat /etc/hostname
echo ""
echo "Show - 'cat /etc/locale.conf':"
cat  "/etc/locale.conf"
echo ""
echo "Show - 'localectl status':"
localectl status
echo ""
echo "Show - 'timedatectl status':"
timedatectl status
echo ""
echo "Show - 'cat /etc/vconsole.conf':"
cat /etc/vconsole.conf
echo ""
}

# optargs
while getopts ":ahk:l:m:st:v:" OPTION; do
  case $OPTION in
        a ) about; exit 1 ;;
        h ) usage; exit 1 ;;
        k ) layout=$OPTARG ;;
         l ) ll_CC=$OPTARG ;;
        m ) myhost=$OPTARG ;;
        p ) privat; exit 1 ;;
        s ) sconf; exit 1 ;;
        t ) tizo=$OPTARG ;;
        v ) vconsole=$OPTARG ;;
         \? )  echo "The option -$OPTARG is not guilty." && usage >&2; exit 1 ;;
        : )  echo "Option -$OPTARG requires an argument!"; exit 1 ;;
  esac
done

# check options and arguments
if  [[ $layout"x" == "x" ]] && [[ $ll_CC"x" == "x" ]] && [[ $myhost"x" == "x" ]] && [[ $tizo"x" == "x" ]] && [[ $vconsole"x" == "x" ]]; then  
    echo "Choose an option!"; cleanupandexit
fi

if ( ! localectl list-x11-keymap-layouts | grep -q "$layout" ) || [[ "$layout" == [a-z] ]]; then 
    echo "Nothing configured. Do 'localectl list-x11-keymap-layouts | less' to get values for -k option!"; cleanupandexit
fi

if [[ $ll_CC"x" != "x" ]];then
    if ( ! grep -q "$ll_CC" "/etc/locale.gen" ) || (  [[ "$ll_CC" != [a-z][a-z]_[A-Z][A-Z] ]] && [[ "$ll_CC" != [a-z][a-z][a-z]_[A-Z][A-Z] ]] ); then 
    echo "Nothing configured. Do 'cat /etc/locale.gen' to get values for -l option!"; cleanupandexit
    fi
fi

if ( ! find "/usr/share/zoneinfo/" -type f | grep -wq "$tizo" ); then  
    echo "Argument in -t is not guilty!"; echo  "Find timezone, with: 'find /usr/share/zoneinfo -type f | less'"; cleanupandexit
fi

if ( ! find "/usr/share/kbd/keymaps/i386/" -type f | grep -qw "$vconsole" ); then 
    echo "The argument in -v is not guilty! Find keyboard map, with: 'find /usr/share/kbd/keymaps/i386/ -type f | grep' <search string>'";  cleanupandexit
fi

# keyboard
echo ""
if [[ $layout"x" != "x" ]]; then
    model=pc105
    variant=nodeadkeys
    options=caps:numlock
    echo "Set-x11-keymap..."
    localectl set-x11-keymap [$layout] [$model] [$variant] [$options]
fi

if [[ $ll_CC"x" != "x" ]]; then
    # set ll
    ll="${ll_CC%_*}"
    # edit /etc/locale.conf
    #Hier muss evt. nachgebessert werden z.B. für tcy_IN.UTF-8 UTF-8
    echo "Edit /etc/locale.conf..."
    cat > "/etc/locale.conf" << EOF
    LANG=$ll_CC.UTF-8
    LANGUAGE=$ll:en
    #LC_COLLATE=C
    LC_TIME=$ll_CC.UTF-8
    LC_PAPER=$ll_CC.UTF-8
    LC_MEASUREMENT=$ll_CC.UTF-8
    LC_MONETARY=$ll_CC.UTF-8
    LC_NUMERIC=$ll_CC.UTF-8
    LC_CTYPE=$ll_CC.UTF-8
    LC_MESSAGES=$ll_CC.UTF-8
    LC_NAME=$ll_CC.UTF-8
    LC_ADDRESS=$ll_CC.UTF-8
    LC_TELEPHONE=$ll_CC.UTF-8
    LC_IDENTIFICATION=$ll_CC.UTF-8
    LC_ALL=
EOF

    # reconfigure /etc/locale.gen.
    sed -ie "/#/!s/^/#/" "/etc/locale.gen"

    # edit /etc/locale.gen
    echo "Edit /etc/locale.gen..."
    sed -ie "s/#$ll_CC/$ll_CC/" "/etc/locale.gen"
    sed -ie "s/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" "/etc/locale.gen"
    echo "locale-gen..."
    echo ""
    locale-gen
    echo ""
fi

# edit /etc/hostname
if [[ $myhost"x" != "x" ]]; then
    echo "Edit /etc/hostname..."
    echo $myhost > /etc/hostname
fi

#ln /etc/localtime
if [[ $tizo"x" != "x" ]]; then
    echo "Set symlink to /etc/localtime..."
    ln -sf /usr/share/zoneinfo/$tizo /etc/localtime
fi

# edit /etc/vconsole.conf
if [[ $vconsole"x" != "x" ]]; then
    echo "Edit /etc/vconsole.conf..."
    echo KEYMAP="$vconsole" > "/etc/vconsole.conf"
    echo FONT=lat9w-16 >> "/etc/vconsole.conf"
fi

echo ""

exit 0

Offline

#2 07.02.2018 20:19:43

tuxnix
Mitglied

Re: naad.sh version0.2(beta)config helper - Bitte fertigstellen

Hallo LinLin,
ich bin für eine lange Beta Phase dann lohnt sich der Verkauf auch richtig big_smile

Wie ich sehe hast du brikler's Vorschlag begriffen und entwickelst unabhängig weiter. Sehr gut!
Ganz heimlich hab ich auch etwas weiter gemacht. Ich stell das mal hier hin.
(Vorsicht die option -p ist noch nicht getestet. Da brauche ich erst noch eine Festplatte dafür.)

Kannst deine Weiterentwicklung ruhig parallel weiter verfolgen.
Irgendwann (wenn Zeit ist) schreiben wir von einander ab und machen eines daraus.
Statt ping pong macht halt jeden nur ping oder pong und irgendwann schreibt man halt vom anderen ab (wie in der Schule).

#!/bin/bash
#naad version 0.3 (beta) is a install and configurtion helper for Arch Linux.
#
#From tuxnix, drcux and LinLin with no garanty at all.

# start as root?
if [ $UID -ne 0 ];  then
    sudo bash -c "$0 $*"; exit $?
fi

#about naad
about()
{
cat << EOF

About some $0 related aspects.

About $0 :
This script is a install and configurtion helper for Arch Linux. Read Arch Wiki if you need some help!
You can use it just to display configurations, as a manual, as a configuratios helper or as a installation tool.

Pakages you might need but you have to install manualy:
For intel: intel-ucode
For wlan: wpa_supplicant, dialog

Keyboard - option -k :
As a default model=pc105, variant=nodeadkeys and options=caps:numlock are preselectet. These values will fit to most cases. Edit skript sektion #keyboard if you want to change this values. To search values use the following commands: 'localectl list-x11-keymap-models |less' 'localectl list-x11-keymap-variants |less' localectl list-x11-keymap-options |less.

Locales - /etc/locale.conf - /etc/locale.gen - option l :
Both files /etc/locale.conf and /etc/locale.gen are configred with the language_COUNTRY code <ll__CC>
To aktivate LC_COLLATE=C (first all little than all big letters) collation behaviour decommend this line in '/etc/locale.conf' file afer you used the -l option.

Partition and Arch install - option -p
This partioniering fit's both Bios and UEFI systems. Do a manuel partioniering if you prefer another partioniering.
SSD drives will need a manualy edit of /etc/fstab.
If you need swap volumen you can add a dynamic swap later.
Splitting root-file-system on diffent disks, you can manage later.
Grup will be installed as the most commen boot loader. Change this in the script if you perfer another bootloader.


Display configurations - option -s :
Will show all configuration settings.

Virtual Console - /etc/vconsole.conf - option -v :
Fonts for virtual console will allways be configerd with 'FONT=lat9w-16' to search for other fonts do 'find /usr/share/kbd/consolefonts -type f | less'. Edit the vconsole.conf section in this script.

EOF
}

# help message
usage()
{
cat << EOF
$0 configures and installs Arch Linux

usage: $0 [option] [argument]
 -a            About $0
 -g <driver>  Install a grafik driver 
 -h            Display this help message
 -k <ll>       Set-x11-keymap <language> code
 -l <ll_CC>    Set <language_COUNTRY> code in locale files
 -m <myhost>   Set hostname
 -p <sdX>      Partition a disk and install Arch Linux base
 -s            Display configurations
 -t <timezone> Set timezone
 -v <keymap>   Set vconsole keymap
 -x <GUI>   Configure xorg and Insall a desktop 

Examples:
$0 -k fr -l fr_CA -m mon-pc -t Canada/Atlantic -v fr-latin1
$0 -k de -l de_DE -m mein-pc -t Europe/Berlin -v de-latin1-nodeadkeys

Terminal commands you may need to search for arguments:
k) localectl list-x11-keymap-layouts | less
l) cat /etc/locale.gen
t) find /usr/share/zoneinfo -type f | less
v) find /usr/share/kbd/keymaps/i386/ -type f | grep <search string>

EOF
}

# Display configurationes
sconf()
{
echo ""
echo "----------------------------"
echo "Display some configurations:"
echo "----------------------------"
echo "echo cat /etc/hostname:"
cat /etc/hostname
echo ""
echo "echo cat /etc/locale.conf:"
cat  "/etc/locale.conf"
echo ""
echo "echo locale -a"
locale -a
echo ""
echo "echo locale"
locale
echo ""
echo "echo localectl status:"
localectl status
echo ""
echo "echo timedatectl status:"
timedatectl status
echo ""
echo "echo cat /etc/vconsole.conf:"
cat /etc/vconsole.conf
echo ""
}

# optargs
while getopts ":ahk:l:m:p:st:v:" OPTION; do
  case $OPTION in
        a ) about; exit 1 ;;
        h ) usage; exit 1 ;;
        k ) layout=$OPTARG ;;
         l ) ll_CC=$OPTARG ;;
        m ) myhost=$OPTARG ;;
        p ) sdX=$OPTARG ;;
        s ) sconf; exit 1 ;;
        t ) tizo=$OPTARG ;;
        v ) vconsole=$OPTARG ;;
         \? )  echo "The option -$OPTARG is not guilty." && usage >&2; exit 1 ;;
        : )  echo "Option -$OPTARG requires an argument!"; exit 1 ;;
  esac
done

# check options and arguments
if  [[ $layout"x" == "x" ]] && [[ $ll_CC"x" == "x" ]] && [[ $myhost"x" == "x" ]] && [[ $tizo"x" == "x" ]] && [[ $vconsole"x" == "x" ]] && [[ $sdX"x" == "x" ]]; then  
    echo "Choose an option!"; exit 1
fi

if ( ! localectl list-x11-keymap-layouts | grep -q "$layout" ) || [[ "$layout" == [a-z] ]]; then 
    echo "Nothing configured. Do 'localectl list-x11-keymap-layouts | less' to get values for -k option!"; exit 1
fi

if [[ $ll_CC"x" != "x" ]];then
    if ( ! grep -q "$ll_CC" "/etc/locale.gen" ) || (  [[ "$ll_CC" != [a-z][a-z]_[A-Z][A-Z] ]] && [[ "$ll_CC" != [a-z][a-z][a-z]_[A-Z][A-Z] ]] ); then 
    echo "Nothing configured. Do 'cat /etc/locale.gen' to get values for -l option!"; exit 1
    fi
fi

if ( ! find "/usr/share/zoneinfo/" -type f | grep -wq "$tizo" ); then  
    echo "Argument in -t is not guilty!"; echo  "Find timezone, with: 'find /usr/share/zoneinfo -type f | less'"; exit 1
fi

if ( ! find "/usr/share/kbd/keymaps/i386/" -type f | grep -qw "$vconsole" ); then 
    echo "The argument in -v is not guilty! Find keyboard map, with: 'find /usr/share/kbd/keymaps/i386/ -type f | grep' <search string>'";  exit 1
fi

# hier noch option p für falsche Argumente sichern.

# partion
if [[ $sdX"x" != "x" ]]; then
lsblk
echo "This will delete all data on $sdX"

echo "Sicherheit geht vor!"
exit 1

printf "o\nn\n+10MB\nEF02n\n+550MB\nEF00\nw\ny\n" | gdisk /dev/$sdX

mkfs.fat -F32 /dev/$sdX2
mkfs.ext4 /dev/$sdX3
mount /dev/$sdX3 /mnt 
mkdir /mnt/boot
mount /dev/$sdX2 /mnt/boot
pacstrap /mnt base base-devel
genfstab -U /mnt >> /mnt/etc/fstab
cat /mnt/etc/fstab
arch-chroot /mnt /bin/bash
hwclock --systohc
sed -ie "/#/!s/^/#/" "/etc/pacman.d/mirrorlist"
pacman -S grub
grub-mkconfig -o /boot/grub/grub.cfg
#Booten per BIOS
grub-install /dev/sda
#Booten per UEFI
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub
exit
umount /mnt/boot
umount /mnt
fi

# keyboard
echo ""
 $layout="${ll_CC%_*}"
if [[ $layout"x" != "x" ]]; then
    model=pc105
    variant=nodeadkeys
    options=caps:numlock
    echo "Set-x11-keymap..."
    localectl set-x11-keymap [$layout] [$model] [$variant] [$options]
fi

if [[ $ll_CC"x" != "x" ]]; then
    # set ll
    ll="${ll_CC%_*}"
    # edit /etc/locale.conf
    #Hier muss evt. nachgebessert werden z.B. für tcy_IN.UTF-8 UTF-8
    echo "Edit /etc/locale.conf..."
    cat > "/etc/locale.conf" << EOF
    LANG=$ll_CC.UTF-8
    LANGUAGE=$ll_CC:pt:BR
    #LC_COLLATE=C
    LC_TIME=$ll_CC.UTF-8
    LC_PAPER=$ll_CC.UTF-8
    LC_MEASUREMENT=$ll_CC.UTF-8
    LC_MONETARY=$ll_CC.UTF-8
    LC_NUMERIC=$ll_CC.UTF-8
    LC_CTYPE=$ll_CC.UTF-8
    LC_MESSAGES=$ll_CC.UTF-8
    LC_NAME=$ll_CC.UTF-8
    LC_ADDRESS=$ll_CC.UTF-8
    LC_TELEPHONE=$ll_CC.UTF-8
    LC_IDENTIFICATION=$ll_CC.UTF-8
    LC_ALL=
EOF

    # reconfigure /etc/locale.gen.
    sed -ie "/#/!s/^/#/" "/etc/locale.gen"

    # edit /etc/locale.gen
    echo "Edit /etc/locale.gen..."
    sed -ie "s/#$ll_CC/$ll_CC/" "/etc/locale.gen"
    sed -ie "s/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" "/etc/locale.gen"
    echo "locale-gen..."
    echo ""
    locale-gen
    echo ""
fi

# edit /etc/hostname
if [[ $myhost"x" != "x" ]]; then
    echo "Edit /etc/hostname..."
    echo $myhost > /etc/hostname
fi

#ln /etc/localtime
if [[ $tizo"x" != "x" ]]; then
    echo "Set symlink to /etc/localtime..."
    ln -sf /usr/share/zoneinfo/$tizo /etc/localtime
fi

# edit /etc/vconsole.conf
if [[ $vconsole"x" != "x" ]]; then
    echo "Edit /etc/vconsole.conf..."
    echo KEYMAP="$vconsole" > "/etc/vconsole.conf"
    echo FONT=lat9w-16 >> "/etc/vconsole.conf"
fi

echo ""
exit 0

Offline

#3 07.02.2018 21:12:06

LinLin
Mitglied

Re: naad.sh version0.2(beta)config helper - Bitte fertigstellen

Ähhhm @tuxnix

Ich bin nur für den Verkauf und die Werbung zuständig.

Ich hab's aus:
Zen Installer - Ein grafischer Installer für Arch Linux
Beitrag #63
kopiert big_smile

Jeder Fehler der vom Kunde bemängelt wird geht auf deine Kappe wink

Ne... Spaß bei Seite. Ich find es klasse das du dich wieder voll reinhängst big_smile

Offline

#4 07.02.2018 22:02:51

tuxnix
Mitglied

Re: naad.sh version0.2(beta)config helper - Bitte fertigstellen

Ja, ja, so sind die Verkäufer.
Große Profite machen, aber für nichts verantwortlich. sad

Jetzt hab ich dich schon als CHE (Chef der humoristischen Exekutive) ins Team aufgenommen.
Denke das hat so seine Richtigkeit.

Mal ganz, ganz im Erst.
Humor gehört zu den wichtigsten Sachen überhaupt.

Humor:
Oben ist das Paradox des Lebens, das so recht niemand verstehen kann.
Unten lauert die Gewissheit des Todes.
Dazwischen kann nur das Zwerchfell vermitteln.

Beitrag geändert von tuxnix (07.02.2018 22:09:43)

Offline

#5 08.02.2018 19:18:27

LinLin
Mitglied

Re: naad.sh version0.2(beta)config helper - Bitte fertigstellen

Also ich hab jetzt 3 Bier und ich bin gut beieinander.... big_smile

Vielleicht hab ich auch 4, aber trotzdem sollten wir das Script fertig stellen.

Offline

#6 08.02.2018 19:34:58

drcux
Mitglied

Re: naad.sh version0.2(beta)config helper - Bitte fertigstellen

# start as root?
...
sudo

sudo ist nicht per default da, hatte es schon korrigiert

# exittrap
trap cleanupandexit 1 2 3 15

cleanupandexit()
{
mach etwas und melde fehler...
}

Hast du ja entfernt, ohne nachzudenken, wofür das ist....

cat << EOF

Kann man immer benutzen, wenn man ewig lange "echo" hat....

Offline

#7 08.02.2018 19:53:38

LinLin
Mitglied

Re: naad.sh version0.2(beta)config helper - Bitte fertigstellen

mhhhh ich versteh das nicht.

Ich lass euch 2 Chefentwickler mal allein.

Verkauf+Werbung = big_smile (Ich)

Beitrag geändert von LinLin (08.02.2018 19:56:54)

Offline

#8 08.02.2018 20:09:21

tuxnix
Mitglied

Re: naad.sh version0.2(beta)config helper - Bitte fertigstellen

@drcux

Hallo erstmal!

zu 1) # start as root?
Mich hat es noch nicht gestört weil ich auf meinem System teste.
Außerdem ist das von dir.
Wenn es aber was besseres gibt, gerne immer her damit.

zu 2) # exittrap
Ich fand das erst einmal sehr schön allein schon wegen dem sprachlichen Ausdruck "cleanupandexit"
Ich habe mir vorgestellt ich hätte eine Putzfrau und wenn sie es sich dann bei mir gemütlich machen will, rufe ich: "cleanupandexit". damit sie endlich geht. big_smile

Neh, mal im Erst, das hatte doch noch gar keine Funktion und die Meldung gebe ich mit echo genauso heraus.
Wenn es gebraucht wird dann ist es aber schnell wieder drinn.

zu 3) cat << EOF
Danke dir. Hab ich von dir gelernt. Und setze es auch ein.
In der neuesten (vers. 0.4 (leider alpha) gib es sogar ein cat | less << EOF

Ach was solls. Ich zeig es schon einmal, aber bitte nicht so laut meckern, ich weiß dass ich 3 Baustellen gleichzeitig aufgemacht habe.

#!/bin/bash
# naad version 0.4 (alpha) is a install and configurtion helper for Arch Linux.
# From tuxnix, drcux and LinLin with no garanty at all.

## User Configurations Section ##

root_passwd=12345
user=duda
user_passwd=12345
software="firefox"

#keyboard
model=pc105
variant=nodeadkeys
options=caps:numlock

#vconsole
FONT=lat9w-16

## The Script ##

# start as root?
if [ $UID -ne 0 ];  then
    sudo bash -c "$0 $*"; exit $?
fi

#about naad
about()
{
cat|less << EOF

About some $0 related aspects.

About $0 :
This script is a installation and configurtion helper for Arch Linux. Read Arch Wiki if you need some help!
You can use it just to display configurations, as a manual, as a configuratios helper or as a installation tool.

Pakages you might need but which you'll have to install manualy:
For intel: intel-ucode
For wlan: wpa_supplicant, dialog
If you do an installation wright software packages you need into the User Configuration Section. (software= )

Display configurations - option -d :
Will show all configuration settings.

Grafik driver - option -g :

Keyboard - option -k :
As a default model=pc105, variant=nodeadkeys and options=caps:numlock are preselectet. These values will fit to most cases. Edit User Configuration Section if you want to change this values. To search values use the following commands: 'localectl list-x11-keymap-models |less' 'localectl list-x11-keymap-variants |less' localectl list-x11-keymap-options |less.

Locales - /etc/locale.conf - /etc/locale.gen - option l :
Both files /etc/locale.conf and /etc/locale.gen are configred with the language_COUNTRY code <ll__CC>
To aktivate LC_COLLATE=C (first all little than all big letters) collation behaviour decommend this line in '/etc/locale.conf' file afer you used the -l option.

Partitioniring and Arch install - option -p :
This partioniering fit's both Bios and UEFI systems. Do a manuel partioniering if you prefer another constallation.
SSD drives will need a manualy edit of /etc/fstab.
If you need swap volumen you can add a dynamic swap later.
Splitting root-file-system on diffent disks, you can manage later.
Grup will be installed as the most commen boot loader. Change this in the script if you perfer another bootloader.

User - option -u
You have to set your name and passwort in User Configuration Section first. (default duda - 12345)
If you run a nnew installation with $o a new user gets a xorg configuration so that desktop will start with 'startx' command after user login. 

Virtual Console - /etc/vconsole.conf - option -v :
Fonts for virtual console will allways be configerd with 'FONT=lat9w-16' to search for other fonts do 'find /usr/share/kbd/consolefonts -type f | less'. Edit the User Configuration Section.

xorg and desktop GUI - option -x :
LXDE, Xfce, LXQT, plasma and GNOME are implemented jet all with a minimal paket set.

FAQ:
Q: Why no display/login manager is implemented?
A: Some grafikcards and drivers causes trouble in combination with some display managers and desktop GUI's. It is better system starts first in terminal so you'll get the chance to fix these problems first.
When the desktop GUI is running without a problem, install a display manager of your choise.

EOF
}

# Display configurationes
dconf()
{
echo ""
echo "----------------------------"
echo "Display some configurations:"
echo "----------------------------"
echo "echo cat /etc/hostname:"
cat /etc/hostname
echo ""
echo "echo cat /etc/locale.conf:"
cat  "/etc/locale.conf"
echo ""
echo "echo locale -a"
locale -a
echo ""
echo "echo locale"
locale
echo ""
echo "echo localectl status:"
localectl status
echo ""
echo "echo timedatectl status:"
timedatectl status
echo ""
echo "echo cat /etc/vconsole.conf:"
cat /etc/vconsole.conf
echo ""
}

# help message
usage()
{
cat << EOF
$0 configures and installs Arch Linux

usage: $0 [option] [argument]
 -a            About $0
 -d            Display configurations
 -g <driver>   Install a grafik driver
 -h            Display this help message
 -k <ll>       Set-x11-keymap <language> code
 -l <ll_CC>    Set <language_COUNTRY> code in locale files
 -lang         Install language pakages (Not implemented jet)
 -m <myhost>   Set hostname
 -p <sdX>      Partition a disk and install Arch Linux base
 -t <timezone> Set timezone
 -u            Add a user (Set name and passwd in User Configuration Section first)
 -v <keymap>   Set vconsole keymap
 -x <GUI>      Configure xorg and Insall a desktop

Examples:
$0 -k fr -l fr_CA -m mon-pc -t Canada/Atlantic -v fr-latin1
$0 -k de -l de_DE -m mein-pc -t Europe/Berlin -v de-latin1-nodeadkeys

Terminal commands you may need to search for arguments:
k) localectl list-x11-keymap-layouts | less
l) cat /etc/locale.gen
t) find /usr/share/zoneinfo -type f | less
v) find /usr/share/kbd/keymaps/i386/ -type f | grep <search string>

EOF
}

# optargs
while getopts ":adg:hk:l:m:p:t:uv:x:" OPTION; do
  case $OPTION in
        a ) about; exit 1 ;;
        d ) dconf; exit 1 ;;
        g ) gdriver=$OPTARG ;;
        h ) usage; exit 1 ;;
        k ) layout=$OPTARG ;;
         l ) ll_CC=$OPTARG ;;
        m ) myhost=$OPTARG ;;
        p ) sdX=$OPTARG ;;
        t ) tizo=$OPTARG ;;
        u ) setuser; exit 1 ;;
        v ) vconsole=$OPTARG ;;
        x ) desktop=$OPTARG ;;
         \? )  echo "The option -$OPTARG is not guilty." && usage >&2; exit 1 ;;
        : )  echo "Option -$OPTARG requires an argument!"; exit 1 ;;
  esac
done

# check options and arguments
if  [[ $layout"x" == "x" ]] && [[ $ll_CC"x" == "x" ]] && [[ $myhost"x" == "x" ]] && [[ $tizo"x" == "x" ]] && [[ $vconsole"x" == "x" ]] && [[ $sdX"x" == "x" ]] && [[ $gdriver"x" == "x" ]] && [[ $desktop"x" == "x" ]]; then  
    echo "Choose an option!"; exit 1
fi

if ( ! localectl list-x11-keymap-layouts | grep -q "$layout" ) || [[ "$layout" == [a-z] ]]; then 
    echo "Nothing configured. Do 'localectl list-x11-keymap-layouts | less' to get values for -k option!"; exit 1
fi

if [[ $ll_CC"x" != "x" ]];then
    if ( ! grep -q "$ll_CC" "/etc/locale.gen" ) || (  [[ "$ll_CC" != [a-z][a-z]_[A-Z][A-Z] ]] && [[ "$ll_CC" != [a-z][a-z][a-z]_[A-Z][A-Z] ]] ); then 
    echo "Nothing configured. Do 'cat /etc/locale.gen' to get values for -l option!"; exit 1
    fi
fi

if ( ! find "/usr/share/zoneinfo/" -type f | grep -wq "$tizo" ); then  
    echo "Argument in -t is not guilty!"; echo  "Find timezone, with: 'find /usr/share/zoneinfo -type f | less'"; exit 1
fi

if ( ! find "/usr/share/kbd/keymaps/i386/" -type f | grep -qw "$vconsole" ); then 
    echo "The argument in -v is not guilty! Find keyboard map, with: 'find /usr/share/kbd/keymaps/i386/ -type f | grep' <search string>'";  exit 1
fi

# hier option -p für falsche Argumente bei $sdX absichern.
# hier option -g für falsche Argumente sichern.
# hier option -x für falsche Argumente sichern.
# oder als einzelne funktion definieren und es dort tun. 

# partitioniering
if [[ $sdX"x" != "x" ]]; then
lsblk
echo "This will delete all data on $sdX"

echo "Sicherheit geht vor!"
exit 1

printf "o\nn\n+10MB\nEF02n\n+550MB\nEF00\nw\ny\n" | gdisk /dev/$sdX

mkfs.fat -F32 /dev/$sdX2
mkfs.ext4 /dev/$sdX3
mount /dev/$sdX3 /mnt 
mkdir /mnt/boot
mount /dev/$sdX2 /mnt/boot
pacstrap /mnt base base-devel
genfstab -U /mnt >> /mnt/etc/fstab
cat /mnt/etc/fstab
arch-chroot /mnt /bin/bash
hwclock --systohc
sed -ie "/#/!s/^/#/" "/etc/pacman.d/mirrorlist"
pacman -S grub
grub-mkconfig -o /boot/grub/grub.cfg
#Booten per BIOS
grub-install /dev/sda
#Booten per UEFI
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub
exit
umount /mnt/boot
umount /mnt
fi

# installing grafikdriver
if [[ $gdriver"x" != "x" ]]; then
gdrivers=([0]=xf86-video-nouveau Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)

if

# install xorg and desktop GUI
desktop ()
{
desktops=([0]=LXDE Xfce LXQT plasma GNOME)
if [[ $desktop != $desktop ]]; then
    echo "$desktop is not defind"
if

if [[ $desktop"x" != "x" ]]; then

       if [[ $desktop == LXDE ]]; then
            packeges="openbox lxsession lxpanel lxde-common lxde-icon-theme"
    elif [[ $desktop == Xfce ]]; then
            packeges="openbox  xfce4-session xfce4-panel human-icon-theme xfce4-terminal"
    elif [[ $desktop == LXQT ]]; then
            packeges="openbox lxqt-session lxqt-pannel breeze-icons"
    elif [[ $desktop == plasma ]]; then
            packeges="kwin plasma-desktop plasma-wayland-session plasma-nm plasma-pa plasma-nm breeze"
    elif [[ $desktop == GNOME ]]; then
            packeges="mutter gnome-desktop gnome-session networkmanager gnome-themes-standard nm-connection-editor gnome-control-center gnome-shell"
       fi

    if [[ $sdX"x" != "x" ]]; then
        mount /dev/$sdX /mnt
        arch-chroot /mnt /bin/bash
        pacman -S "xorg-server xorg-xinit $packeges $software"
        exit
        umount /mnt
    else
        if [[ pacman -Qs xorg-server ]]; then
            pacman -S "$packeges"
        else
            pacman -S "xorg-server xorg-xinit $packeges"
        fi
    fi
fi
}

# set a user
setuser()
{
if  [[ $layout"x" == "x" ]] && [[ $ll_CC"x" == "x" ]]; then
    echo "Set name and password in the user configuration section"
else
    if [[ $sdX"x" != "x" ]]; then
        mount /dev/$sdX /mnt
        arch-chroot /mnt /bin/bash
        useradd -p `mkpasswd "$user_passwd"` -d /home/"$user" -m -g users -G wheel,audio,video,games,power -s /bin/bash "$user"
        cp /etc/sudoers /etc/sudoers.bak
        sed 's/#%wheel ALL=(ALL) ALL /%wheel ALL=(ALL) ALL_/g'` /etc/sudoers
        exit
        umount /mnt
    else
        useradd -p `mkpasswd "$user_passwd"` -d /home/"$user" -m -g users -G wheel,audio,video,games,power -s /bin/bash "$user"
        cp /etc/sudoers /etc/sudoers.bak
        sed 's/#%wheel ALL=(ALL) ALL /%wheel ALL=(ALL) ALL_/g'` /etc/sudoers
fi
    
}

# keyboard
echo ""
 $layout="${ll_CC%_*}"
if [[ $layout"x" != "x" ]]; then
    echo "Set-x11-keymap..."
    localectl set-x11-keymap [$layout] [$model] [$variant] [$options]
fi

if [[ $ll_CC"x" != "x" ]]; then
    # set ll
    ll="${ll_CC%_*}"
    # edit /etc/locale.conf
    #Hier muss noch nachgebessert werden z.B. für tcy_IN.UTF-8 UTF-8
    echo "Edit /etc/locale.conf..."
    cat > "/etc/locale.conf" << EOF
    LANG=$ll_CC.UTF-8
    LANGUAGE=$ll_CC:pt:BR
    #LC_COLLATE=C
    LC_TIME=$ll_CC.UTF-8
    LC_PAPER=$ll_CC.UTF-8
    LC_MEASUREMENT=$ll_CC.UTF-8
    LC_MONETARY=$ll_CC.UTF-8
    LC_NUMERIC=$ll_CC.UTF-8
    LC_CTYPE=$ll_CC.UTF-8
    LC_MESSAGES=$ll_CC.UTF-8
    LC_NAME=$ll_CC.UTF-8
    LC_ADDRESS=$ll_CC.UTF-8
    LC_TELEPHONE=$ll_CC.UTF-8
    LC_IDENTIFICATION=$ll_CC.UTF-8
    LC_ALL=
EOF

    # reconfigure /etc/locale.gen.
    sed -ie "/#/!s/^/#/" "/etc/locale.gen"

    # edit /etc/locale.gen
    echo "Edit /etc/locale.gen..."
    sed -ie "s/#$ll_CC/$ll_CC/" "/etc/locale.gen"
    sed -ie "s/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" "/etc/locale.gen"
    echo "locale-gen..."
    echo ""
    locale-gen
    echo ""
fi

# edit /etc/hostname
if [[ $myhost"x" != "x" ]]; then
    echo "Edit /etc/hostname..."
    echo $myhost > /etc/hostname
fi

#ln /etc/localtime
if [[ $tizo"x" != "x" ]]; then
    echo "Set symlink to /etc/localtime..."
    ln -sf /usr/share/zoneinfo/$tizo /etc/localtime
fi

# edit /etc/vconsole.conf
if [[ $vconsole"x" != "x" ]]; then
    echo "Edit /etc/vconsole.conf..."
    echo KEYMAP="$vconsole" > "/etc/vconsole.conf"
    echo FONT=$FONT >> "/etc/vconsole.conf"
fi

echo ""
exit 0

Beitrag geändert von tuxnix (08.02.2018 20:26:22)

Offline

#9 13.02.2018 19:44:34

drcux
Mitglied

Re: naad.sh version0.2(beta)config helper - Bitte fertigstellen

tuxnix schrieb:

zu 2) # exittrap
Ich fand das erst einmal sehr schön allein schon wegen dem sprachlichen Ausdruck "cleanupandexit"
Ich habe mir vorgestellt ich hätte eine Putzfrau und wenn sie es sich dann bei mir gemütlich machen will, rufe ich: "cleanupandexit". damit sie endlich geht. big_smile

Neh, mal im Erst, das hatte doch noch gar keine Funktion und die Meldung gebe ich mit echo genauso heraus.
Wenn es gebraucht wird dann ist es aber schnell wieder drinn.

1.

Falscher Ansatz "Brauch ich nicht, kann man ja später wieder einbauen":

Einen zentralen Exit-Ausgang mit Ausgabe der Fehlermeldung kann man +immer+ gebrauchen, stell dir mal vor, du willst die Fehlerausgabe doch etwas anders gestalten, dann musst du alle "echo $fehler" anpassen. Mit einem sauberen exit brauchst du nur an einer Stelle deinen Code ändern.

2.

cleanupandexit hat schon noch mehr Funktionen:

Mit "trap cleanupandexit 1 2 3 15" wird der "doofe" Nutzer auch abgefangen, du hast die Chance aktive Mounts wieder zu unmounten wenn der User STRG-C drückt. Du kannst die Katastrophe abfangen, wenn der User beim Ausführen von grub-install abbricht, etc.

Offline

#10 13.02.2018 21:14:37

tuxnix
Mitglied

Re: naad.sh version0.2(beta)config helper - Bitte fertigstellen

Zur Dokumentation des Fortschritts  aber auch zur Sicherung, hier die nächste alpa Version:
(Alpha ist nocht nicht für Betatester geeignet.)

Vorsicht, die Option '-p sdX' partitioniert die Festplatte!

Viele Änderungen und einige Baustellen weniger:
Option -u legt einen neuen user an.
Option -s installiet Software.
Option -x installiert eine Desktop GUI

#!/bin/bash
# naad version 0.5.0 (alpha) FAFBL 1.0 is a install and configurtion tool for Arch Linux.
# From tuxnix, drcux and LinLin with no garanty at all.

#### User-Configurations-Section ####

root_passwd=secret
user=arch_user
user_passwd=secret
groups=( wheel audio video games power )

packages="sudo aspell hunspell firefox"

#keyboard
model=pc105
variant=nodeadkeys
options=caps:numlock

#vconsole
FONT=lat9w-16

#### The-Script ####

# start as root?
if [ $UID -ne 0 ];  then
    sudo bash -c "$0 $*"; exit $?
fi

## Display-Section ##

#about naad
about(){
cat|less << EOF

About $0:
This script is a installation and configuration tool for Arch Linux. Read Arch Wiki if you need some help!
You can use it just to display configurations, as a manual, as a configuratios helper or as a installation tool.

Packages and services you might need but you'll have to install them manualy.
For::
Intel: intel-ucode
WLAN: wpa_supplicant, wireless_tools, dialog
Notebooks: acpid
If you need some of these software packages edit 'software=' in User-Configuration-Section.
To activate acpid.service do a 'systemctl enable --now acpid.service' command on terminal.

Grafik driver - option -g:
Closed NVIDIA driver will need some manual configuration aferwards.

Keyboard - option -k:
As a default model=pc105, variant=nodeadkeys and options=caps:numlock are preselectet. These values will fit to most cases. Edit User Configuration Section if you want to change these values. To search values use the following commands: 'localectl list-x11-keymap-models |less' 'localectl list-x11-keymap-variants |less' localectl list-x11-keymap-options |less.

Locales - /etc/locale.conf - /etc/locale.gen - option -l:
Both files /etc/locale.conf and /etc/locale.gen are configred with the language_COUNTRY code <ll_CC>
To aktivate LC_COLLATE=C (first all little than all big letters) collation behaviour decommend this line in '/etc/locale.conf' file afer you used the -l option.

Partitioniring and Arch base install - option -p:
This partioniering fit's both Bios and UEFI systems. (Grub for BIOS in partition sdX1 (10MB), a boot Partition for UEFI (550MB)  sdX2 and a sdX3 partition for rootfs on the rest of the disk). Do a manuel partitioniering if you prefer another constallation (Or edit gdisk in this script).
SSD drives will need a manualy edition of /etc/fstab.
If you need swap volumen you can add a dynamic swap or change gdisk command in this script (printf "o\ny\n n\n\n\n+10M\nEF02\nn\n\n\n+550M\nEF00\nn\n120\n\n+(your RAM size)G\n\nw\ny\n" | gdisk /dev/$sdX) to get a swap partition.

Splitting root-file-system onto diffent disks, can be managed later (mount disks and use genfstab).
Grup will be installed as the most commen boot loader. Change this in the script if you perfer another bootloader.

Sofware - option -s:
It's your choise. Edit User Configuration Section.
Langguage packages will be installed automaticaly.

User - option -u
You have to set a name and password in User Configuration Section. (Now this ist set to: $user - $user_passwd)
The user will become menber of the following groups: $groups

Virtual Console - /etc/vconsole.conf - option -v:
Fonts for virtual console will allways be configerd with 'FONT=lat9w-16' to search for other fonts do 'find /usr/share/kbd/consolefonts -type f | less'. Edit the User Configuration Section.

Xorg and desktop GUI - option -x:
lxde, xfce4, lxqt, plasma and gnome are implemented jet all with a minimal package set.
The first user will get a xorg configuration so that desktop will start with 'startx' command after user login.

Log-Sektion
Under 'exit 0 there are some logs. You can delete these logs form time to time. If 'Internet' and 'Update' are noticed here these checks will not be done by script anymore.

FAQ:
Q: Why no display/login manager is implemented?
A: Some grafikcards and drivers causes trouble in combination with some display managers and desktop-GUI's. It is better system starts first in terminal so you'll get the chance to fix these problems.
Start desktop GUI with 'startx' after user login from terminal. (xorg is configured.) When GUI is running well, install a display manager of your choise.

EOF
}

# Display configurationes
dconf(){
echo ""
echo "----------------------------"
echo "Display some configurations:"
echo "----------------------------"
echo "echo cat /etc/hostname:"
cat /etc/hostname
echo ""
echo "echo cat /etc/locale.conf:"
cat  "/etc/locale.conf"
echo ""
echo "echo locale -a"
locale -a
echo ""
echo "echo locale"
locale
echo ""
echo "echo localectl status:"
localectl status
echo ""
echo "echo timedatectl status:"
timedatectl status
echo ""
echo "echo cat /etc/vconsole.conf:"
cat /etc/vconsole.conf
echo ""
}

# help message
usage(){
cat << EOF
$0 - Install and configure Arch Linux

Usage: $0 [option] [argument]
 -a            About: $0 (man page)
 -d            Display configurations
 -g <driver>   Install a grafik driver
 -h            Display this help
 -k <ll>       Set-x11-keymap <language> code
 -l <ll_CC>    Set <language_COUNTRY> code in locale files
 -m <my-host>  Set hostname
 -p <sdX>      Partition a disk and install Arch base (Will delete all data on disk sdX)
 -s <ll>       Install software and language packages. (Edit 'software=' in UCS first.)
 -t <timezone> Set timezone
 -u            Add a user (Set 'name= and passwd=' in User Configuration Section first)
 -v <keymap>   Set vconsole keymap
 -x <GUI>      Configure xorg and Insall a desktop GUI
 -?            Display this help message

Example:
$0 -g xf86-video-nouveau -k de -l de_DE -m mein-pc -s de -t Europe/Berlin -u -v de-latin1 -x lxqt

Terminal commands you may need to search for arguments:
g) pacman -Ssq xf86-video nvidia
k) localectl list-x11-keymap-layouts | less
l) cat /etc/locale.gen
p) lsblk or fdisk -l
t) find /usr/share/zoneinfo -type f | less
v) find /usr/share/kbd/keymaps/i386/ -type f | grep <search string>

EOF
}

## Menu-Section ##

# optargs
while getopts ":adg:hk:l:m:p:s:t:uv:x:" OPTION; do
  case $OPTION in
       
        a ) about; exit 1 ;;
        d ) dconf; exit 1 ;;
        g ) gdriver=$OPTARG ;;
        h ) usage; exit 1 ;;
        k ) layout=$OPTARG ;;
        l ) ll_CC=$OPTARG ;;
        m ) myhost=$OPTARG ;;
        p ) sdX=$OPTARG ;;
        s ) ll=$OPTARG ;;
        t ) timezone=$OPTARG ;;
        u ) $OPTARG ;;
        v ) vconsole=$OPTARG ;;
        x ) desktop=$OPTARG ;;
        \? )  echo "The option -$OPTARG is not guilty."; exit 1 ;;
        : )  echo "Option -$OPTARG requires an argument!"; exit 1 ;;
  esac
done

# check if a option is set
option=("$@")
if [[ ${option[0]}"x" == "x" ]]; then
    echo "Choose an option!"; exit 1
fi

## Funktion-Section ##

# exittrap
trap cleanupandexit 1 2 3 15
cleanupandexit()
{
exit 1
}

# Internet Connection
intcon(){
echo ""
echo "Test internet connection..."
if ( ! ping -qc1 www.archlinux.org ); then
    echo "Exit! For option -g, -s and -x internet connection is needed.";  cleanupandexit
else
    printf "log=`date --date=now` - Succsess: Internet Connection\n" >> $0
fi
}

# package update
packupdate(){
echo ""
echo "Exec: pacman  --noconfirm -Syu..."
pacman --noconfirm -Syu
#auf Fehlercode prüfen. Hier wird bis jetzt nur eine Ausgabe gemacht!
printf "log=`date --date=now` - Succsess: Package Update\n" >> $0
}

xorginstall(){
echo ""
echo "Exec: pacman -S --needed --noconfirm xorg-server xorg-xinit..."
pacman -S --needed --noconfirm xorg-server xorg-xinit
#auf Fehlercode prüfen. Hier wird bis jetzt nur eine Ausgabe gemacht!
printf "log=`date --date=now` - Succsess: Install xorg\n" >> $0
}

## Exec-Option-Section ##

# check  argumentes - option -g
for opt in ${option[@]}; do
    if [[ $opt == -g ]]; then
       declare -a grafikdrivers=("xf86-video-amdgpu" "xf86-video-ati" "xf86-video-dummy" "xf86-video-fbdev" "xf86-video-intel" "xf86-video-nouveau" "xf86-video-openchrome" "xf86-video-sisusb" "xf86-video-vesa" "xf86-video-vmware" "xf86-video-voodoo" "xf86-video-qxl")
       echo ""
       for (( i=1; i<12; i++ )); do
          if [[ ${grafikdrivers[$i]} != $gdriver ]]; then
             nodriver=0
        elif [[ ${grafikdrivers[$i]} == $gdriver ]]; then
             yesdrive=1
          fi
       done
    fi
done

if [[ $yesdrive == 0 ]]; then
    echo "Argument '$gdriver' is not listed in $0 as a free grafik-driver."
    echo "Perhaps you need one of these:"
    for (( i=1; i<12; i++ )); do
        echo $i") "  ${grafikdrivers[$i]}
    done
    echo ""; cleanupandexit
else
# Install grafikdriver - option -g
    if [[ $gdrive == 1  ]]; then
        echo "Exec: pacman -S --needed --noconfirm $gdriver..."
        pacman -S --needed --noconfirm $gdriver
    fi
fi

# edit /etc/hostname - option -h
if [[ $myhost"x" != "x" ]]; then
    echo "Exec: echo '$myhost' > /etc/hostname..."
    echo $myhost > /etc/hostname
    echo "done..."
fi

# keyboard - option -k
for opt in ${option[@]}; do
   if [[ $opt == -k ]]; then
   echo ""
        if ( ! localectl list-x11-keymap-layouts | grep -q "$layout" ) || [[ "$layout" == [a-z] ]]; then 
            echo "Nothing configured!"
            echo "Exec 'localectl list-x11-keymap-layouts | less' to get values for -k option!"
            echo ""; cleanupandexit
        else
            echo "Exec: localectl set-x11-keymap [$layout] [$model] [$variant] [$options]..."
            localectl set-x11-keymap [$layout] [$model] [$variant] [$options]
            echo "done..."
            echo ""
        fi
    fi
done

# check argumentes option -l
if [[ $ll_CC"x" != "x" ]]; then
    if ( ! grep -q "$ll_CC" "/etc/locale.gen" ) || (  [[ "$ll_CC" != [a-z][a-z]_[A-Z][A-Z] ]] && [[ "$ll_CC" != [a-z][a-z][a-z]_[A-Z][A-Z] ]] ); then 
    echo "Nothing configured. Do 'cat /etc/locale.gen' to get values for -l option!"; cleanupandexit
    fi
fi

# edit /etc/locale.gen - option -l
if [[ $ll_CC"x" != "x" ]]; then
    # set ll
    ll="${ll_CC%_*}"
    # edit /etc/locale.conf
    #Hier muss noch nachgebessert werden z.B. für tcy_IN.UTF-8 UTF-8
    echo "Exec: echo '$ll_CC' > /etc/locale.conf..."
    cat > "/etc/locale.conf" << EOF
    LANG=$ll_CC.UTF-8
    LANGUAGE=$ll_CC:pt:BR
    #LC_COLLATE=C
    LC_TIME=$ll_CC.UTF-8
    LC_PAPER=$ll_CC.UTF-8
    LC_MEASUREMENT=$ll_CC.UTF-8
    LC_MONETARY=$ll_CC.UTF-8
    LC_NUMERIC=$ll_CC.UTF-8
    LC_CTYPE=$ll_CC.UTF-8
    LC_MESSAGES=$ll_CC.UTF-8
    LC_NAME=$ll_CC.UTF-8
    LC_ADDRESS=$ll_CC.UTF-8
    LC_TELEPHONE=$ll_CC.UTF-8
    LC_IDENTIFICATION=$ll_CC.UTF-8
    LC_ALL=
EOF
fi

if [[ $ll_CC"x" != "x" ]]; then
    # reconfigure /etc/locale.gen.
    sed -ie "/#/!s/^/#/" "/etc/locale.gen"
    echo "Exec: sed -ie s/#'$ll_CC'/'$ll_CC'/ /etc/locale.gen..."
    sed -ie "s/#$ll_CC/$ll_CC/" "/etc/locale.gen"
    echo "Exec: sed -ie s/#'en_US.UTF-8 UTF-8'/'en_US.UTF-8 UTF-8'/ "/etc/locale.gen"..."
    sed -ie "s/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" "/etc/locale.gen"
    echo "Exec: locale-gen..."
    echo ""
    locale-gen
    echo ""
fi

# # Partition disk and install Arch base - option -p
for opt in ${option[@]}; do
    if [[ $opt == -p ]]; then
        if [[ $sdX != sd[a-z] ]]; then echo "Choose a disk ( sda, sdb, sdc...) for Partitioniering."; cleanupandexit
        else
while true; do
  #clear
  echo "Partiton disk and install Arch Linux base on /dev/$sdX"!
  echo -n "Caution: All data on /dev/$sdX will be lost! y/N ? "; read f
  if [[ "$f" == "n" ]]; then cleanupandexit
  elif [[ "$f" == "y" ]]; then echo "Partiton disk $sdX"; sleep 13
  fi
done     
            printf "log=`date --date=now` - Starttime" >> $0
            
            printf "o\ny\nn\n\n\n+10M\nEF02\nn\n\n\n+550M\nEF00\nn\n\n\n\n\nw\ny\n" | gdisk /dev/$sdX
            echo "Partitioniering done..."
            printf "log=`date --date=now` - Succsess: Partitioniering $sdX\n" >> $0
            echo ""
            echo "Format $sdX"
            mkfs.fat -F32 "/dev/$sdX"2
            printf "y" | mkfs.ext4 "/dev/$sdX"3
            echo  ""
            echo "mount $sdX3 /mnt"
            mount /dev/$sdX"3" /mnt
            mkdir /mnt/boot
            echo "mount /dev/$sdX2 /mnt/boot"
            mount /dev/$sdX"2" /mnt/boot
            echo ""
            echo "Edit /etc/pacman.d/mirrorlist"
            sed -ie "s/#Server/Server/" "/etc/pacman.d/mirrorlist"
            echo "done..."
            echo "pacstrap /mnt base base-devel"
            pacstrap /mnt base base-devel
            echo "done..."
            echo ""
            echo "Generate /mnt/etc/fstab"
            genfstab -U /mnt >> /mnt/etc/fstab
            echo "done..."
            echo ""
            echo "cat /mnt/etc/fstab"
            cat /mnt/etc/fstab
            arch-chroot /mnt
            echo "systemctl enable systemd-timesyncd.service"
            systemctl enable systemd-timesyncd.service
            echo "done..."
            echo ""
            echo "pacman -Syyu --noconfirm"
            pacman -Syyu --noconfirm
            echo "done..."
            echo ""
            #echo "pacman -S grub"
            #pacman -S grub
            grub-mkconfig -o /boot/grub/grub.cfg
            #Booten per BIOS
            echo "grub-install - BIOS"
            grub-install
            printf "log=`date --date=now` - grub-install (for BIOS)" >> $0
            #Booten per UEFI
            echo "Install grub - UEFI "
            grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub
             printf "log=`date --date=now` - grub-install (UEFI)" >> $0
        echo "All done..."
        echo ""
        echo "exec mkinitcpio -p linux"
        mkinitcpio -p linux
        echo "done..."
        echo "Set root password"
        echo -e "$root_passwd'\n'$root_passwd'\n" | (passwd root)
        echo "done..."
        echo ""
        echo "exec pacman -Syu"
        pacman -Syu
        echo ""
        echo "Set hardware clock"
        hwclock --systohc && sync
        echo "done..."
        echo ""
        echo "Exit: arch-chroot" 
        exit
        printf "log=`date --date=now` - Exit: arch-chroot" >> $0
        echo "done..."
        cp $0 /usr/bin && sync
        #script_path="$(dirname "$0")"
        #script_name="$(basename "$0")"
        #cp "${script_path}/${script_name}" "/usr/bin/${script_name}"
        umount /mnt/boot
        umount /mnt
        echo ""
        echo "Arch base system is installed."
        printf "log=`date --date=now` - Arch base system installed" >> $0
        echo "Do a 'reboot' and change bootsequens to $sdX"
        echo ""
    fi
fi
done

# install software- option -s
for opt in ${option[@]}; do
    if [[ $opt == -s ]]; then
        if ( ! grep -q "[0-9][0-9][0-9][0-9] - Succsess: Internet Connection" $0 ); then intcon; fi
        if ( ! grep -q "[0-9][0-9][0-9][0-9] - Succsess: Package Update" $0 ); then packupdate; fi
        echo ""
        echo "Exec: pacman -S --needed --noconfirm $packages..."
        pacman -S --needed --noconfirm $packages
        #Install language packages
        echo ""
        if ( ! localectl list-x11-keymap-layouts | grep -q "$ll" ) || [[ "$ll" == [a-z] ]]; then
            echo "No language package installed!"
            echo "You need a language code."
            echo "Exec 'localectl list-x11-keymap-layouts | less' to get values for -k option!"
            echo ""; cleanupandexit
        else
        echo "Install language packages"
        declare -a pack=( man-pages aspell gimp hunspell firefox libreoffice libreoffice-fresh libreoffice-still thunderbird thunderbird plasma bluegriffon hyphen kompozer )
        
        if ( pacman -Qsq man-pages 1> /dev/null ); then langpack[0]=man-pages-$ll; fi
        if ( pacman -Qsq aspell 1> /dev/null ); then langpack[1]=aspell-$ll; fi
        if ( pacman -Qsq gimp 1> /dev/null ); then langpack[2]=gimp-help-$ll; fi
        if ( pacman -Qsq hunspell 1> /dev/null ); then langpack[3]=hunspell-$ll; fi
        if ( pacman -Qsq firefox 1> /dev/null ); then langpack[4]=firefox-i18n-$ll; fi
        if ( pacman -Qsq libreoffice-fresh 1> /dev/null ); then langpack[5]=libreoffice-fresh-$ll; fi
        if ( pacman -Qsq libreoffice-still 1> /dev/null ); then langpack[6]=libreoffice-still-$ll; fi
        if ( pacman -Qsq thunderbird 1> /dev/null ); then langpack[7]=thunderbird-i18n-$ll; fi
        if ( pacman -Qsq thunderbird 1> /dev/null ); then langpack[8]=kde-l10n-$ll; fi
        #if ( pacman -Qsq bluegriffon ); then langpack[9]=bluegriffon-i18n-$ll; fi
        if ( pacman -Qsq hyphen 1> /dev/null ); then langpack[10]=hyphen-$ll; fi
        if ( pacman -Qsq kompozer 1> /dev/null ); then langpack[11]=kompozer-i18n-$ll; fi

        pacman -Sq  --needed --noconfirm ${langpack[@]}
        fi
    fi
done

# ln /etc/localtime - option -t
for opt in ${option[@]}; do
    if [[ $opt == -t ]]; then
        if ( ! find "/usr/share/zoneinfo/" -type f | grep -wq "$timezone" ); then  
            echo "Argument in -t is not guilty!"; echo  "Find timezone, with: 'find /usr/share/zoneinfo -type f | less'"; cleanupandexit
        else
            echo "Exec: ln -sf /usr/share/zoneinfo/'$timezone' /etc/localtime..."
            ln -sf /usr/share/zoneinfo/$timezone /etc/localtime
            echo "done..."
            echo ""
        fi              
    fi
done

# Add a user - option -u
for opt in ${option[@]}; do
    if [[ $opt == -u ]]; then
        if [[ $user"x" == "x"  ]]; then
            echo ""
            echo "Set a user-name in User Configuration Section"
            echo ""; cleanupandexit
        elif [[ $user_passwd"x" == "x" ]]; then
            echo ""
            echo "Set a user-password in User Configuration Section"
            echo ""; cleanupandexit
        elif  [[ $user"x" != "x" ]] && [[ $user_passwd"x" != "x" ]]; then
            echo "Add user with name: $user"
            useradd -m -g users -s /bin/bash $user
            printf $user_passwd"\n"$user_passwd"\n" | passwd $user
            for group in ${groups[@]}; do
            gpasswd -a "$user" "$group"
            done
            echo ""
            echo "Activate wheel /etc/sudoers"
            sed 's/#%wheel ALL=(ALL) ALL /%wheel ALL=(ALL) ALL_/' "/etc/sudoers" 1> /dev/null
            echo "done..."
            echo ""
        fi
    fi
done
#userdel -r $user

# check argumentes option -v
for opt in ${option[@]}; do
    if [[ $opt == -v ]]; then
        if ( ! find "/usr/share/kbd/keymaps/i386/" -type f | grep -qw "$vconsole" ); then 
            echo "Wrong argument in option -v! Find keyboard map, with: 'find /usr/share/kbd/keymaps/i386/ -type f | grep' <search string>'";  cleanupandexit
        else
            echo "Exec: echo 'KEYMAP=$vconsole' > /etc/vconsole.conf..."
            echo KEYMAP="$vconsole" > "/etc/vconsole.conf"
            echo "Exec: echo 'FONT=$FONT' > /etc/vconsole.conf..."
            echo FONT=$FONT >> "/etc/vconsole.conf"
            echo "done..."
            echo ""
        fi
    fi
done

# Install desktop GUI -option -x
for opt in ${option[@]}; do
   if [[ $opt == -x ]]; then
        if [[ $desktop == lxde ]]; then
            packages="openbox lxsession lxpanel lxde-common lxde-icon-theme"
        elif [[ $desktop == xfce ]]; then
            packages="openbox xfce4-session xfce4-panel human-icon-theme xfce4-terminal"
        elif [[ $desktop == lxqt ]]; then
            packages="openbox lxqt-session lxqt-panel breeze-icons"
        elif [[ $desktop == plasma ]]; then
            packages="kwin plasma-desktop plasma-wayland-session plasma-nm plasma-pa breeze"
        elif [[ $desktop == gnome ]]; then
            packages="mutter gnome-desktop gnome-session networkmanager gnome-themes-standard nm-connection-editor gnome-control-center gnome-shell"
        else
            echo ""; echo "A desktop GUI '$desktop' is not known in $0."
            echo "Choose 'lxde', 'xfce4', 'lxqt', 'plasma', 'gnome' or install another GUI manualy."; echo ""; cleanupandexit
        fi
        if ( ! grep -q "[0-9][0-9][0-9][0-9] - Succsess: Internet Connection" $0 ); then intcon; fi
        if ( ! grep -q "[0-9][0-9][0-9][0-9] - Succsess: Package Update" $0 ); then packupdate; fi
        if ( ! grep -q "[0-9][0-9][0-9][0-9] - Succsess: Install xorg" $0 ); then xorginstall; fi    
      echo ""
      echo "Exec: pacman -S --needed --noconfirm $packages..."
      pacman -S --needed --noconfirm $packages
   fi
done

#sed -n 'd/log=Do/lala/' $0

exit 0
# Ausstehende Arbeiten:
# option -p
# option -l splitten.
# del logs option ?
# Logs ausbauen.

Glück im Unglück:
Nach dem letzten update des kenels (4.15.) wurde mein System instabil. Es blieb einfach stehen und ich musste mehrhmals Neustarten. Wie sich kurz später herrausstellte lag es nicht am kernel. Es war meine Festplatte die den Geist aufgab. Ein paar Daten konnte ich noch retten, den Rest versuche ich erst dann von der kaputten Festplatte rüberzuspielen wenn ich wieder ein System mit großer Festplatte zur Verfügung habe (noch bekomme ich Zugriff über USB-Adapter). Mein altes IBM ThinkPad T43 rettet mich derzeit. Habe es erst kürzlich auf Arch Linux 32 umgestellt und ich genieße gerade die butterweiche und exakte Tastatur, die besser funzt wie alles andere was ich bisher kennen lernen durfte.

Glück, für das Skript dabei ist, dass ich meinen bisherigen Arbeitsrechner als Testsystem umgebaut habe. Die Option -p wird hierdrauf getestet und das skript entwickelt sich so schneller. Eine beta Version wird herauskommen wenn es mir gelingt mit dem skript die komplette Arch Installation vorzunehmen.

Beitrag geändert von tuxnix (15.02.2018 11:40:04)

Offline

#11 13.02.2018 21:47:14

tuxnix
Mitglied

Re: naad.sh version0.2(beta)config helper - Bitte fertigstellen

@drcux
Da magst du Recht haben!
(Das Konstruckt finde ich auch sehr schön.)
Dann muss ich halt jetzt da durch und hab dann im Endeffekt mehr Arbeit falls  ich es evt. wieder haben will.
Nah, ja. Es gibt Schlimmeres. Siehe oben.

zu 1) # start as root?
Mir macht es jetzt aktuell keine Probleme, weil ich ja das sudo auf meinem System zur Verfügung habe und auf einem Arch-Iso-Stick ist man von Anfang an root, sodass die Abfrage schlicht übergangen wird.
Du hast geschrieben, dass du das noch verbessert hättest.
Kannst du die Verbesserung mal posten damit ich sie sehe?

Beitrag geändert von tuxnix (13.02.2018 21:59:33)

Offline

#12 16.02.2018 17:27:29

tuxnix
Mitglied

Re: naad.sh version0.2(beta)config helper - Bitte fertigstellen

Zu Sicherungszwecken und Dokumentation hier das nächste update:

Neuerungen:
Die # exittrap ist wieder drin und alle 'exit 1'  werden jetzt über die cleanupandexit Funktion geleitet.
Sie wird noch eine weitere Aufgabe bekommen siehe nächster Punkt.

Logs: naad loggt jetzt seinen Programm Ablauf.
Die Log Einträge werden hinter das exit 0 notiert, wo sie den Programmablauf nicht beeinflussen..
Zusätzlich zu den eigentlichen Vorteilen des Loggens kann so vermieden werden, dass die Prüfung der Internet Verfügbarkeit, das Paketupdate und die Installation von xorg bei jedem Optionsaufruf erneut stattfinden muss. Die messages die noch für die #exittrap zugewiesen werden sollen, können dann auch ebenso für das Loggen eingesetzt werden.

Option -s hat jetzt zusätzlich die Aufgabe erhalten zu den Softwarepaketen die dann schon installiert sind die passenden Sprachpakete hinzuzufügen.

Option -p ist immer noch nicht fertig, hat aber schon zur Sicherheit eine j/N Abfrage erhalten.

$0 - Install and configure Arch Linux

Usage: $0 [option] [argument]
-a                         About: $0 (man page)
-d                         Display configurations
-g <driver>       Install a grafik driver
-h                         Display this help
-k <ll>                Set-x11-keymap <language> code
-l <ll_CC>          Set <language_COUNTRY> code in locale files
-m <my-host> Set hostname
-p <sdX>            Partition a disk and install Arch base (Will delete all data on disk sdX)
-s <ll>                 Install software and language packages. (Edit 'software=' in UCS first.)
-t <timezone>  Set timezone
-u                          Add a user (Set 'name= and passwd=' in User Configuration Section first)
-v <keymap>    Set vconsole keymap
-x <GUI>            Configure xorg and Insall a desktop GUI

Example:
$0 -g xf86-video-nouveau -k de -l de_DE -m mein-pc -s de -t Europe/Berlin -u -v de-latin1 -x lxqt

Terminal commands you may need to search for arguments:
g) pacman -Ssq xf86-video nvidia
k) localectl list-x11-keymap-layouts | less
l) cat /etc/locale.gen
p) lsblk or fdisk -l
t) find /usr/share/zoneinfo -type f | less
v) find /usr/share/kbd/keymaps/i386/ -type f | grep <search string>

(Alpha ist noch nicht für Betatester geeignet.)

#!/bin/bash
# naad version 0.5.4 (alpha) under FAFBL 1.0 is a install and configurtion tool for Arch Linux.
# From tuxnix, drcux and LinLin with no garanty at all.

#### User-Configurations-Section ####

root_passwd=secret
user=arch_user
user_passwd=secret
groups=( wheel audio video games power )

packages="sudo aspell hunspell firefox"

#keyboard
model=pc105
variant=nodeadkeys
options=caps:numlock

#vconsole
FONT=lat9w-16

#### The-Script ####

# start as root?
if [ $UID -ne 0 ];  then
    sudo bash -c "$0 $*"; exit $?
fi

## Display-Section ##

#about naad
about(){
cat|less << EOF

About $0:
This script is a installation and configuration tool for Arch Linux. Read Arch Wiki if you need some help!
You can use it just to display configurations, as a manual, as a configuratios helper or as a installation tool.

Packages and services you might need but you'll have to install them manualy.
For::
Intel: intel-ucode
WLAN: wpa_supplicant, wireless_tools, dialog
Notebooks: acpid
If you need some of these software packages edit 'software=' in User-Configuration-Section.
To activate acpid.service do a 'systemctl enable --now acpid.service' command on terminal.

Grafik driver - option -g:
Closed NVIDIA driver will need some manual configuration aferwards.

Keyboard - option -k:
As a default model=pc105, variant=nodeadkeys and options=caps:numlock are preselectet. These values will fit to most cases. Edit User Configuration Section if you want to change these values. To search values use the following commands: 'localectl list-x11-keymap-models |less' 'localectl list-x11-keymap-variants |less' localectl list-x11-keymap-options |less.

Locales - /etc/locale.conf - /etc/locale.gen - option -l:
Both files /etc/locale.conf and /etc/locale.gen are configred with the language_COUNTRY code <ll_CC>
To aktivate LC_COLLATE=C (first all little than all big letters) collation behaviour decommend this line in '/etc/locale.conf' file afer you used the -l option.

Partitioniring and Arch base install - option -p:
This partioniering fit's both Bios and UEFI systems. (Grub for BIOS in partition sdX1 (10MB), a boot Partition for UEFI (550MB)  sdX2 and a sdX3 partition for rootfs on the rest of the disk). Do a manuel partitioniering if you prefer another constallation (Or edit gdisk in this script).
SSD drives will need a manualy edition of /etc/fstab.
If you need swap volumen you can add a dynamic swap or change gdisk command in this script (printf "o\ny\n n\n\n\n+10M\nEF02\nn\n\n\n+550M\nEF00\nn\n120\n\n+(your RAM size)G\n\nw\ny\n" | gdisk /dev/$sdX) to get a swap partition.

Splitting root-file-system onto diffent disks, can be managed later (mount disks and use genfstab).
Grup will be installed as the most commen boot loader. Change this in the script if you perfer another bootloader.

Sofware - option -s:
It's your choise. Edit User Configuration Section.
Langguage packages will be installed automaticaly.

User - option -u
You have to set a name and password in User Configuration Section. (Now this ist set to: $user - $user_passwd)
The user will become menber of the following groups: $groups

Virtual Console - /etc/vconsole.conf - option -v:
Fonts for virtual console will allways be configerd with 'FONT=lat9w-16' to search for other fonts do 'find /usr/share/kbd/consolefonts -type f | less'. Edit the User Configuration Section.

Xorg and desktop GUI - option -x:
lxde, xfce4, lxqt, plasma and gnome are implemented jet all with a minimal package set.
The first user will get a xorg configuration so that desktop will start with 'startx' command after user login.

Log-Sektion
Under 'exit 0 there are some logs. You can delete these logs form time to time. If 'Internet' and 'Update' are noticed here these checks will not be done by script anymore.

FAQ:
Q: Why no display/login manager is implemented?
A: Some grafikcards and drivers causes trouble in combination with some display managers and desktop-GUI's. It is better system starts first in terminal so you'll get the chance to fix these problems.
Start desktop GUI with 'startx' after user login from terminal. (xorg is configured.) When GUI is running well, install a display manager of your choise.

EOF
}

# Display configurationes
dconf(){
echo ""
echo "----------------------------"
echo "Display some configurations:"
echo "----------------------------"
echo "echo cat /etc/hostname:"
cat /etc/hostname
echo ""
echo "echo cat /etc/locale.conf:"
cat  "/etc/locale.conf"
echo ""
echo "echo locale -a"
locale -a
echo ""
echo "echo locale"
locale
echo ""
echo "echo localectl status:"
localectl status
echo ""
echo "echo timedatectl status:"
timedatectl status
echo ""
echo "echo cat /etc/vconsole.conf:"
cat /etc/vconsole.conf
echo ""
}

# help message
usage(){
cat << EOF
$0 - Install and configure Arch Linux

Usage: $0 [option] [argument]
 -a            About: $0 (man page)
 -d            Display configurations
 -g <driver>   Install a grafik driver
 -h            Display this help
 -k <ll>       Set-x11-keymap <language> code
 -l <ll_CC>    Set <language_COUNTRY> code in locale files
 -m <my-host>  Set hostname
 -p <sdX>      Partition a disk and install Arch base (Will delete all data on disk sdX)
 -s <ll>       Install software and language packages. (Edit 'software=' in UCS first.)
 -t <timezone> Set timezone
 -u            Add a user (Set 'name= and passwd=' in User Configuration Section first)
 -v <keymap>   Set vconsole keymap
 -x <GUI>      Configure xorg and Insall a desktop GUI
 -?            Display this help message

Example:
$0 -g xf86-video-nouveau -k de -l de_DE -m mein-pc -s de -t Europe/Berlin -u -v de-latin1 -x lxqt

Terminal commands you may need to search for arguments:
g) pacman -Ssq xf86-video nvidia
k) localectl list-x11-keymap-layouts | less
l) cat /etc/locale.gen
p) lsblk or fdisk -l
t) find /usr/share/zoneinfo -type f | less
v) find /usr/share/kbd/keymaps/i386/ -type f | grep <search string>

EOF
}

## Menu-Section ##

# optargs
while getopts ":adg:hk:l:m:p:s:t:uv:x:" OPTION; do
  case $OPTION in
       
        a ) about; exit 1 ;;
        d ) dconf; exit 1 ;;
        g ) gdriver=$OPTARG ;;
        h ) usage; exit 1 ;;
        k ) layout=$OPTARG ;;
        l ) ll_CC=$OPTARG ;;
        m ) myhost=$OPTARG ;;
        p ) sdX=$OPTARG ;;
        s ) ll=$OPTARG ;;
        t ) timezone=$OPTARG ;;
        u ) $OPTARG ;;
        v ) vconsole=$OPTARG ;;
        x ) desktop=$OPTARG ;;
        \? )  echo "The option -$OPTARG is not guilty."; exit 1 ;;
        : )  echo "Option -$OPTARG requires an argument!"; exit 1 ;;
  esac
done

# check if a option is set
option=("$@")
if [[ ${option[0]}"x" == "x" ]]; then
    echo "Choose an option!"; exit 1
fi

## Funktion-Section ##

# exittrap
trap cleanupandexit 1 2 3 15
cleanupandexit()
{
exit 1
}

# Internet Connection
intcon(){
echo ""
echo "Test internet connection..."
if ( ! ping -qc1 www.archlinux.org ); then
    echo "Exit! For option -g, -s and -x internet connection is needed.";  cleanupandexit
else
    printf "log=`date --date=now` - Succsess: Internet Connection\n" >> $0
fi
}

# package update
packupdate(){
echo ""
echo "Exec: pacman  --noconfirm -Syu..."
pacman --noconfirm -Syu
#auf Fehlercode prüfen. Hier wird bis jetzt nur eine Ausgabe gemacht!
printf "log=`date --date=now` - Succsess: Package Update\n" >> $0
}

xorginstall(){
echo ""
echo "Exec: pacman -S --needed --noconfirm xorg-server xorg-xinit..."
pacman -S --needed --noconfirm xorg-server xorg-xinit
#auf Fehlercode prüfen. Hier wird bis jetzt nur eine Ausgabe gemacht!
printf "log=`date --date=now` - Succsess: Install xorg\n" >> $0
}

## Exec-Option-Section ##

# check  argumentes - option -g
for opt in ${option[@]}; do
    if [[ $opt == -g ]]; then
       declare -a grafikdrivers=("xf86-video-amdgpu" "xf86-video-ati" "xf86-video-dummy" "xf86-video-fbdev" "xf86-video-intel" "xf86-video-nouveau" "xf86-video-openchrome" "xf86-video-sisusb" "xf86-video-vesa" "xf86-video-vmware" "xf86-video-voodoo" "xf86-video-qxl")
       echo ""
       for (( i=1; i<12; i++ )); do
          if [[ ${grafikdrivers[$i]} != $gdriver ]]; then
             nodriver=0
        elif [[ ${grafikdrivers[$i]} == $gdriver ]]; then
             yesdrive=1
          fi
       done
    fi
done

if [[ $yesdrive == 0 ]]; then
    echo "Argument '$gdriver' is not listed in $0 as a free grafik-driver."
    echo "Perhaps you need one of these:"
    for (( i=1; i<12; i++ )); do
        echo $i") "  ${grafikdrivers[$i]}
    done
    echo ""; cleanupandexit
else
# Install grafikdriver - option -g
    if [[ $gdrive == 1  ]]; then
        echo "Exec: pacman -S --needed --noconfirm $gdriver..."
        pacman -S --needed --noconfirm $gdriver
    fi
fi

# edit /etc/hostname - option -h
if [[ $myhost"x" != "x" ]]; then
    echo "Exec: echo '$myhost' > /etc/hostname..."
    echo $myhost > /etc/hostname
    echo "done..."
fi

# keyboard - option -k
for opt in ${option[@]}; do
   if [[ $opt == -k ]]; then
   echo ""
        if ( ! localectl list-x11-keymap-layouts | grep -q "$layout" ) || [[ "$layout" == [a-z] ]]; then 
            echo "Nothing configured!"
            echo "Exec 'localectl list-x11-keymap-layouts | less' to get values for -k option!"
            echo ""; cleanupandexit
        else
            echo "Exec: localectl set-x11-keymap [$layout] [$model] [$variant] [$options]..."
            localectl set-x11-keymap [$layout] [$model] [$variant] [$options]
            echo "done..."
            echo ""
        fi
    fi
done

# check argumentes option -l
if [[ $ll_CC"x" != "x" ]]; then
    if ( ! grep -q "$ll_CC" "/etc/locale.gen" ) || (  [[ "$ll_CC" != [a-z][a-z]_[A-Z][A-Z] ]] && [[ "$ll_CC" != [a-z][a-z][a-z]_[A-Z][A-Z] ]] ); then 
    echo "Nothing configured. Do 'cat /etc/locale.gen' to get values for -l option!"; cleanupandexit
    fi
fi

# edit /etc/locale.gen - option -l
if [[ $ll_CC"x" != "x" ]]; then
    # set ll
    ll="${ll_CC%_*}"
    # edit /etc/locale.conf
    #Hier muss noch nachgebessert werden z.B. für tcy_IN.UTF-8 UTF-8
    echo "Exec: echo '$ll_CC' > /etc/locale.conf..."
    cat > "/etc/locale.conf" << EOF
    LANG=$ll_CC.UTF-8
    LANGUAGE=$ll_CC:pt:BR
    #LC_COLLATE=C
    LC_TIME=$ll_CC.UTF-8
    LC_PAPER=$ll_CC.UTF-8
    LC_MEASUREMENT=$ll_CC.UTF-8
    LC_MONETARY=$ll_CC.UTF-8
    LC_NUMERIC=$ll_CC.UTF-8
    LC_CTYPE=$ll_CC.UTF-8
    LC_MESSAGES=$ll_CC.UTF-8
    LC_NAME=$ll_CC.UTF-8
    LC_ADDRESS=$ll_CC.UTF-8
    LC_TELEPHONE=$ll_CC.UTF-8
    LC_IDENTIFICATION=$ll_CC.UTF-8
    LC_ALL=
EOF
fi

if [[ $ll_CC"x" != "x" ]]; then
    # reconfigure /etc/locale.gen.
    sed -ie "/#/!s/^/#/" "/etc/locale.gen"
    echo "Exec: sed -ie s/#'$ll_CC'/'$ll_CC'/ /etc/locale.gen..."
    sed -ie "s/#$ll_CC/$ll_CC/" "/etc/locale.gen"
    echo "Exec: sed -ie s/#'en_US.UTF-8 UTF-8'/'en_US.UTF-8 UTF-8'/ "/etc/locale.gen"..."
    sed -ie "s/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" "/etc/locale.gen"
    echo "Exec: locale-gen..."
    echo ""
    locale-gen
    echo ""
fi

# # Partition disk and install Arch base - option -p
for opt in ${option[@]}; do
    if [[ $opt == -p ]]; then
	if [[ $sdX != sd[a-z] ]]; then echo "Choose a disk ( sda, sdb, sdc...) for Partitioniering."; cleanupandexit
		else

		
while true; do
	#clear
	echo "Partiton disk and install Arch Linux base on /dev/$sdX"
	echo -n "Caution: All data on /dev/$sdX will be lost! y/N ? "; read f
	if [[ "$f" == "n" ]]; then cleanupandexit
	elif	[[ "$f" == "y" ]]; then echo "Partiton disk $sdX"; break
	fi
done
sleep 5

            printf "log=`date --date=now` - Starttime" >> $0
            
            printf "o\ny\nn\n\n\n+10M\nEF02\nn\n\n\n+550M\nEF00\nn\n\n\n\n\nw\ny\n" | gdisk /dev/$sdX
            echo "Partitioniering done..."
            printf "log=`date --date=now` - Succsess: Partitioniering $sdX\n" >> $0
            
            
while true; do
	#clear
	echo -n "Format: mkfs.fat -F32 "/dev/$sdX"2"
	echo ""
	echo -n "Format: mkfs.ext4 "/dev/$sdX"3 ! y/N ? "; read f
	if [[ "$f" == "n" ]]; then cleanupandexit
	elif [[ "$f" == "y" ]]; then echo "Partiton disk $sdX"; break
	fi
done     
            sleep 5
            
            echo ""
            echo "Format $sdX"
            mkfs.fat -F32 "/dev/$sdX"2
            echo "y" | mkfs.ext4 -L p_arch "/dev/$sdX"3
            
            sleep 5
            echo  ""
            echo "mount "/dev/$sdX"3 /mnt"
            mount /dev/$sdX"3" /mnt
            mkdir /mnt/boot
            echo "mount "/dev/$sdX"2 /mnt/boot"
            mount "/dev/$sdX"2 "/mnt/boot"
            sleep 5
            echo ""
            echo "Edit /etc/pacman.d/mirrorlist"
            sed -ie "s/#Server/Server/" "/etc/pacman.d/mirrorlist"
            echo "done..."
            intcon
            echo "pacstrap /mnt base base-devel"
            pacstrap /mnt base base-devel
            echo "done..."
            sleep 5
            echo ""
            echo "Generate /mnt/etc/fstab"
            genfstab -U /mnt >> /mnt/etc/fstab
            echo "done..."
            sleep 5
            echo ""
            echo "cat /mnt/etc/fstab"
            cat /mnt/etc/fstab
            arch-chroot /mnt
            echo "systemctl enable --now systemd-timesyncd.service"
            systemctl enable --now systemd-timesyncd.service
            echo "done..."
            sleep 5
            echo ""
            echo "pacman -Syyu --noconfirm"
            pacman -Syyu --noconfirm
            echo "done..."
            sleep 5
            echo ""
            
            
while true; do
	#clear
	echo "Install and configure grub"
	echo "BIOS: grub-install"
	echo ""
	echo -n "UEFI: grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub ? y/N ? "; read f
	if [[ "$f" == "n" ]]; then cleanupandexit
	elif [[ "$f" == "y" ]]; then echo "Partiton disk $sdX";  break
	fi
done
sleep 5
            
            #echo "pacman -S grub"
            #pacman -S grub
            grub-mkconfig -o /boot/grub/grub.cfg
            sleep 5
            #Booten per BIOS
            echo "grub-install - BIOS"
            grub-install
            printf "log=`date --date=now` - grub-install (for BIOS)" >> $0
            #Booten per UEFI
            echo "Install grub - UEFI "
            grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub
             printf "log=`date --date=now` - grub-install (UEFI)" >> $0
        echo "All done..."
        sleep 5
        echo ""
        echo "exec mkinitcpio -p linux"
        mkinitcpio -p linux
        echo "done..."
        sleep 5
        echo "Set root password"
        echo -e "$root_passwd'\n'$root_passwd'\n" | (passwd root)
        echo "done..."
        sleep 5
        echo ""
        echo "Set hardware clock"
        hwclock --systohc && sync
        echo "done..."
        echo ""
        echo "Exit: arch-chroot" 
        exit
        printf "log=`date --date=now` - Exit: arch-chroot" >> $0
        echo "done..."
        sleep 5
        cp $0 /usr/bin && sync
        #script_path="$(dirname "$0")"
        #script_name="$(basename "$0")"
        #cp "${script_path}/${script_name}" "/usr/bin/${script_name}"
        umount /mnt/boot
        umount /mnt
        echo ""
        echo "Arch base system is installed."
        printf "log=`date --date=now` - Arch base system installed" >> $0
        echo "Do a 'reboot' and change bootsequens to $sdX"
        echo ""
    fi
fi
done

# install software- option -s
for opt in ${option[@]}; do
    if [[ $opt == -s ]]; then
        if ( ! grep -q "[0-9][0-9][0-9][0-9] - Succsess: Internet Connection" $0 ); then intcon; fi
        if ( ! grep -q "[0-9][0-9][0-9][0-9] - Succsess: Package Update" $0 ); then packupdate; fi
        echo ""
        echo "Exec: pacman -S --needed --noconfirm $packages..."
        pacman -S --needed --noconfirm $packages
        #Install language packages
        echo ""
        if ( ! localectl list-x11-keymap-layouts | grep -q "$ll" ) || [[ "$ll" == [a-z] ]]; then
            echo "No language package installed!"
            echo "You need a language code."
            echo "Exec 'localectl list-x11-keymap-layouts | less' to get values for -k option!"
            echo ""; cleanupandexit
        else
        echo "Install language packages"
        declare -a pack=( man-pages aspell gimp hunspell firefox libreoffice libreoffice-fresh libreoffice-still thunderbird thunderbird plasma bluegriffon hyphen kompozer )
        
        if ( pacman -Qsq man-pages 1> /dev/null ); then langpack[0]=man-pages-$ll; fi
        if ( pacman -Qsq aspell 1> /dev/null ); then langpack[1]=aspell-$ll; fi
        if ( pacman -Qsq gimp 1> /dev/null ); then langpack[2]=gimp-help-$ll; fi
        if ( pacman -Qsq hunspell 1> /dev/null ); then langpack[3]=hunspell-$ll; fi
        if ( pacman -Qsq firefox 1> /dev/null ); then langpack[4]=firefox-i18n-$ll; fi
        if ( pacman -Qsq libreoffice-fresh 1> /dev/null ); then langpack[5]=libreoffice-fresh-$ll; fi
        if ( pacman -Qsq libreoffice-still 1> /dev/null ); then langpack[6]=libreoffice-still-$ll; fi
        if ( pacman -Qsq thunderbird 1> /dev/null ); then langpack[7]=thunderbird-i18n-$ll; fi
        if ( pacman -Qsq thunderbird 1> /dev/null ); then langpack[8]=kde-l10n-$ll; fi
        #if ( pacman -Qsq bluegriffon ); then langpack[9]=bluegriffon-i18n-$ll; fi
        if ( pacman -Qsq hyphen 1> /dev/null ); then langpack[10]=hyphen-$ll; fi
        if ( pacman -Qsq kompozer 1> /dev/null ); then langpack[11]=kompozer-i18n-$ll; fi

        pacman -Sq  --needed --noconfirm ${langpack[@]}
        fi
    fi
done

# ln /etc/localtime - option -t
for opt in ${option[@]}; do
    if [[ $opt == -t ]]; then
        if ( ! find "/usr/share/zoneinfo/" -type f | grep -wq "$timezone" ); then  
            echo "Argument in -t is not guilty!"; echo  "Find timezone, with: 'find /usr/share/zoneinfo -type f | less'"; cleanupandexit
        else
            echo "Exec: ln -sf /usr/share/zoneinfo/'$timezone' /etc/localtime..."
            ln -sf /usr/share/zoneinfo/$timezone /etc/localtime
            echo "done..."
            echo ""
        fi              
    fi
done

# Add a user - option -u
for opt in ${option[@]}; do
    if [[ $opt == -u ]]; then
        if [[ $user"x" == "x"  ]]; then
            echo ""
            echo "Set a user-name in User Configuration Section"
            echo ""; cleanupandexit
        elif [[ $user_passwd"x" == "x" ]]; then
            echo ""
            echo "Set a user-password in User Configuration Section"
            echo ""; cleanupandexit
        elif  [[ $user"x" != "x" ]] && [[ $user_passwd"x" != "x" ]]; then
            echo "Add user with name: $user"
            useradd -m -g users -s /bin/bash $user
            printf $user_passwd"\n"$user_passwd"\n" | passwd $user
            for group in ${groups[@]}; do
            gpasswd -a "$user" "$group"
            done
            echo ""
            echo "Activate wheel /etc/sudoers"
            sed 's/#%wheel ALL=(ALL) ALL /%wheel ALL=(ALL) ALL_/' "/etc/sudoers" 1> /dev/null
            echo "done..."
            echo ""
        fi
    fi
done
#userdel -r $user

# check argumentes option -v
for opt in ${option[@]}; do
    if [[ $opt == -v ]]; then
        if ( ! find "/usr/share/kbd/keymaps/i386/" -type f | grep -qw "$vconsole" ); then 
            echo "Wrong argument in option -v! Find keyboard map, with: 'find /usr/share/kbd/keymaps/i386/ -type f | grep' <search string>'";  cleanupandexit
        else
            echo "Exec: echo 'KEYMAP=$vconsole' > /etc/vconsole.conf..."
            echo KEYMAP="$vconsole" > "/etc/vconsole.conf"
            echo "Exec: echo 'FONT=$FONT' > /etc/vconsole.conf..."
            echo FONT=$FONT >> "/etc/vconsole.conf"
            echo "done..."
            echo ""
        fi
    fi
done

# Install desktop GUI -option -x
for opt in ${option[@]}; do
   if [[ $opt == -x ]]; then
        if [[ $desktop == lxde ]]; then
            packages="openbox lxsession lxpanel lxde-common lxde-icon-theme"
        elif [[ $desktop == xfce ]]; then
            packages="openbox xfce4-session xfce4-panel human-icon-theme xfce4-terminal"
        elif [[ $desktop == lxqt ]]; then
            packages="openbox lxqt-session lxqt-panel breeze-icons"
        elif [[ $desktop == plasma ]]; then
            packages="kwin plasma-desktop plasma-wayland-session plasma-nm plasma-pa breeze"
        elif [[ $desktop == gnome ]]; then
            packages="mutter gnome-desktop gnome-session networkmanager gnome-themes-standard nm-connection-editor gnome-control-center gnome-shell"
        else
            echo ""; echo "A desktop GUI '$desktop' is not known in $0."
            echo "Choose 'lxde', 'xfce4', 'lxqt', 'plasma', 'gnome' or install another GUI manualy."; echo ""; cleanupandexit
        fi
        if ( ! grep -q "[0-9][0-9][0-9][0-9] - Succsess: Internet Connection" $0 ); then intcon; fi
        if ( ! grep -q "[0-9][0-9][0-9][0-9] - Succsess: Package Update" $0 ); then packupdate; fi
        if ( ! grep -q "[0-9][0-9][0-9][0-9] - Succsess: Install xorg" $0 ); then xorginstall; fi    
      echo ""
      echo "Exec: pacman -S --needed --noconfirm $packages..."
      pacman -S --needed --noconfirm $packages
   fi
done

#sed -n 'd/log=Do/lala/' $0

exit 0
# Ausstehende Arbeiten:
# option -p fertigstellen
# option -l splitten
# del logs option schreiben
# Logs noch weiter ausbauen

log=Do 15. Feb 11:57:18 CET 2018 - Starttimelog=Do 15. Feb 11:57:18 CET 2018 - Succsess: Partitioniering sdh
log=Do 15. Feb 12:02:40 CET 2018 - Starttimelog=Do 15. Feb 12:02:40 CET 2018 - Succsess: Partitioniering sdh
log=Do 15. Feb 12:04:49 CET 2018 - Starttimelog=Do 15. Feb 12:04:49 CET 2018 - Succsess: Partitioniering sdh
log=Do 15. Feb 15:23:05 CET 2018 - Starttimelog=Do 15. Feb 15:23:07 CET 2018 - Succsess: Partitioniering sdc
log=Do 15. Feb 15:28:22 CET 2018 - Starttimelog=Do 15. Feb 15:28:23 CET 2018 - Succsess: Partitioniering sdc
log=Do 15. Feb 15:33:01 CET 2018 - Starttimelog=Do 15. Feb 15:33:03 CET 2018 - Succsess: Partitioniering sdc
log=Do 15. Feb 15:33:40 CET 2018 - grub-install (for BIOS)log=Do 15. Feb 15:33:40 CET 2018 - grub-install (UEFI)
log=Fr 16. Feb 01:06:44 CET 2018 - Succsess: Internet Connection
log=Fr 16. Feb 01:06:46 CET 2018 - Succsess: Package Update

Beitrag geändert von tuxnix (16.02.2018 17:31:51)

Offline

#13 18.02.2018 21:07:55

tuxnix
Mitglied

Re: naad.sh version0.2(beta)config helper - Bitte fertigstellen

Zu Sicherungszwecken und zur Dokumentation.
Hier das nächste update:
Option -p ist jetzt ein ganzes Stück weiter gekommen.
Partitionierung und mkfs laufen schon einmal gut.
Der Rest ist noch ein wenig Arbeit.
Die nächste beta ist gewiss.

(Alpha ist noch nicht für Betatester geeignet.)

#!/bin/bash
# naad 0.7 (alpha)  is an install and configuration helper for Arch Linux.
# From tuxnix, drcux and LinLin under FAFB-Lizenz with no garanty at all.

#### User-Configuration-Section ####

root_passwd=secret
newuser=arch_user
newuser_passwd=secret
groups="wheel audio video games power"

packages="sudo aspell hunspell"

#keyboard
model=pc105
variant=nodeadkeys
options=caps:numlock

#vconsole
FONT=lat2-16
#lat9w-16
#setfont

# rootfs
namen_rootfs=p_arch


# Add these software to 'packages=' if you need it!
# Intel: intel-ucode
# WLAN: wpa_supplicant, wireless_tools, dialog
# Notebooks: acpid, xf86-input-synaptics
# Login-Manager: xorg-xdm, gdm, sddm sddm-kcm, lxdm, lightdm
# Font: ttf-dejavu
# Login-manager: xdm gdm sddm lxdm lightdm
# NVIDIA: nvidia-340xx-dkms nvidia-340xx-utils nvidia-dkms nvidia-settings nvidia-utils opencl-nvidia-340xx nvidia-cg-toolkit xf86-video-qxl

# To activate acpid.service do a 'systemctl enable --now acpid.service' command on terminal.
# Login-Manager activation with 'systemctl enable <login-manager.service>'

#### The-Script ####
# start as root?
if [ $UID -ne 0 ];  then
    sudo bash -c "$0 $*"; exit $?
fi

## Display-Section ##
# Display About naad
about(){
cat|less << EOF

About $0:
This script is a installation and configuration tool for Arch Linux. Read Arch Wiki if you need some help!
You can use it just to display configurations, as a manual, as a configuration helper or as a installation tool.

Grafik driver - option -g:
Closed NVIDIA driver will need some manual configuration aferwards.

Keyboard - option -k:
As a default model=pc105, variant=nodeadkeys and options=caps:numlock are preselectet. These values will fit to most cases. Edit User Configuration Section if you want to change these values. To search values use the following commands: 'localectl list-x11-keymap-models |less' 'localectl list-x11-keymap-variants |less' localectl list-x11-keymap-options |less.

Locales - /etc/locale.conf - /etc/locale.gen - option -l:
Both files /etc/locale.conf and /etc/locale.gen are configred with the language_COUNTRY code <ll_CC>
To aktivate LC_COLLATE=C (first all little than all big letters) collation behaviour decommend this line in '/etc/locale.conf' file afer you used the -l option.

Partitioniring and Arch base install - option -p:
This partioniering fit's both Bios and UEFI systems. (Grub for BIOS in partition sdX1 (10MB), a boot Partition for UEFI (550MB)  sdX2 and a sdX3 partition for rootfs on the rest of your disk). Do a manuel partitioniering if you prefer another constallation (Or edit gdisk in this script).
SSD drives will need a manualy edition of /etc/fstab.
If you need swap volumen you can add a dynamic swap or change gdisk command line in this script (printf "o\ny\n n\n\n\n+10M\nEF02\nn\n\n\n+550M\nEF00\nn\n120\n\n+(your RAM size)G\n\nw\ny\n" | gdisk /dev/$sdX) to get a swap partition.

Splitting root-file-system onto differend disks, can be managed later (mount disks and use genfstab).
Grub will be installed as the most commen boot loader. Change or comment this in the script if you perfer another bootloader.

Sofware - option -s:
It's your choise. Edit User-Configuration-Section.
Langguage packages will be installed automaticaly.

User - option -u
You have to set a name and password in User Configuration Section. (Now this ist set to: $newuser - $newuser_passwd)
The user will become a menber of the following groups, witch are allthought defined in UCS. Aktualy with these values: $groups.

Virtual Console - /etc/vconsole.conf - option -v:
Fonts for virtual console will be configerd with 'FONT=lat9w-16' by default. To search for other possible fonts do: 'find /usr/share/kbd/consolefonts -type f | less'. Edit 'FONT=' in the User-Configuration-Section.

Xorg and desktop GUI - option -x:
lxde, xfce4, lxqt, plasma and gnome are implemented jet. All with a minimal package set.
As a light login-manager lightdm will be installed and enabled. This will give you the chance to test your grafik strack.
If all this works well, install and enable a login manager of your own choise afterwards.

Log-Section
Under 'exit 0' there is a 'Log-Section' which loggs all tasks done by this script. If 'Internet' and 'Update' were noticed here as o.K. these proofments will not be done twice till you delete these lines.

EOF
}

# Display Configurationes
dconf(){
echo ""
echo "----------------------------"
echo "Display some configurations:"
echo "----------------------------"
echo "echo cat /etc/hostname:"
cat /etc/hostname
echo ""
echo "echo cat /etc/locale.conf:"
cat  "/etc/locale.conf"
echo ""
echo "echo locale -a"
locale -a
echo ""
echo "echo locale"
locale
echo ""
echo "echo localectl status:"
localectl status
echo ""
echo "echo timedatectl status:"
timedatectl status
echo ""
echo "echo cat /etc/vconsole.conf:"
cat /etc/vconsole.conf
echo ""
}

# Display ?
usage(){
cat << EOF
$0 - Install and configure Arch Linux

Usage: $0 [option] [argument]

 -a            About: $0 (man page)
 -d            Display configurations
 -g <driver>   Install a grafik driver
 -h            Display this help
 -k <ll>       Set-x11-keymap <language> code
 -l <ll_CC>    Set <language_COUNTRY> code in locale files
 -m <my-host>  Set hostname
 -p <sdX>      Partition a disk and install Arch base (Will delete all data on disk sdX)
 -s <ll>       Install software and language packages. (Edit 'software=' in UCS first.)
 -t <timezone> Set timezone
 -u            Add a user (Set 'name= and passwd=' in User Configuration Section first)
 -v <keymap>   Set vconsole keymap
 -x <GUI>      Configure xorg and Insall a desktop GUI
 -?            Display this help message

Example:
$0 -g xf86-video-ati -k de -l de_DE -m mein-pc -s de -t Europe/Berlin -u -v de-latin1 -x lxqt

Terminal commands you may need to search for arguments:
g) 'pacman -Ssq xf86-video' 'pacman -Ssq nvidia-'
k) localectl list-x11-keymap-layouts | less
l) cat /etc/locale.gen
p) lsblk or fdisk -l
t) find /usr/share/zoneinfo -type f | less
v) find /usr/share/kbd/keymaps/i386/ -type f | grep <search string>

EOF
}

## Menu-Section ##
while getopts ":adg:hk:l:m:p:s:t:uv:x:" OPTION; do
  case $OPTION in
       
         a ) about; exit 1 ;;
        d ) dconf; exit 1 ;;
        g ) gdriver=$OPTARG ;;
        h ) usage; exit 1 ;;
        k ) layout=$OPTARG ;;
        l ) ll_CC=$OPTARG ;;
        m ) myhost=$OPTARG ;;
        p ) sdX=$OPTARG ;;
        s ) ll=$OPTARG ;;
        t ) timezone=$OPTARG ;;
        u ) $OPTARG ;;
        v ) vconsole=$OPTARG ;;
        x ) desktop=$OPTARG ;;
        \? )  echo "The option -$OPTARG is not guilty."; exit 1 ;;
        : )  echo "Option -$OPTARG requires an argument!"; exit 1 ;;
  esac
done

# check if a option is set
option=("$@")
if [[ ${option[0]}"x" == "x" ]]; then
    echo "Choose an option!"; exit 1
fi

## Funktion-Section ##
# exittrap
trap cleanupandexit 1 2 3 15
error(){
echo ""
echo "Error: $message"
if  [[ $tip ]] ; then
	echo "Tip: $tip"
fi
echo ""
printf "`date --date=now`: 'Error' - $message\n" >> $0
exit 1
}

succsess(){
echo ""
echo $message
printf "`date --date=now`: $message\n" >> $0
}

# internet connection
intcon(){
echo "Test internet connection..."
if ( ! ping -qc1 www.archlinux.org ); then
    message="A Internet connection is needed!"; error
else
    message="Internet Connection is o.K."; succsess
fi
}

# package update
packupdate(){
echo "Exec: pacman  --noconfirm -Syu..."
pacman --noconfirm -Syu
message="All Packages are up to date (now)."; succsess
}

## Exec-Section ##
# check  argumentes - option -g
for opt in ${option[@]}; do
    if [[ $opt == -g ]]; then
       declare -a grafikdrivers=([1]=xf86-video-amdgpu xf86-video-ati xf86-video-dummy xf86-video-fbdev xf86-video-intel xf86-video-nouveau xf86-video-openchrome xf86-video-sisusb xf86-video-vesa xf86-video-vmware xf86-video-voodoo nvidia-lts nvidia-340xx nvidia-340xx-lts)
       for (( i=1; i<16; i++ )); do
          if [[ ${grafikdrivers[$i]} != $gdriver ]]; then
             nodrive=0
        elif [[ ${grafikdrivers[$i]} == $gdriver ]]; then
             yesdrive=1
          fi
       done
    fi
done
if [[ $yesdrive == 1 ]]; then
	if ( ! grep -q "[0-9][0-9][0-9][0-9]: Internet Connection is o.K." $0 ); then intcon; fi
        if ( ! grep -q "[0-9][0-9][0-9][0-9]: All Packages are up to date (now)." $0 ); then packupdate; fi
	pacman -S --needed --noconfirm xorg-server xorg-xinit
	message="xorg-server and  xorg-xinit installed (already)."; succsess
	echo "Exec: pacman -S --needed --noconfirm '$gdriver'"
	pacman -S --needed --noconfirm $gdriver
	message="Grafik driver '$gdriver' installed (already)."; succsess
elif [[ $nodrive == 0 ]]; then
	message="'Argument $gdriver is not listed in $0 as a grafik-driver'."
	tip="Perhaps you need one above."
	echo ""
    for (( i=1; i<16; i++ )); do
        echo $i ") "  ${grafikdrivers[$i]}
    done;  error
fi

# keyboard - option -k
for opt in ${option[@]}; do
   if [[ $opt == -k ]]; then
        if ( ! localectl list-x11-keymap-layouts | grep -q "$layout" ) || [[ "$layout" == [a-z] ]]; then 
            message= "Nothing configured! - Exec 'localectl list-x11-keymap-layouts | less' to get values for -k option!"; error
        else
            echo "Exec: localectl set-x11-keymap..."
            localectl set-x11-keymap [$layout] [$model] [$variant] [$options]
            message="Keymap is set to: '[$layout] [$model] [$variant] [$options]'."; succsess 
		    # /etc/X11/xorg.conf.d/20-keyboard.conf
        fi
    fi
done

# check argumentes option -l
for opt in ${option[@]}; do
   if [[ $opt == -l ]]; then
    if ( ! grep -q "$ll_CC" "/etc/locale.gen" ) || (  [[ "$ll_CC" != [a-z][a-z]_[A-Z][A-Z] ]] && [[ "$ll_CC" != [a-z][a-z][a-z]_[A-Z][A-Z] ]] ); then 
    message="'$ll_CC' is a wrorg value for option -l! Do 'cat /etc/locale.gen' to search for."; error
else
    cat > "/etc/locale.conf" << EOF
    LANG=$ll_CC.UTF-8
    LANGUAGE=$ll_CC:pt:BR
    #LC_COLLATE=C
    LC_TIME=$ll_CC.UTF-8
    LC_PAPER=$ll_CC.UTF-8
    LC_MEASUREMENT=$ll_CC.UTF-8
    LC_MONETARY=$ll_CC.UTF-8
    LC_NUMERIC=$ll_CC.UTF-8
    LC_CTYPE=$ll_CC.UTF-8
    LC_MESSAGES=$ll_CC.UTF-8
    LC_NAME=$ll_CC.UTF-8
    LC_ADDRESS=$ll_CC.UTF-8
    LC_TELEPHONE=$ll_CC.UTF-8
    LC_IDENTIFICATION=$ll_CC.UTF-8
    LC_ALL=
EOF
message="Exec: echo '$ll_CC' > /etc/locale.conf"; succsess
 ll="${ll_CC%_*}"
 # reconfigure /etc/locale.gen.
    sed -ie "/#/!s/^/#/" "/etc/locale.gen"
# configure /etc/locale.gen.
    message="sed -ie "/#/!s/^/#/" "/etc/locale.gen""
    sed -ie "s/#$ll_CC/$ll_CC/" "/etc/locale.gen"
    message="Exec: sed -ie s/#$ll_CC/'$ll_CC'/ /etc/locale.gen"; succsess
    sed -ie "s/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" "/etc/locale.gen"
    message="Exec: sed -ie s/#en_US.UTF-8 UTF-8/'en_US.UTF-8 UTF-8'/ "/etc/locale.gen""; succsess
    locale-gen
    message="Exec: 'locale-gen'"; succsess
    fi
fi
done

# edit /etc/hostname - option -m
for opt in ${option[@]}; do
	if [[ $opt == -m ]]; then
    	echo "Exec: echo '$myhost' > /etc/hostname..."
    	echo $myhost > /etc/hostname
    	message="Hostname '$myhost' is configured."; succsess
	fi
done

# # Partition disk and install Arch (base) - option -p
for opt in ${option[@]}; do
	if [[ $opt == -p ]]; then
		if [[ $sdX != sd[a-z] ]]; then 
			message="Choose a disk ( sda, sdb, sdc...) for Partitioniering."; error
		else
			while true; do
				#clear
				fdisk -l /dev/$sdX
				message="Partiton disk and install Arch Linux (base) on /dev/$sdX"; succsess
				echo -n "Caution: All data on /dev/$sdX will be lost! y/N ? "; read f
				if [[ "$f" == "n" ]]; then 
					message="Good By"; error
				elif	[[ "$f" == "y" ]]; then
					echo ""
					echo "Partiton disk /dev/$sdX"; break
				fi
			done
		fi
	fi
done
#: <<KOMMENTARIO
# partition
sgdisk -z -o  -n 1:0:-200M  -t 1:8300  -n 2:-200M:-0  -t 2:ef00  -A 2:set:2 /dev/$sdX # zap anything existing

# umount mkfs
message="make file system"; succsess
partprobe
umount -l /run/media/
umount -l /mnt/
#mkfs.ext4  -L p_arch "/dev/$sdX"1
printf "j\n" | mkfs.ext4 "/dev/$sdX"1
mkfs.fat -F32 "/dev/$sdX"2
#KOMMENTARIO
# mounten
message="mount "/dev/$sdX"1 /mnt"; succsess
mount "/dev/$sdX"1 /mnt

mkdir /mnt/boot/
mount "/dev/$sdX"2 /mnt/boot/
#
# create obligatory directories
message=""Creating arch file system at $sdX"1"; succsess
mkdir -m 0755 -p /mnt/var/{cache/pacman/pkg,lib/pacman,log} /mnt/{dev,run,etc}
mkdir -m 1777 -p /mnt/tmp
mkdir -m 0555 -p /mnt/{sys,proc}
#KOMMENTARIO

message="copy keyring"; succsess
if ( ! cp -a /etc/pacman.d/gnupg /mnt/etc/pacman.d/ ); then
	message="copy keyring"; error
fi

message="copy mirrorlist"; succsess
if ( ! cp -a /etc/pacman.d/mirrorlist /mnt/etc/pacman.d/ ); then
	message="copy keyring"; error
fi

intcon #evt. hier lieber so, dass es bei einem reboot nochmal geprüft wird.

pacman -Syyu --needed --noconfirm
#pacman_args=( bash coreutils cryptsetup device-mapper linux  util-linux )
#pacman_args+=( grub )
#message="${pacman_args[@]}"; succsess

pacman -r /mnt -Syy
pacman -r /mnt -S base grub --ignore gnupg --noconfirm && sync

mount -t proc proc /mnt
mount -t sysfs sys /mnt
mount -o bind /dev /mnt

message="chroot /mnt"; succsess
chroot /mnt

# mount API filesystems
#chroot /mnt || message="failed to setup chroot to /mnt";error
#message="Programmiererabbruch"; error
#message="Programmiererabbruch"; error

message="systemctl enable --now systemd-timesyncd.service"; succsess
systemctl enable --now systemd-timesyncd.service

pacman -S grub --needed --noconfirm
message="genfstab -U -p /mnt >> /etc/fstab"; succsess
genfstab -U -p >> /etc/fstab

#message="sed -ie 's/#Server/Server/' /etc/pacman.d/mirrorlist"; succsess
#sed -ie 's/#Server/Server/' "/etc/pacman.d/mirrorlist"

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

#Boot BIOS
grub-install

#Boot UEFI
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub

mkinitcpio -p linux

printf $root_passwd"\n"$root_passwd"\n" | passwd $root
echo ""
echo ""
message="Set ***** as root password"; succsess

#cat /etc/fstab

message="Set hardware clock"; succsess
hwclock --systohc


exit
umount /mnt/boot
umount /mnt

message="All done. Do a 'reboot' and change bootsequens to $sdX"; succsess

# install software- option -s
for opt in ${option[@]}; do
    if [[ $opt == -s ]]; then
        if ( ! grep -q "[0-9][0-9][0-9][0-9]: Internet Connection is o.K." $0 ); then intcon; fi
        if ( ! grep -q "[0-9][0-9][0-9][0-9]: All Packages are up to date (now)." $0 ); then packupdate; fi
        echo ""
        echo "Exec: pacman -S --needed --noconfirm $packages..."
        pacman -S --needed --noconfirm $packages
        #Install language packages
        if ( ! localectl list-x11-keymap-layouts | grep -q "$ll" ) || [[ "$ll" == [a-z] ]]; then
            message="'No language package installed!'"
            Tip="Exec 'localectl list-x11-keymap-layouts | less' to get values for -k option!"
            echo ""; cleanupandexit
        else
        echo "Install language packages..."
        declare -a pack=( man-pages aspell gimp hunspell firefox libreoffice libreoffice-fresh libreoffice-still thunderbird thunderbird plasma bluegriffon hyphen kompozer )
        
        if ( pacman -Qsq man-pages 1> /dev/null ); then langpack[0]=man-pages-$ll; fi
        if ( pacman -Qsq aspell 1> /dev/null ); then langpack[1]=aspell-$ll; fi
        if ( pacman -Qsq gimp 1> /dev/null ); then langpack[2]=gimp-help-$ll; fi
        if ( pacman -Qsq hunspell 1> /dev/null ); then langpack[3]=hunspell-$ll; fi
        if ( pacman -Qsq firefox 1> /dev/null ); then langpack[4]=firefox-i18n-$ll; fi
        if ( pacman -Qsq libreoffice-fresh 1> /dev/null ); then langpack[5]=libreoffice-fresh-$ll; fi
        if ( pacman -Qsq libreoffice-still 1> /dev/null ); then langpack[6]=libreoffice-still-$ll; fi
        if ( pacman -Qsq thunderbird 1> /dev/null ); then langpack[7]=thunderbird-i18n-$ll; fi
        if ( pacman -Qsq thunderbird 1> /dev/null ); then langpack[8]=kde-l10n-$ll; fi
        #if ( pacman -Qsq bluegriffon ); then langpack[9]=bluegriffon-i18n-$ll; fi
        if ( pacman -Qsq hyphen 1> /dev/null ); then langpack[10]=hyphen-$ll; fi
        if ( pacman -Qsq kompozer 1> /dev/null ); then langpack[11]=kompozer-i18n-$ll; fi
        pacman -Sq  --needed --noconfirm ${langpack[@]}
        message="Language packages are installed (already)."; succsess
        fi
    fi
done

# ln /etc/localtime - option -t
for opt in ${option[@]}; do
    if [[ $opt == -t ]]; then
        if ( ! find "/usr/share/zoneinfo/" -type f | grep -wq "$timezone" ); then
        	message="'Wrong argument in option -t!'"
            tip="Find timezone, with: 'find /usr/share/zoneinfo -type f | less'."; error
        else
			echo ""
            echo "ln -sf /usr/share/zoneinfo/'$timezone' /etc/localtime..."
            ln -sf /usr/share/zoneinfo/$timezone /etc/localtime
            message="Timezone '$timezone' is set."; succsess
        fi              
    fi
done

# Add a user - option -u
for opt in ${option[@]}; do
    if [[ $opt == -u ]]; then
        if [[ $newuser"x" == "x"  ]]; then
        	message="'No user name!'"
            tip="Set a user name in User Configuration Section."; error
        elif [[ $newuser_passwd"x" == "x" ]]; then
            message="'No user password!'"
            tip="Set a user password in User Configuration Section."; error
        elif  [[ $newuser"x" != "x" ]] && [[ $newuser_passwd"x" != "x" ]]; then
			echo ""
            echo "Add user with name: $newuser..."
            useradd -m -g users -s /bin/bash $newuser
            printf $newuser_passwd"\n"$newuser_passwd"\n" | passwd $newuser
            message="New user '$newuser' is set."; succsess
            for group in ${groups[@]}; do
            gpasswd -a "$newuser" "$group"
            done
            echo ""
            echo "Activate wheel /etc/sudoers..."
            sed -n 's/#%wheel ALL=(ALL) ALL /%wheel ALL=(ALL) ALL/' "/etc/sudoers"
			message="All users are allowed to use 'sudo' now."; succsess
        fi
    fi
done

# /etc/vconsole.conf option -v
for opt in ${option[@]}; do
    if [[ $opt == -v ]]; then
        if ( ! find "/usr/share/kbd/keymaps/i386/" -type f | grep -qw "$vconsole" ); then 
            message="Wrong <ll> argument in option -v!"
            tip="Find keyboard map, with: 'find /usr/share/kbd/keymaps/i386/ -type f | grep <ll>'"; error
        else
            echo "KEYMAP=$vconsole" > "/etc/vconsole.conf"
            message="KEYMAP='$vconsole' > /etc/vconsole.conf"; succsess
            echo "FONT=$FONT" >> "/etc/vconsole.conf"
            message="FONT='$FONT' >> /etc/vconsole.conf"; succsess
        fi
    fi
done

# Install desktop GUI -option -x
for opt in ${option[@]}; do
   if [[ $opt == -x ]]; then
        if [[ $desktop == lxde ]]; then
            packages="openbox lxsession lxpanel lxde-common lxde-icon-theme"
        elif [[ $desktop == xfce ]]; then
            packages="openbox xfce4-session xfce4-panel human-icon-theme xfce4-terminal"
        elif [[ $desktop == lxqt ]]; then
            packages="openbox lxqt-session lxqt-panel breeze-icons"
        elif [[ $desktop == plasma ]]; then
            packages="kwin plasma-desktop plasma-wayland-session plasma-nm plasma-pa breeze"
        elif [[ $desktop == gnome ]]; then
            packages="mutter gnome-desktop gnome-session networkmanager gnome-themes-standard nm-connection-editor gnome-control-center gnome-shell"
        else
        	message="A desktop GUI '$desktop' is not known in $0! Nothing installed."
            tip="Choose 'lxde', 'xfce4', 'lxqt', 'plasma', 'gnome' or install another GUI manualy."; error
        fi
        if ( ! grep -q "[0-9][0-9][0-9][0-9]: Internet Connection is o.K." $0 ); then intcon; fi
        if ( ! grep -q "[0-9][0-9][0-9][0-9]: All Packages are up to date (now)." $0 ); then packupdate; fi
		pacman -S --needed --noconfirm xorg-server xorg-xinit
		message="'xorg-server' and 'xorg-xinit' installed (already)."; succsess
        pacman -S --needed --noconfirm $packages
        message="Desktop-GUI '$desktop' is installed (already)."; succsess
        pacman -S --needed --noconfirm lightdm
        message="Login-manager 'lightdm' is installed (already)."; succsess
        systemctl enable lightdm.service
        message="Login-manager 'lightdm' is enabled (already)."; succsess
   fi
done

exit 0
# Ausstehende Arbeiten:
# option -p fertigstellen
# del logs option schreiben
# logischen Ablauf (optionen Reihenfolge - array)
# users groups message

## Log-Section ##

Beitrag geändert von tuxnix (24.02.2018 03:56:10)

Offline

Schnellantwort auf dieses Thema

Schreibe deinen Beitrag und versende ihn
Deine Antwort

Fußzeile des Forums