Răsfoiți Sursa

:hammer: use local package

Jeremy Zheng 3 ani în urmă
părinte
comite
04ddf7b728
2 a modificat fișierele cu 41 adăugiri și 43 ștergeri
  1. 17 16
      scripts/spring/user/create.sh
  2. 24 27
      scripts/spring/user/setup.sh

+ 17 - 16
scripts/spring/user/create.sh

@@ -8,14 +8,14 @@ then
     exit 1
 fi
 
-apt -y install zsh git zip unzip bzip2 curl wget vim pwgen
+pacman -S --needed zsh git zip unzip bzip2 curl wget vim pwgen
 
 if id "$1" &>/dev/null
 then
     echo "user $1 found"
 else
     echo "create user $1"
-    useradd -m -d /workspace/home/$1 -s /bin/zsh $1
+    useradd -m -d /home/$1 -s /bin/zsh $1
 fi
 
 echo 'reset password'
@@ -23,42 +23,43 @@ passwd -l $1
 echo "$1:$(pwgen 32 1)" | chpasswd
 
 echo 'setup nginx'
+export WORKSPACE=/srv/http/$1
 
-if [ ! -d /workspace/www/$1/htdocs ]
+if [ ! -d $WORKSPACE/htdocs ]
 then
-    mkdir -p /workspace/www/$1/htdocs
-    chown $1:$1 /workspace/www/$1/htdocs
+    mkdir -p $WORKSPACE/htdocs
+    chown $1:$1 $WORKSPACE/htdocs
 fi
 
-if [ ! -d /workspace/www/$1/logs ]
+if [ ! -d $WORKSPACE/logs ]
 then
-    mkdir -p /workspace/www/$1/logs
-    chown www-data:www-data /workspace/www/$1/logs
+    mkdir -p $WORKSPACE/logs
+    chown http:http $WORKSPACE/logs
 fi
 
-if [ ! -d /workspace/www/$1/tmp ]
+if [ ! -d $WORKSPACE/tmp ]
 then
     mkdir -p /workspace/tmp/$1
     chown $1:$1 /workspace/tmp/$1
 fi
 
-if [ ! -f /workspace/www/$1/nginx.conf ]
+if [ ! -f $WORKSPACE/nginx.conf ]
 then
     # https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
-    cat > /workspace/www/$1/nginx.conf <<EOF
+    cat > $WORKSPACE/nginx.conf <<EOF
 # https://laravel.com/docs/9.x/deployment#nginx
 
 server {
-  listen 80;
+  listen 60080;
   server_name ${1//_/-}.spring.wikipali.org;
 
-  access_log /workspace/www/$1/logs/access.org;
-  error_log /workspace/www/$1/logs/error.log;
+  access_log $WORKSPACE/logs/access.org;
+  error_log $WORKSPACE/logs/error.log;
 
   add_header X-Frame-Options "SAMEORIGIN";
   add_header X-Content-Type-Options "nosniff";
 
-  root /workspace/www/$1/htdocs/public;
+  root $WORKSPACE/htdocs/public;
   index index.html index.php;
 
   charset utf-8;
@@ -84,7 +85,7 @@ server {
 }
 EOF
 
-ln -sf /workspace/www/$1/nginx.conf /etc/nginx/sites-enabled/$1.spring.wikipali.org.conf
+ln -sf $WORKSPACE/nginx.conf /etc/nginx/sites-enabled/$1-spring.conf
 
 fi
 

+ 24 - 27
scripts/spring/user/setup.sh

@@ -5,7 +5,8 @@ set -e
 echo 'setup zsh'
 if [ ! -d "$HOME/.oh-my-zsh" ]
 then
-    git clone https://github.com/ohmyzsh/ohmyzsh.git $HOME/.oh-my-zsh
+    # git clone https://github.com/ohmyzsh/ohmyzsh.git $HOME/.oh-my-zsh
+    tar xf ohmyzsh.tar.xz -C $HOME
 fi
 if [ ! -f "$HOME/.zshrc" ]
 then
@@ -16,7 +17,8 @@ fi
 echo 'setup nodejs'
 if [ ! -d "$HOME/.nvm" ]
 then
-    git clone https://github.com/nvm-sh/nvm.git $HOME/.nvm
+    # git clone https://github.com/nvm-sh/nvm.git $HOME/.nvm
+    tar xf nvm.tar.xz -C $HOME
 
     cat >> $HOME/.profile <<EOF
 export NVM_DIR="\$HOME/.nvm"
@@ -24,31 +26,32 @@ export NVM_DIR="\$HOME/.nvm"
 [ -s "\$NVM_DIR/bash_completion" ] && \. "\$NVM_DIR/bash_completion" 
 EOF
     echo 'export PATH=$HOME/.yarn/bin:$PATH' >> $HOME/.profile
+    echo 'export EDITOR=vim' >> $HOME/.profile
 fi
 
-cd $HOME/.nvm
-git checkout v0.39.2
-. $HOME/.nvm/nvm.sh
+# cd $HOME/.nvm
+# git checkout v0.39.3
+# . $HOME/.nvm/nvm.sh
 
-if ! [ -x "$(command -v yarn)" ]
-then
-    nvm install node 
-    nvm use node 
-    npm install yarn -g
-fi
+# if ! [ -x "$(command -v yarn)" ]
+# then
+#     nvm install node 
+#     nvm use node 
+#     npm install yarn -g
+# fi
 
-mkdir -p $HOME/.local/bin $HOME/local $HOME/downloads
+mkdir -p $HOME/.local/bin $HOME/local $HOME/downloads $HOME/tmp $HOME/workspace
 
 echo 'setup php'
-if [ ! -f "$HOME/downloads/composer" ]
-then
-    wget -O $HOME/downloads/composer https://getcomposer.org/installer
-fi
+# if [ ! -f "$HOME/downloads/composer" ]
+# then
+#     wget -O $HOME/downloads/composer https://getcomposer.org/installer
+# fi
 if [ ! -f "$HOME/.local/bin/composer" ]
 then
-    cd $HOME/downloads
-    php composer
-    mv composer.phar $HOME/.local/bin/composer
+    # cd $HOME/downloads
+    # php composer
+    cp composer.phar $HOME/.local/bin/composer
 fi
 
 echo 'setup ssh'
@@ -56,20 +59,14 @@ if [ ! -d $HOME/.ssh ]
 then
     mkdir $HOME/.ssh
     chmod 700 $HOME/.ssh
-    cat /tmp/$USER.pub > $HOME/.ssh/authorized_keys
+    cat $USER.pub > $HOME/.ssh/authorized_keys    
 fi
 
 
 echo 'setup workspace folder'
 if [ ! -L $HOME/www ]
 then
-    ln -sf /workspace/www/$USER $HOME/www
-fi
-
-echo 'setup tmp folder'
-if [ ! -L $HOME/tmp ]
-then
-    ln -sf /workspace/tmp/$USER $HOME/tmp
+    ln -sf /srv/http/$USER $HOME/www
 fi
 
 echo 'setup tmux'