#!/bin/bash
read -p "New root password: " rootpw
read -p "New user: " newuser
read -p "${newuser}'s password: " userpw
#update os
echo -e "Server = http://mirror.nus.edu.sg/archlinux-arm/$arch/$repo
`cat /etc/pacman.d/mirrorlist`" > /etc/pacman.d/mirrorlist
echo -e "Server = http://ftp.tku.edu.tw/Linux/ArchLinux-arm/$arch/$repo
`cat /etc/pacman.d/mirrorlist`" > /etc/pacman.d/mirrorlist
echo -e "Server = http://mirrors.hust.edu.cn/archlinux-arm/$arch/$repo
`cat /etc/pacman.d/mirrorlist`" > /etc/pacman.d/mirrorlist
echo -e "Server = http://mirrors.tuna.tsinghua.edu.cn/archlinuxarm/$arch/$repo
`cat /etc/pacman.d/mirrorlist`" > /etc/pacman.d/mirrorlist
echo -e "Server = http://mirrors.ustc.edu.cn/archlinuxarm/$arch/$repo
`cat /etc/pacman.d/mirrorlist`" > /etc/pacman.d/mirrorlist
pacman -Syu --noconfirm
pacman -S --noconfirm lxde wqy-microhei ttf-dejavu dialog
wpa_supplicant iw netctl wifi-radar ifplugd wpa_actiond leafpad
udisks2 unrar unzip xarchiver zip p7zip mesa alsa-utils ntfs-3g
gvfs lxde git vlc gvfs gvfs-mtp xf86-video-vesa xf86-input-evdev
xorg-xinit xorg-server tigervnc zsh sudo base-devel aria2 uget
ibus ibus-pinyin ibus-qt midori
#set local
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
echo "zh_CN.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
echo "LANG=zh_CN.UTF-8" > /etc/locale.conf
echo "#LANG=en_US.UTF-8" >> /etc/locale.conf
rm /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#new user init
rm -rf /etc/skel/*
echo "autoload -U compinit promptinit" > /etc/skel/.zshrc
echo "compinit" >> /etc/skel/.zshrc
echo "promptinit" >> /etc/skel/.zshrc
echo "prompt adam2" >> /etc/skel/.zshrc
echo "" >> /etc/skel/.zshrc
echo 'bindkey "e[1~" beginning-of-line # Home' >> /etc/skel/.zshrc
echo 'bindkey "e[4~" end-of-line # End' >> /etc/skel/.zshrc
echo 'bindkey "e[5~" beginning-of-history # PageUp' >> /etc/skel/.zshrc
echo 'bindkey "e[6~" end-of-history # PageDown' >> /etc/skel/.zshrc
echo 'bindkey "e[2~" quoted-insert # Ins' >> /etc/skel/.zshrc
echo 'bindkey "e[3~" delete-char # Del' >> /etc/skel/.zshrc
echo '' >> /etc/skel/.zshrc
echo 'export GTK_IM_MODULE=ibus' >> /etc/skel/.zshrc
echo 'export XMODIFIERS=@im=ibus' >> /etc/skel/.zshrc
echo 'export QT_IM_MODULE=ibus' >> /etc/skel/.zshrc
mkdir -p /etc/skel/.config/lxsession/LXDE
echo '@lxpanel --profile LXDE' > /etc/skel/.config/lxsession/LXDE/autostart
echo '@pcmanfm --desktop --profile LXDE' >> /etc/skel/.config/lxsession/LXDE/autostart
echo '@xscreensaver -no-splash' >> /etc/skel/.config/lxsession/LXDE/autostart
echo '/usr/bin/ibus-daemon' >> /etc/skel/.config/lxsession/LXDE/autostart
mkdir /etc/skel/.vnc
echo '#!/bin/sh' > /etc/skel/.vnc/xstartup
echo 'exec startlxde' >> /etc/skel/.vnc/xstartup
chmod 755 /etc/skel/.vnc/xstartup
mkdir /etc/skel/.aria2
mkdir /etc/skel/Downloads
echo 'continue' > /etc/skel/.aria2/aria2.conf
echo 'dir=../Downloads' >> /etc/skel/.aria2/aria2.conf
echo 'file-allocation=none' >> /etc/skel/.aria2/aria2.conf
echo 'log-level=warn' >> /etc/skel/.aria2/aria2.conf
echo 'max-connection-per-server=4' >> /etc/skel/.aria2/aria2.conf
echo 'min-split-size=5M' >> /etc/skel/.aria2/aria2.conf
echo 'on-download-complete=exit' >> /etc/skel/.aria2/aria2.conf
#sudo
echo "Defaults rootpw" >> /etc/sudoers
#root password
(echo $rootpw;sleep 1;echo $rootpw) | passwd > /dev/null
#newuser
userdel -r alarm
useradd -m -s $(which zsh) $newuser
echo "$newuser ALL=(ALL) ALL" >> /etc/sudoers
echo "Defaults:$newuser !authenticate" >> /etc/sudoers
(echo $userpw;sleep 1;echo $userpw) | passwd $newuser > /dev/null
mkdir /etc/systemd/system/getty@tty1.service.d
echo '[Service]' > /etc/systemd/system/getty@tty1.service.d/override.conf
echo 'ExecStart=' >> /etc/systemd/system/getty@tty1.service.d/override.conf
echo "ExecStart=-/usr/bin/agetty --autologin $newuser --noclear %I 38400 linux" >> /etc/systemd/system/getty@tty1.service.d/override.conf
#auto start vnc
touch /etc/systemd/system/vncserver@:1.service
echo -e "[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=simple
User=$newuser
PAMName=login
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver -alwaysshared -fg %i
ExecStop=/usr/bin/vncserver -kill %i
[Install]
WantedBy=multi-user.target
" > /etc/systemd/system/vncserver@:1.service
systemctl enable vncserver@:1.service
#yaourt
mkdir tmp
cd tmp
git clone https://aur.archlinux.org/package-query.git
cd package-query
makepkg -si
cd ..
git clone https://aur.archlinux.org/yaourt.git
cd yaourt
makepkg -si
cd ../..
rm -rf tmp
#set wireless
wifi-menu -o
systemctl enable netctl-auto@wlan0.service
systemctl enable netctl-ifplugd@wlan0.service