#!/bin/zsh
function createmenu
{
if [ -z $tempdir ];then
export pathcomp=`mktemp -u --suffix a|tr / "\\n"`
export temppath=`echo $pathcomp|tr / "\\n"|grep -nw tmp.|cut -f 1 -d :`
export tempdir=`echo $pathcomp|head -n $(($temppath-1))|tr "\\n" /`
fi
export menudesc=`stty -a|grep rows|cut -f 2-6 -d \;|cut -f 3,5,8 -d \ |tr \; \ |sed s/"  "/" "/|sed s/"  "/" "/`
cat $1|tail -n 1 >$tempdir/itemlist
export numitems=`cat $tempdir/itemlist|wc -l`
export linecounter=1
while true;do
cat $tempdir/itemlist|head -n $linecounter|tail -n 1 >>$tempdir/items
export linecounter=$(($linecounter+1))
if [ $linecounter -gt $numitems ];then
break
else
continue
fi
done
echo whiptail --menu --nocancel `cat $1|head -n 1` `echo -n $menudesc` `cat $1|tail -n 1`>$tempdir/menu
chmod 755 $tempdir/menu
$tempdir/menu 2>$tempdir/choice
export choice=`cat $tempdir/choice|cut -f 2 -d \;`
cat $tempdir/itemlist|sed s/"\"\ /\\n/g"|sed "s/\"//g" > $tempdir/items
export testnum=`cat $tempdir/items|grep -nw $choice|cut -f 1 -d :|head -n 1`
export itemname=`cat $tempdir/items|head -n $(($testnum+1))|tail -n 1`
rm $tempdir/choice $tempdir/menu $tempdir/itemlist $tempdir/items $tempdir/dynmenu > /dev/null 2>/dev/null
clear
}
function createdynamicmenu
{
if [ -z $tempdir ];then
export pathcomp=`mktemp -u --suffix a|tr / "\\n"`
export temppath=`echo $pathcomp|tr / "\\n"|grep -nw tmp.|cut -f 1 -d :`
export tempdir=`echo $pathcomp|head -n $(($temppath-1))|tr "\\n" /`
fi
$@>$tempdir/itemlist
export numitems=`cat $tempdir/itemlist|wc -l`
export counter=1
if [ -f $tempdir/menutitle ];then
export title=`cat $tempdir/menutitle|head -n 1`
else
export title="$numitems items available"
fi
echo \"$title\" > $tempdir/dynmenu
while true;do
export ltr=`cat $tempdir/itemlist|head -n $counter|tail -n 1|cut -c 1`
export item=`cat $tempdir/itemlist|head -n $counter|tail -n 1`
echo -n \" >> $tempdir/dynmenu
if [ $ltr = \" ];then
export ltr="|"
fi
echo -n $ltr\;$counter >> $tempdir/dynmenu
echo -n \"\  >>$tempdir/dynmenu
echo -n \" >> $tempdir/dynmenu
if echo $item|grep -q \";then
export item=`echo $item|sed "s/\"/\|/g"`
fi
echo -n $item >> $tempdir/dynmenu
echo -n \"\  >>$tempdir/dynmenu
export counter=$(($counter+1))
if [ $counter -gt $numitems ];then
break
else
continue
fi
done
createmenu $tempdir/dynmenu
rm $tempdir/menutitle > /dev/null 2>/dev/null
}
if [ -e /etc/fscrypt.conf ];then
sleep .01
else
echo n|fscrypt setup > /dev/null 2>/dev/null
sed -i "s|#HandleSuspendKey=suspend|HandleSuspendKey=ignore|g;s|#HandleLidSwitch=suspend|HandleLidSwitch=ignore|g;s|#HandleLidSwitchExternalPower=suspend|HandleLidSwitchExternalPower=ignore|g;s|#HandleLidSwitchDocked=ignore|HandleLidSwitchDocked=ignore|g" /etc/systemd/logind.conf
sed -i "s|\/etc\/hosts|\/etc/hostname|g" /etc/zsh/zshrc
fi
if [ -e /unattend ];then
source /unattend
fi
if [ -z $accessibility ]||[ -z $host ]||[ -z $name ]||[ -z $user ]||[ -z $pass ]||[ -z $encrypthome ]||[ -z $autologin ];then
export hoststate=`cat /etc/hostname`
if [ -z $hoststate ];then
export hoststate="not set, press enter to change"
fi
export host=`cat /etc/hostname`
export namestate="not set, press enter to change"
export usrstate="not set, press enter to change"
export pstate="not set, press enter to change"
if fscrypt status|grep -iw /|grep -i not\ supported;then
export encrypthome=0
export homestate="Disabled"
else
export encrypthome=1
export homestate="Enabled"
fi
if [ -z $autologin ];then
export autologin=0
export autologinstate=disabled
fi
while true;do
clear
if pgrep -af speech-dispatcher > /dev/null 2>/dev/null||pgrep -af speechd-up > /dev/null 2>/dev/null||pgrep -af espeakup > /dev/null 2>/dev/null||pgrep -af fenrir > /dev/null 2>/dev/null;then
export accessibility=1
export accessstate="on"
else
export accessibility=0
export accessstate="off"
fi
echo "\"Welcome to your jenux powered system! Let's get you set up!\"">/tmp/cfgmenu
echo -n "\"a\" \"toggle accessibility mode for setup and new users: currently $accessstate\" \"c\" \"computer name: currently $hoststate\" \"n\" \"name: $namestate\" \"u\" \"username: $usrstate\" \"p\" \"password: $pstate\" \"d\" \"done!\" \"r\" \"quit setup and reboot system\" \"s\" \"quit setup and shut down system\" \"y\" \"automatic login: currently $autologinstate\" \"z\" \"Encrypted home: Currently $homestate\"" >> /tmp/cfgmenu
createmenu /tmp/cfgmenu
case "$choice" in
a)
if [ -e /etc/systemd/system/speech-dispatcherd.service.requires/speechd-up.service ]||[ -e /etc/systemd/system/sound.target.wants/espeakup.service ]||[ -e /etc/systemd/system/multi-user.target.wants/speech-dispatcherd.service ];then
export accessibility=1
export accessstate="on"
else
export accessibility=0
export accessstate="off"
fi
if [ $accessibility = 0 ];then
export reader=`cat /bin/speechctl|grep export\ reader=|sed "/\\$2/d;s|export reader=||g"|tail -n 1`
case "$reader" in
espeakup)
export speechsvcs="speakupconf espeakup"
;;
fenrir)
export speechsvcs="fenrirscreenreader speech-dispatcherd"
;;
speechd-up)
export speechsvcs="speakupconf speechd-up speech-dispatcherd"
;;
*)
export speechsvcs="fenrirscreenreader speech-dispatcherd"
;;
esac
speechctl enable
speechctl start
case "$1" in
base)
rm /etc/skel/jenux.defaults /etc/skel/applydef.sh
for f in "/etc/skel/.zlogin" "/etc/skel/.profile" "/etc/skel/.bash_profile";do
cat > $f <<EOF
if tty|grep -w pts;then
sleep .01
else
sudo cpuperf
sudo speechctl stop
sudo speechctl start
fi
EOF
chmod 755 $f
done
;;
basegui)
for f in "/etc/skel/.zlogin" "/etc/skel/.profile" "/etc/skel/.bash_profile";do
cat > $f <<EOF
if tty|grep -w pts;then
sleep .01
else
if is-x-running;then
sleep .01
else
sudo cpuperf
./applydef.sh
sudo speechctl stop
startx
sudo speechctl start
logout
fi
fi
EOF
chmod 755 $f
done
echo ratpoison > /etc/skel/.xinitrc
echo 'sh -c "if which piper-tts-sd-update > /dev/null 2>/dev/null;then piper-tts-sd-update;fi;killall -9 orca speech-dispatcher;orca --replace"' >> /etc/skel/.ratpoisonrc
;;
gnome)
cat > /etc/skel/.config/autostart/orca.desktop<<EOF
[Desktop Entry]
Type=Application
Exec=sh -c "if which piper-tts-sd-update > /dev/null 2>/dev/null;then piper-tts-sd-update;fi;killall -9 orca speech-dispatcher;orca --replace"
Hidden=false
X-MATE-Autostart-enabled=true
Name[C]=orca
Name=orca
Comment[C]=
Comment=
EOF
for f in "/etc/skel/.zlogin" "/etc/skel/.profile" "/etc/skel/.bash_profile";do
cat > $f <<EOF
if tty|grep -qw pts;then
sleep .01
else
if is-x-running;then
sleep .01
else
sudo cpuperf
./applydef.sh
sudo speechctl stop
startwl
sudo speechctl start
logout
fi
fi
EOF
chmod 755 $f
done
echo gnome-session --no-reexec > /etc/skel/.wldesktop
chmod 755 /etc/skel/.wldesktop
mkdir -p /etc/systemd/system/getty@.service.d
cat > /etc/systemd/system/getty@.service.d/wayland.conf<<EOF
[Service]
Environment=XDG_SESSION_TYPE=wayland
EOF
systemctl daemon-reload
;;
mate)
cat > /etc/skel/.config/autostart/orca.desktop<<EOF
[Desktop Entry]
Type=Application
Exec=sh -c "if which piper-tts-sd-update > /dev/null 2>/dev/null;then piper-tts-sd-update;fi;killall -9 orca speech-dispatcher;orca --replace"
Hidden=false
X-MATE-Autostart-enabled=true
Name[C]=orca
Name=orca
Comment[C]=
Comment=
EOF
for f in "/etc/skel/.zlogin" "/etc/skel/.profile" "/etc/skel/.bash_profile";do
cat > $f <<EOF
if tty|grep -qw pts;then
sleep .01
else
if is-x-running;then
sleep .01
else
./applydef.sh
sudo cpuperf
sudo speechctl stop
startx
sudo speechctl start
logout
fi
fi
EOF
chmod 755 $f
done
echo mate-session > /etc/skel/.xinitrc
;;
plasma)
cat > /etc/skel/.config/autostart/orca.desktop<<EOF
[Desktop Entry]
Type=Application
Exec=sh -c "if which piper-tts-sd-update > /dev/null 2>/dev/null;then piper-tts-sd-update;fi;killall -9 orca speech-dispatcher;orca --replace"
Hidden=false
X-MATE-Autostart-enabled=true
Name[C]=orca
Name=orca
Comment[C]=
Comment=
EOF
for f in "/etc/skel/.zlogin" "/etc/skel/.profile" "/etc/skel/.bash_profile";do
cat > $f <<EOF
if tty|grep -qw pts;then
sleep .01
else
if is-x-running;then
sleep .01
else
./applydef.sh
sudo cpuperf
sudo speechctl stop
startx
sudo speechctl start
logout
fi
fi
EOF
chmod 755 $f
done
echo startplasma-x11 > /etc/skel/.xinitrc
;;
all)
cat > /etc/skel/.config/autostart/orca.desktop<<EOF
[Desktop Entry]
Type=Application
Exec=sh -c "if which piper-tts-sd-update > /dev/null 2>/dev/null;then piper-tts-sd-update;fi;killall -9 orca speech-dispatcher;orca --replace"
Hidden=false
X-MATE-Autostart-enabled=true
Name[C]=orca
Name=orca
Comment[C]=
Comment=
EOF
for f in "/etc/skel/.zlogin" "/etc/skel/.profile" "/etc/skel/.bash_profile";do
cat > $f <<EOF
if tty|grep -qw pts;then
sleep .01
else
if is-x-running;then
sleep .01
else
./applydef.sh
sudo cpuperf
sudo speechctl stop
startx
sudo speechctl start
logout
fi
fi
EOF
chmod 755 $f
done
echo mate-session > /etc/skel/.xinitrc
;;
*)
echo unsupported desktop profile, on login, you may be dropped to a console. To start your graphical environment if you have installed one, type startx and press enter.
read -t 5 var
for f in "/etc/skel/.zlogin" "/etc/skel/.profile" "/etc/skel/.bash_profile";do
cat > $f <<EOF
sudo cpuperf
./applydef.sh
sudo speechctl stop
sudo speechctl start
EOF
chmod 755 $f
done
;;
esac
sed -i "s|screen-reader-enabled=false|screen-reader-enabled=true|g" /etc/skel/jenux.defaults
else
speechctl disable
speechctl stop
rm /etc/skel/.config/autostart/orca.desktop
for f in "/etc/skel/.zlogin" "/etc/skel/.profile" "/etc/skel/.bash_profile";do
sed -i "/sudo\ speechctl/d" $f
chmod 755 $f
done
sed -i "s|screen-reader-enabled=true|screen-reader-enabled=false|g" /etc/skel/jenux.defaults
sed -i "/orca/d" /etc/skel/.ratpoisonrc
sleep 1
fi
;;
r)
sync
reboot -f
;;
s)
sync
poweroff -f
;;
c)
echo enter your computer\'s name that it uses when talking to other computers.
read host
export hoststate=$host
;;
n)
echo enter your real name. This will be used, for example, by some email programs to set the name on outgoing mail.
read name
export namestate=$name
;;
u)
echo enter your login name
read user
export usrstate=$user
;;
p)
echo "enter a password that you will use to log in. Note:  your password must be 64 characters or less in order for the file encryption to work propperly. This password will not be shown as you type it."
read -r -s pass
if [ -z $pass ];then
export pstate="not set, press enter to change"
else
export pstate="set, press enter to change."
fi
;;
d)
if [ -z $host ];then
echo please set your computer name before finishing setup
read -t 5 var
continue
fi
if [ -z $name ];then
echo please set your name before finishing setup
read -t 5 var
continue
fi
if [ -z $user ];then
echo please set your username before finishing setup
read -t 5 var
continue
fi
if [ -z $pass ];then
echo please set your password before finishing setup
read -t 5 var
continue
fi
break
;;
y)
if [ $autologin = 1 ];then
export autologin=0
export autologinstate="disabled"
else
export autologin=1
export autologinstate="enabled"
export encrypthome=0
export homestate="disabled, incompatible with automatic login"
fi
;;
z)
if [ $encrypthome = 1 ];then
export encrypthome=0
export homestate="disabled"
else
export encrypthome=1
export homestate="enabled"
fi
;;
esac
done
fi
if [ -e /unattend ];then
echo export accessibility=\'$accessibility\' >> /unattend
fi
if [ -e /unattend ];then
echo export host=\'$host\' >> /unattend
fi
if [ -e /unattend ];then
echo export name=\'$name\' >> /unattend
fi
if [ -e /unattend ];then
echo export user=\'$user\' >> /unattend
fi
if [ -e /unattend ];then
echo export pass=\'$pass\' >> /unattend
fi
if [ -e /unattend ];then
echo export autologin=\'$autologin\' >> /unattend
fi
if [ -e /unattend ];then
echo export encrypthome=\'$encrypthome\' >> /unattend
fi
export lastuid=`cat /etc/passwd|cut -f 3 -d :|uniq|sort -V|sed "/65534/d"|tail -n 1`
echo customizing password hash difficulty for PAM stack, please wait
export time=`cat /etc/fscrypt.conf|grep \"time\"|head -n 1|cut -f 2 -d :|cut -f 2 -d \"`
export parallelism=`cat /etc/fscrypt.conf|grep \"parallelism\"|head -n 1|cut -f 2 -d :|cut -f 2 -d \"`
export rounds=$(($time*$parallelism*10000))
sed -i "s|#SHA_CRYPT_MIN_ROUNDS 5000|SHA_CRYPT_MIN_ROUNDS $rounds|g;s|#SHA_CRYPT_MAX_ROUNDS 5000|SHA_CRYPT_MAX_ROUNDS $rounds|g;s|ENCRYPT_METHOD YESCRYPT|ENCRYPT_METHOD SHA512|g" /etc/login.defs
echo setting computer name, please wait
hostname $host
echo -n $host > /etc/hostname
echo setting up root command line environment
usermod -s /bin/zsh root
starship init bash >> /etc/skel/.bashrc
cp -aT /etc/skel/ /root/
rm /root/applydef.sh /root/jenux.defaults /root/.zlogin /root/.profile /root/.zlogout
echo adding your user and copying default files, please wait
export lastuid=`cat /etc/passwd|cut -f 3 -d :|sort -V|uniq|tail -n 2|head -n 1`
export newuid=$(($lastuid+$RANDOM&1000+$lastuid))
while true;do
if echo $encrypthome|grep -qw 1;then
if echo $pass|adduser $user $newuid;then
echo $pass|fscrypt unlock /home/$user
break
else
deluser $user
continue
fi
else
rm /etc/skel/.bash_logout /etc/skel/.zlogout
if useradd -m -s /bin/zsh $user;then
echo -en $pass\\n$pass|passwd $user
break
else
userdel $user
continue
fi
fi
done
usermod -a -G wheel,audio,video,optical,network,dbus,floppy,storage,scanner,input,speech,power,brlapi -c $name -u $newuid $user
groupmod -g $newuid $user
chown -R $user:$user /home/$user /.fscrypt/policies/* /.fscrypt/protectors/*
if [ -e /unattend ];then
mv /unattend /home/$user
chown $user:$user /home/$user/unattend
chmod 600 /home/$user/unattend
fi
if [ -e /etc/skel/.ssh/authorized_keys ];then
echo removing ssh key access from all new users
rm /etc/skel/.ssh/authorized_keys
fi
if [ -e /root/.ssh/authorized_keys ];then
echo removing ssh key access for root
rm /etc/skel/.ssh/authorized_keys
fi
cd
echo setting permissions for $user home directory
while true;do
if chown -R $user:$user /home/$user;then
break
else
continue
fi
done
echo locking home directory for $user
fscrypt lock /home/$user --all-users > /dev/null 2>/dev/null
if [ $autologin = 1 ];then
echo enabling autologin for $user
rm -rf /etc/systemd/system/getty@tty*
mv /lib/systemd/system/getty@.service.sys /lib/systemd/system/getty@.service
mkdir -p /etc/systemd/system/getty@tty1.service.d
cat > /etc/systemd/system/getty@tty1.service.d/firstboot.conf<<EOF
[Service]
ExecStart=
ExecStart=-/sbin/agetty -a $user --noclear --nohostname --nonewline %I \$TERM
EOF
else
rm -rf /etc/systemd/system/getty@tty1.service.d
mv /lib/systemd/system/getty@.service.sys /lib/systemd/system/getty@.service
fi
clear
echo $host is set up and ready to go! Enjoy your Jenux system! Press enter to continue
read -t 5 var
true
