OSDN Git Service

auto detect new mice and set sensitivity
[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 "nobody workaround not required"
59 else
60     sudo groupadd nobody
61 fi
62
63 # fix java gui appearing empty on instantWM
64 if ! grep -q 'instantwm' </etc/profile; then
65     echo "fixing java windows for instantwm in /etc/profile"
66     echo '# fix instantwm java windows' >>/etc/profile
67     echo 'export _JAVA_AWT_WM_NONREPARENTING=1' >>/etc/profile
68 else
69     echo "java workaround already applied"
70 fi
71
72 # color scheme for tty
73 if ! grep -q '# nord colors' /etc/profile; then
74     echo "applying color scheme"
75
76     {
77         echo '# nord colors'
78         echo 'if [ "$TERM" = "linux" ]; then'
79     } >>/etc/profile
80
81     cat <<EOT >>/etc/profile
82     echo -en "\e]P0383c4a" #black
83     echo -en "\e]P8404552" #darkgrey
84     echo -en "\e]P19A4138" #darkred
85     echo -en "\e]P9E7766B" #red
86     echo -en "\e]P24BEC90" #darkgreen
87     echo -en "\e]PA3CBF75" #green
88     echo -en "\e]P3CFCD63" #brown
89     echo -en "\e]PBFFD75F" #yellow
90     echo -en "\e]P45294e2" #darkblue
91     echo -en "\e]PC579CEF" #blue
92     echo -en "\e]P5CE50DD" #darkmagenta
93     echo -en "\e]PDE7766B" #magenta
94     echo -en "\e]P66BE5E7" #darkcyan
95     echo -en "\e]PE90FDFF" #cyan
96     echo -en "\e]P7CCCCCC" #lightgrey
97     echo -en "\e]PFFFFFFF" #white
98     clear #for background artifacting
99 fi
100
101 EOT
102
103 fi
104
105 # /tmp/topinstall is present if rootinstall is running on postinstall
106 # like on existing installations
107 if ! [ -e /tmp/topinstall ] && command -v plymouth-set-default-theme && ! grep -iq 'manjaro' /etc/os-release; then
108     # install a custom repo
109     if ! grep -q '\[instant\]' /etc/pacman.conf; then
110         echo "restoring repo"
111         /usr/share/instantutils/repo.sh
112     else
113         echo "instantOS repo found"
114     fi
115
116     # deactivate root password, will be reenabled on postinstall
117     if ! grep -iq manjaro /etc/os-release; then
118         echo "root ALL=(ALL) NOPASSWD:ALL #instantosroot" >>/etc/sudoers
119         echo "" >>/etc/sudoers
120     fi
121
122     if ! [ -e /opt/instantos/bootscreen ] && [ -e /opt/instantos/realinstall ] && ! [ -e /opt/instantos/noplymouth ]; then
123         echo "installing boot splash screen"
124         plymouth-set-default-theme instantos
125
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
131         if ! grep -q '.*plymouth.* # boot screen' /etc/mkinitcpio.conf; then
132             sed -i '/^HOOKS/aHOOKS+=(plymouth) # boot screen' /etc/mkinitcpio.conf
133         fi
134
135         systemctl disable lightdm
136         systemctl enable lightdm-plymouth
137
138         /etc/mkinitcpio.conf
139         update-grub
140         mkinitcpio -P
141         touch /opt/instantos/bootscreen
142     fi
143 fi
144
145 # tmux doesn't count as console user
146 if ! [ -e /etc/X11/Xwrapper.config ]; then
147     echo "enabling startx"
148     echo 'allowed_users=anybody' >/etc/X11/Xwrapper.config
149 fi
150
151 if [ -e /opt/livebuilder ]; then
152     echo "live session builder detected"
153 else
154     if [ -e /etc/lightdm/lightdm.conf ] && ! grep -q 'instantwm' /etc/lightdm/lightdm.conf; then
155         sudo sed -i 's/^user-session=.*/user-session=instantwm/g' /etc/lightdm/lightdm.conf
156         sudo sed -i '# user-session = Session to load for users/user-session=instantwm/g' /etc/lightdm/lightdm.conf
157     fi
158
159     # check if computer is a potato
160     MEMAMOUNT="$($(which free) -m | grep -vi swap | grep -o '[0-9]*' | sort -n | tail -1)"
161
162     # computer is not a potato if it has an nvidia card, a ryzen processor or more than 3,5gb of ram.
163     # it can be unpotatoed at any time.
164
165     if grep -iq 'Ryzen' /proc/cpuinfo || lshw -C display | grep -q 'nvidia' || [ "$MEMAMOUNT" -gt 3500 ]; then
166         echo "classifying pc as not a potato"
167     else
168         echo "looks like your pc is a potato"
169         mkdir -p /opt/instantos
170         echo "true" >/opt/instantos/potato
171     fi
172
173     # fix brightness permissions
174     bash /usr/share/instantassist/data/backlight.sh
175     # set up postinstall trigger
176
177     mkdir -p /opt/instantos
178     touch /opt/instantos/installtrigger
179 fi
180
181 # indicator file
182 touch /opt/instantos/rootinstall