OSDN Git Service

better internet check
[instantos/instantOS.git] / rootinstall.sh
1 #!/bin/bash
2
3 ####################################################
4 ## installs all system wide tweaks for instantOS  ##
5 ####################################################
6
7 if ! [ "$(whoami)" = "root" ]; then
8     echo "please run this as root"
9     exit 1
10 fi
11
12 mkdir -p /opt/instantos
13
14 # add group and add users to group
15 ugroup() {
16     groupadd "$1" &>/dev/null
17     for USER in $(ls /home/ | grep -v '+'); do
18         if ! sudo su "$USER" -c groups | grep -Eq " $1|$1 "; then
19             sudo gpasswd -a "$USER" "$1"
20         fi
21     done
22 }
23
24 ugroup video
25 ugroup input
26
27 export RAW="https://raw.githubusercontent.com"
28
29 # adds permanent global environment variable
30 addenv() {
31     [ -e /etc/environment ] || touch /etc/environment
32     if [ "$1" = "-f" ]; then
33         local FORCE="true"
34         shift 1
35     fi
36
37     if grep -q "$1=" /etc/environment; then
38         if [ -z "$FORCE" ]; then
39             echo "key already existing"
40             return 1
41         else
42             sed -i "s~$1=.*~$1=$2~g" /etc/environment
43         fi
44     else
45         echo "$1=$2" >>/etc/environment
46     fi
47 }
48
49 addenv -f "QT_QPA_PLATFORMTHEME" "qt5ct"
50 addenv -f "PAGER" "less"
51 if which nvim; then
52     addenv -f "EDITOR" "$(which nvim)"
53 fi
54 addenv -f "XDG_MENU_PREFIX" "gnome-"
55
56 # needed for instantLOCK
57 if ! grep -q 'nobody' /etc/groups &>/dev/null && ! grep -q 'nobody' </etc/group &>/dev/null; then
58     echo "created group nobody"
59     sudo groupadd nobody
60 fi
61
62 # fix java gui appearing empty on instantWM
63 if ! grep -q 'instantwm' </etc/profile; then
64     echo "fixing java windows for instantwm in /etc/profile"
65     echo '# fix instantwm java windows' >>/etc/profile
66     echo 'export _JAVA_AWT_WM_NONREPARENTING=1' >>/etc/profile
67 else
68     echo "java workaround already applied"
69 fi
70
71 # color scheme for tty
72 if ! grep -q '# nord colors' /etc/profile; then
73     echo "applying color scheme"
74
75     {
76         echo '# nord colors'
77         echo 'if [ "$TERM" = "linux" ]; then'
78     } >>/etc/profile
79
80     cat <<EOT >>/etc/profile
81     echo -en "\e]P0383c4a" #black
82     echo -en "\e]P8404552" #darkgrey
83     echo -en "\e]P19A4138" #darkred
84     echo -en "\e]P9E7766B" #red
85     echo -en "\e]P24BEC90" #darkgreen
86     echo -en "\e]PA3CBF75" #green
87     echo -en "\e]P3CFCD63" #brown
88     echo -en "\e]PBFFD75F" #yellow
89     echo -en "\e]P45294e2" #darkblue
90     echo -en "\e]PC579CEF" #blue
91     echo -en "\e]P5CE50DD" #darkmagenta
92     echo -en "\e]PDE7766B" #magenta
93     echo -en "\e]P66BE5E7" #darkcyan
94     echo -en "\e]PE90FDFF" #cyan
95     echo -en "\e]P7CCCCCC" #lightgrey
96     echo -en "\e]PFFFFFFF" #white
97     clear #for background artifacting
98 fi
99
100 EOT
101
102 fi
103
104 # /tmp/topinstall is present if rootinstall is running on postinstall
105 # like on existing installations
106 if ! [ -e /tmp/topinstall ] && command -v plymouth-set-default-theme && ! grep -iq 'manjaro' /etc/os-release; then
107     # install a custom repo
108     if ! grep -q '\[instant\]' /etc/pacman.conf; then
109         echo "restoring repo"
110         /usr/share/instantutils/repo.sh
111     else
112         echo "instantOS repo found"
113     fi
114
115     # give everybode free root, will be disabled on postinstall
116     if ! grep -iq manjaro /etc/os-release; then
117         echo "root ALL=(ALL) NOPASSWD:ALL #instantosroot" >>/etc/sudoers
118         echo "" >>/etc/sudoers
119     fi
120
121     if ! [ -e /opt/instantos/bootscreen ] && [ -e /opt/instantos/realinstall ] && ! [ -e /opt/instantos/noplymouth ]; then
122         echo "installing boot splash screen"
123         plymouth-set-default-theme instantos
124
125         if [ -e /etc/default/grub ]; then
126             if ! grep -q 'instantos boot animation' /etc/default/grub; then
127                 sed -i '/^GRUB_CMDLINE_LINUX_DEFAULT="/aGRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT quiet splash loglevel=3 rd.udev.log_priority=3 vt.global_cursor_default=0" # instantos boot animation' \
128                     /etc/default/grub
129             fi
130         fi
131
132         if ! grep -q '.*plymouth.* # boot screen' /etc/mkinitcpio.conf; then
133             sed -i '/^HOOKS/aHOOKS+=(plymouth) # boot screen' /etc/mkinitcpio.conf
134         fi
135
136         systemctl disable lightdm
137         systemctl enable lightdm-plymouth
138
139         /etc/mkinitcpio.conf
140         if [ -e /etc/default/grub ]; then
141             update-grub
142         fi
143         mkinitcpio -P
144         touch /opt/instantos/bootscreen
145     fi
146 fi
147
148 # tmux doesn't count as console user
149 if ! [ -e /etc/X11/Xwrapper.config ]; then
150     echo "enabling startx"
151     echo 'allowed_users=anybody' >/etc/X11/Xwrapper.config
152 fi
153
154 if [ -e /opt/livebuilder ]; then
155     echo "live session builder detected"
156 else
157     if [ -e /etc/lightdm/lightdm.conf ] && ! grep -q 'instantwm' /etc/lightdm/lightdm.conf; then
158         sudo sed -i 's/^user-session=.*/user-session=instantwm/g' /etc/lightdm/lightdm.conf
159         sudo sed -i '# user-session = Session to load for users/user-session=instantwm/g' /etc/lightdm/lightdm.conf
160     fi
161
162     # check if computer is a potato
163     MEMAMOUNT="$($(which free) -m | grep -vi swap | grep -o '[0-9]*' | sort -n | tail -1)"
164
165     # computer is not a potato if it has an nvidia card, a ryzen processor or more than 3,5gb of ram.
166     # it can be unpotatoed at any time.
167
168     if grep -iq 'Ryzen' /proc/cpuinfo || lshw -C display | grep -q 'nvidia' || [ "$MEMAMOUNT" -gt 3500 ]; then
169         echo "classifying pc as not a potato"
170     else
171         echo "looks like your pc is a potato"
172         mkdir -p /opt/instantos
173         echo "true" >/opt/instantos/potato
174     fi
175
176     # fix brightness permissions
177     bash /usr/share/instantassist/data/backlight.sh
178     # set up postinstall trigger
179
180     mkdir -p /opt/instantos
181     touch /opt/instantos/installtrigger
182 fi
183
184 # indicator file
185 touch /opt/instantos/rootinstall