Last active
December 31, 2023 07:05
-
-
Save moglerdev/c9c4ba4a69b35c363af0da09b8526c5d to your computer and use it in GitHub Desktop.
This script downloads the tar.gz files from Microsoft servers, installs them in the /opt folder, and registers a symlink, as well as in the application pool. Designed for the convenience of Arch Linux users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#################################################################################### | |
### LICENSE MIT | |
### | |
### Copyright (c) 2023 Christopher R. Jaeger | |
### | |
### Permission is hereby granted, free of charge, to any person obtaining a copy | |
### of this software and associated documentation files (the "Software"), to deal | |
### in the Software without restriction, including without limitation the rights | |
### to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
### copies of the Software, and to permit persons to whom the Software is | |
### furnished to do so, subject to the following conditions: | |
### | |
### The above copyright notice and this permission notice shall be included in all | |
### copies or substantial portions of the Software. | |
### | |
### THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
### IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
### FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
### AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
### LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
### OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
### SOFTWARE. | |
#################################################################################### | |
# this script downloads vscode and installs it to /opt/ | |
if [ -d /tmp/vscode.tar.gz ]; then | |
rm /tmp/vscode.tar.gz | |
fi | |
# download vscode | |
curl -L -f "https://code.visualstudio.com/sha/download?build=stable&os=linux-x64" -o /tmp/vscode.tar.gz | |
# check if download successed | |
if [ $? -ne 0 ]; then | |
echo "Download failed!" | |
exit 1 | |
fi | |
# extract vscode | |
tar -xvf /tmp/vscode.tar.gz -C /tmp/ | |
# checked if extracted | |
if [ $? -ne 0 ]; then | |
echo "Extraction failed!" | |
exit 1 | |
fi | |
# close all instances of vscode | |
killall -9 code | |
# check if vscode exists | |
if [ ! -d /opt/vscode ]; then | |
echo "VSCode not installed!" | |
echo "Skip removing old vscode" | |
else | |
# remove old vscode | |
sudo rm -rf /opt/vscode | |
fi | |
# move vscode to /opt/ | |
sudo mv /tmp/VSCode-linux-x64 /opt/vscode | |
# check if moved | |
if [ $? -ne 0 ]; then | |
echo "Move failed!" | |
exit 1 | |
fi | |
# check if symlink dont exists | |
if [ -f /usr/local/bin/code ]; then | |
echo "Symlink already exists!" | |
echo "Remove old symlink" | |
sudo rm /usr/local/bin/code | |
fi | |
# create symlink | |
sudo ln -s /opt/vscode/bin/code /usr/local/bin/code | |
# check if symlink created | |
if [ $? -ne 0 ]; then | |
echo "Symlink failed!" | |
exit 1 | |
fi | |
# remove downloaded file | |
rm /tmp/vscode.tar.gz | |
# register in application pool | |
file="[Desktop Entry] | |
Name=Visual Studio Code | |
Comment=Code Editing. Redefined. | |
GenericName=Text Editor | |
Exec=/opt/vscode/code | |
Icon=/opt/vscode/resources/app/resources/linux/code.png | |
Type=Application | |
StartupNotify=true | |
StartupWMClass=Code | |
Categories=Utility;TextEditor;Development;IDE; | |
MimeType=text/plain;inode/directory; | |
" | |
msg="[INFO] Currently registered only for your user! Please run the script as root to register it system-wide." | |
if [ "$(id -u)" -ne 0 ]; then | |
echo "$file" > ~/.local/share/applications/code.desktop | |
else | |
msg="Successfully registered for all users!" | |
echo "$file" > /usr/share/applications/code.desktop | |
fi | |
# check if registered | |
if [ $? -ne 0 ]; then | |
echo "Register failed!" | |
exit 1 | |
fi | |
# success | |
echo "VSCode installed!" | |
echo "$msg" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment